Jump to content

My PHP script works at school but not at home?!


JakkyD

Recommended Posts

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.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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());

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.