Beauford Posted March 15, 2008 Share Posted March 15, 2008 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; } } Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 15, 2008 Share Posted March 15, 2008 "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." Is your hosting service also Windows/IIS? or are they Linux/Apache? Quote Link to comment Share on other sites More sharing options...
Beauford Posted March 15, 2008 Author Share Posted March 15, 2008 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.