php session help
Posted: Wed Oct 12, 2005 5:23 pm
Ok, here is the issue. I have a script to log in and define the users session as w/e it is in the database. The only problem is that when it sets the session name, if it even does set it, it doesn't stick. When this script is run, it comes out fine, no errors, and echo's "You are now logged in" when the correct password and username are provided. When you go back to the login screen, it should see that you are already logged in and direct you to a page, instead it just gives you the same message.
Also, when this script is run, it returns the test session name but the whole echo having to do with the usersess session name just doesn't show up.
Like I said, it finds the database, username, and everything fine, it just doesn't do anything with setting the session name. I’m really stumped on this one, I can’t figure out why it won’t set. Any help would be greatly appreciated.
Code: Select all
<?php
session_start();
if (!isset($_SESSION['name'])) {
if (isset ($_POST['username'])) {
$person = $_POST['username'];
$pwd = $_POST['password'];
$dbusername="abc";
$dbpassword="abc";
$database="mysql";
mysql_connect($database, $dbusername, $dbpassword);
mysql_select_db($database) or die("Unable to connect to database. Please contact the webmaster for further assistance.");
$query = "SELECT name FROM user_handle.users WHERE uname = '$person' AND pword = '$pwd'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
echo ("Sorry but you are not authorize to view this page. Please check your username and password.");
}
else {
$result = $_SESSION['usersess'];
echo ("You are now logged in");
}
}
}
else {
require ('auth_index.html');
}
?>Code: Select all
<?php
session_start();
unset ($_SESSION['test']);
$_SESSION['test'] = 'test_session';
echo ("{$_SESSION['test']} is your test session name");
echo ("{$_SESSION['usersess']} is your test session name");
?>