Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP User Class System
Old 04-16-2008, 06:49 PM PHP User Class System
Junior Talker

Posts: 1
Trades: 0
I have begun writing a PHP website template system, and have hit a problem
Code:
<?php

include '../includes/db_connect.php';
include '../includes/config_table.inc.php';


$user_name = $_POST["user_name"];        
$user_password = $_POST["user_password"];    

if ($user_name && $user_password)        
{

$salt = substr($user_password, 0, 2);
$userPswd = crypt($user_password, $salt);
$login_check = mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd'" ));
 $check_ad = mysql_query("SELECT * FROM `$user` WHERE userlevel=0");
    $check_us = mysql_query("SELECT * FROM `$user` WHERE userlevel=1");
   
   //echo("DEBUG:\r\n");
   //echo("login_check:".$login_check."\r\n"."check_ad:".$check_ad."\r\n"."check_us:".$check_us."\r\n\r\n");

    if ($login_check == 1 && $check_ad) {
   
echo "Logged In Sucessfully. Please wait while you are redirected";    
echo "<meta http-equiv='refresh' content='2; url=setadmincookie.php?u=$username&p=$user_password'>";

    } elseif ($login_check == 1 && $check_us) {    
    
echo "Logged In Sucessfully. Please wait while you are redirected";    
echo "<meta http-equiv='refresh' content='2; url=setcookie.php?u=$username&p=$user_password'>";

    } else {
   
echo 'Login failed. Username and Password did not match database entries.';    

    }
}

else    
{
    echo "Form was not completed. Please go back and make sure that the form was fully completed.";    
}


mysql_close();
?>
this code is ment to check the userlevel against the database and send them to one place or another depending on there level.
How ever is isn't working, it is always sending to the admin area, and not the user area.Now i no why it isn't working as it is only checking the database not comparing?
But i don't no how to fix it.
i have two accounts made on the site, one user and one admin. Admin has userlevel 1, user has userlevel 2.
Any ideas?
Blade280891 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-17-2008, 08:13 AM Re: PHP User Class System
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
From what I can see (for future reference, please put php code in the [php][/php] tags, it makes the code easier to read) I can't actually see any reference to the number 2 (Though near the end there seems to be a place where it could be). I think your code is meant to be:
PHP Code:
<?php

include '../includes/db_connect.php';
include 
'../includes/config_table.inc.php';


$user_name $_POST["user_name"];        
$user_password $_POST["user_password"];    

if (
$user_name && $user_password)        
{

$salt substr($user_password02);
$userPswd crypt($user_password$salt);
$login_check mysql_num_rows(mysql_query("SELECT * FROM `$user` WHERE user_name='$user_name' AND user_password='$userPswd'" ));
 
$check_ad mysql_query("SELECT * FROM `$user` WHERE userlevel=0");
    
$check_us mysql_query("SELECT * FROM `$user` WHERE userlevel=1");
   
   
//echo("DEBUG:\r\n");
   //echo("login_check:".$login_check."\r\n"."check_ad:".$check_ad."\r\n"."check_us:".$check_us."\r\n\r\n");

    
if ($login_check == && $check_ad) {
   
echo 
"Logged In Sucessfully. Please wait while you are redirected";    
echo 
"<meta http-equiv='refresh' content='2; url=setadmincookie.php?u=$username&p=$user_password'>";

    } elseif (
$login_check == && $check_us) {    
    
echo 
"Logged In Sucessfully. Please wait while you are redirected";    
echo 
"<meta http-equiv='refresh' content='2; url=setcookie.php?u=$username&p=$user_password'>";

    } else {
   
echo 
'Login failed. Username and Password did not match database entries.';    

    }
}

else    
{
    echo 
"Form was not completed. Please go back and make sure that the form was fully completed.";    
}


mysql_close();
?>
Also, it's good security to not send user names and passwords via the URL because someone can easily see them.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 04-17-2008 at 08:15 AM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to PHP User Class System
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10314 seconds with 12 queries