Sessions Clearing After One Page
Posted: Tue Sep 04, 2007 5:01 pm
feyd | Please use
And Here Is The Code For The Login
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Im having a problem. I have built a login script that works, that sets the rights to the users on the website using a $_SESSION call. Now, it works on the first page I go to, but after the first page, the session clears itself out. I ran in isset call on this Session on the second page I visit, and its empty. Can anyone help me with this? Thank you
you can check it out at http://www.n-volved.com
login at the top with
username:test
password:test1
Here is the code for the adduser pageCode: Select all
<?
session_start();
if (!isset($_SESSION['rights'])) {
header ('Location: index.php');
print '<p><font color="CCCCCC">No Session Stored</font></p>';
}
if ($_SESSION['rights'] < 11) {
header ('Locations: privelages.php');
exit();
}
$username = $_POST['username'];
$password = $_POST['password'];
$rpassword = $_POST['rpassword'];
$rights = $_POST['rights'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
require('functions.php');
if (!$username)
echo "Username is blank";
else if (!$password || !$rpassword)
echo "Password(s) field empty.";
else if (!$first_name || !$last_name)
echo "First or last name not entered!";
else if ($username && $password && rpassword && $rights && $first_name && $last_name && $email) {
if ($username == $password)
echo "Username and password cannot be the same!";
else if (!ereg("[a-z||0-9]", $username))
echo "Username has illegal characters, alphanumbers only.";
else if($password != $rpassword)
echo "You failed to retype the password correctly.";
else if (adduser('$username', '$password', '$rights', '$first_name', '$last_name', '$email')) {
echo 'Added Successfully';
} else {
echo 'Error Occured';
}
}
?>Code: Select all
$auth = false;
if (isset($_POST['submit'])) {
mysql_connect('localhost', "kromped", "*")or die("cannot connect");
mysql_select_db('main-site')or die("cannot select DB");
// username and password sent from signup form
$myusername=$_POST['username'];
$password = $_POST['password'];
$mypassword= md5($password);
$sql="SELECT username, password, rights FROM login WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
$frights = mysql_fetch_array($result);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION['username'] = "$myusername";
$_SESSION['rights'] = "$frights[2]";
header ('Location: main_login.php');
exit();
}else {
echo "<font color=\"red\">Wrong Username or Password</font>";
}
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]