Jump to content

Sessions - weird problem saving them.


Beauford

Recommended Posts

I have a weird problem with sessions, and for the life of me I can't figure it out. Running Windows 2003, IIS, PHP 5.1, MySQL 5.0. I use this for testing before I upload to my hosting service, which by the way runs perfectly with the exact same code.

 

I have a seperate registration page and a seperate login page. If a user registers successfully they are automatically logged in and the session variables are set and I can see the information has been set in the session file.

 

But if the user just trys to log in from the login page, I can not get the session variables set, the session file is created, but there is nothing in it.

 

This is my code, very simple and straight forward.  The only other thing in the file below is the form itself, which consists of two input fields, the username and pasword - the file calls itself to validate input. No rocket science here, but why is it not updating the session file. Not permissions or anything, as the register file works fine.

 

Any ideas???? THX

 

<?

session_start();

 

serverhost,serveruser,serverpass,db (These are set here with the correct info)

 

if(!$connect = @mysql_connect(serverhost,serveruser,serverpass)) {

echo $mysqlerror = mysql_error();

 

}

if(!@mysql_select_db($db)) {

echo $mysqlerror = mysql_error();

}

 

if(isset($_POST['submit'])) {

 

if(!get_magic_quotes_gpc()) {

$username = mysql_real_escape_string($_POST['username']);

}

else {

$username = $_POST['username'];

}

 

$query = "SELECT id, realname, username, email FROM members WHERE username = '$username' AND password = '".md5($_POST['password'])."'";

$result = mysql_query($query);

 

if($result) {

if(mysql_num_rows($result) > 0) {

 

$member = mysql_fetch_array($result);

$_SESSION["SESSIONUSERID"] = $member['id'];

$_SESSION["USERNAME"] = $member['username'];

$_SESSION["REALNAME"] = $member['realname'];

$_SESSION["EMAIL"] = $member['email'];

header("location: index.php");

exit();

}

else {

$formerror['error'] = loginfalse;

}

}

else {

$formerror['error'] = server_error;

}

}

Link to comment
Share on other sites

They are Linux / Apache - but I have solved the problem. I put the Form itself in one file and the actual login verification (the code I posted) in a seperate file, and now it works.

 

So for some odd reason when the form called itself, it is messing something up - not sure what as I have done this in other scripts using sessions for various other things without issue.

 

If any one has any ideas, I'd still be curious to know for future reference.

 

THX

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.