View Single Post
Old 10-15-2008, 03:12 PM   #1 (permalink)
CoryMathews
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default Starting Session Problem

Im having a small problem with a login script. When a user logs in the session is not stored, however if they log in again their session is started. I do not understand why, it is not every single time but almost every time.

On my login page it works something like this after the user hits the submit button.

PHP Code:
session_start();
...
//query to check user
...
$hour time() + 3600
setcookie(iSearchNotes$UserName$hour); 
setcookie(iSearchNotes$pass$hour);

$_SESSION["UserName"] = $UserName;
$_SESSION["UserId"] = $uID;
//forward to main page. 
then on the rest of the pages it will look like

PHP Code:
session_start();
...
if(isset(
$_SESSION['UserName']) and $_SESSION['UserName'] != '' and isset($_SESSION['UserId'])) {
echo 
'Welcome '.$_SESSION['UserName'].'- <a href="user_logout.php">Log out</a>';
.. 
This check almost always fails on the first login. Anyone see why this is? Also you can try it out at iSearchNotes.com - Make Your Notes Searchable
CoryMathews is offline  
Reply With Quote