JakkyD Posted January 28, 2011 Share Posted January 28, 2011 My school is running PHP 4.3.2 on its network, and I'm running PHP 5.3.1 on my localhost machine using Xampp/Apache. My login system works perfectly at school, however $_SESSION["LoggedIn"] does not register, recognise nor acknowledge on my home system. It's not the script itself as I've copied the files across, so in theory it should work exactly the same? I've compared phpinfo()'s and within the session category all values are the same. The database/MySQL works fine on both networks so it's not a problem to do with this. Any ideas? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/ Share on other sites More sharing options...
ChemicalBliss Posted January 28, 2011 Share Posted January 28, 2011 Are you running windows 7? If you are there are more than likely Read-Only permissions on the session folder. Make sure there is not. Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166588 Share on other sites More sharing options...
BlueSkyIS Posted January 28, 2011 Share Posted January 28, 2011 It's not the script itself as I've copied the files across, so in theory it should work exactly the same? no, not necessarily. whether register_globals is on, path differences between windows/non-windows, there are lots of things that can change between installations. we'd need to see code to try to help troubleshoot the problem. regardless, if you don't have this at the top of your script, it might help spot any unexpected problems error_reporting(E_ALL); ini_set("display_errors", -1); Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166591 Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2011 Share Posted January 28, 2011 We'd need to see the code that's causing the problems. Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166592 Share on other sites More sharing options...
JakkyD Posted January 28, 2011 Author Share Posted January 28, 2011 Are you running windows 7? If you are there are more than likely Read-Only permissions on the session folder. Make sure there is not. Hope this helps Yes at home I'm running Windows 7 whereas the school is running XP. Linux for the web hosting I think :/ I've unset read-only to the whole xampp folder and that didn't change anything. It's not the script itself as I've copied the files across, so in theory it should work exactly the same? no, not necessarily. whether register_globals is on, path differences between windows/non-windows, there are lots of things that can change between installations. we'd need to see code to try to help troubleshoot the problem. regardless, if you don't have this at the top of your script, it might help spot any unexpected problems error_reporting(E_ALL); ini_set("display_errors", -1); I've just looked at phpinfo() and register_globals is off for my home network. I assume this should be set to on? How do I do this? Thanks both of you. Edit - I've looked at my schools phpinfo() and register_globals is also off so I now assume this isn't the problem. We'd need to see the code that's causing the problems. There isn't much to the code: LoginDo.php <?php $con = mysql_connect("localhost","root",""); //Connect to database if (!$con) { die('Could not connect: ' . mysql_error()); //Produces error if database connection is unsuccessful } mysql_select_db("database",$con); // Define $Email and $Password $Email=$_POST['Email']; $Password=$_POST['Password']; // To protect MySQL injection (more detail about MySQL injection) $Email = stripslashes($Email); $Password = stripslashes($Password); $Email = mysql_real_escape_string($Email); $Password = mysql_real_escape_string($Password); $Password=md5($Password); $sql="SELECT * FROM customers WHERE Email='$Email' and Password='$Password'"; $result=mysql_query($sql); $query_row=mysql_fetch_array($result); $CustomerID = $query_row[CustomerID]; $Forename = $query_row[Forename]; // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $Email and $Password, table row must be 1 row if($count==1){ // Register $Email, $Password and redirect to file "LoginSuccessful.php" session_start(); $_SESSION["LoggedIn"] = '1'; $_SESSION["CustomerID"] = $CustomerID; $_SESSION["Forename"] = $Forename; $_SESSION["Email"] = $Email; header("location:LoginSuccessful.php"); } else { echo "Wrong Email Address or Password"; } ?> LoginSuccessful.php <?php session_start(); if(!$_SESSION["LoggedIn"] == '1'){ header("location:index.php"); } $Email = $_SESSION["Email"]; $CustomerID = $_SESSION["CustomerID"]; $Forename = $_SESSION["Forename"]; ?> <html> <body> Login Successful <?php echo "Welcome"; echo $Email; echo $_SESSION["CustomerID"]; echo $_SESSION["Forename"]; echo $CustomerID; echo $Forename; ?> </body> </html> (I was just messing around in this file seeing if I could echo the SESSIONS and its variables) Both these files work fine on the schools system Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166595 Share on other sites More sharing options...
BlueSkyIS Posted January 28, 2011 Share Posted January 28, 2011 so you log in successfully on index.php, get header()'d to LoginSuccessful.php, and then immediately get sent back to index.php because !$_SESSION["LoggedIn"] is not equal to '1'? try adding error check after query to make sure it's working? $result=mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166702 Share on other sites More sharing options...
jcbones Posted January 28, 2011 Share Posted January 28, 2011 Did you do a database dump from school, to populate your database at home? Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166710 Share on other sites More sharing options...
laffin Posted January 29, 2011 Share Posted January 29, 2011 Enable the session support in php.ini Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166875 Share on other sites More sharing options...
ChemicalBliss Posted January 29, 2011 Share Posted January 29, 2011 Try usnig the PHPSESSID query var and see if it works, if it does it's just not giving you the session cookie. Take a look at your browsers security and try setting a normal cookie. Quote Link to comment https://forums.phpfreaks.com/topic/225968-my-php-script-works-at-school-but-not-at-home/#findComment-1166938 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.