Jump to content

PHP cookies not working remotely


kalm1234

Recommended Posts

Hi all,

 

Recently, I upgraded my apache and PHP version at the same time.  When I did, it seemed like it was a smooth upgrade and nothing had gone wrong.  I tested my site locally, but a friend of mine tried it and he had a problem logging in.  The cookies were not working remotely, but were working locally.  My php version is 5.3.2.  My site was working perfectly before, but since I upgraded, the cookies scripts I made have not been working for remote users.  Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/202704-php-cookies-not-working-remotely/
Share on other sites

I host my own server.  I double checked the session section in my php.ini and cannot find a problem, though that's not saying much as I am new to this.

 

Here is my login page:

 

<?php

$user = $_POST['username'];
$pass = $_POST['password'];
if (($user == "") || ($pass == ""))
{
echo 'Please enter the form correctly.';
exit();
}
if (file_exists("../../users/".$user.".php"))
{
  $userfile = "../../users/".$user.".php";
  $fh = fopen($userfile, 'r');
  $contents = fread($fh, filesize($userfile));

  $lines = explode("\n",$contents);
  fclose($fh);

  if (crypt($pass, $lines[6]) == $lines[6])
  {
   $ip=$_SERVER['REMOTE_ADDR'];
   if ($ip == '127.0.0.1')
   {
    setcookie("loginhda5", $user, time()+3600, "/", "127.0.0.1");
   }
   else
   {
    setcookie("loginhda5", $user, time()+3600, "/", "65.5.164.229");
   }

  }

  else

  {
   echo "The username or password you entered is invalid. Please <a href='../index.php'>try again</a>";
  }

}
else
{
echo "The username or password you entered is invalid.  Please <a href='../index.php'>try again</a>";
}
?>

Sorry if its not spaced out enough.

 

I'm pretty sure there is nothing wrong in the code (nothing that would prevent it from working anyway).

The script does not give me any errors when trying to open the file, so I didn't think it was a problem with the folder permissions.  My friend has cookies enabled because he had never had a problem with it before.  Also, now I am getting messages from others that they are having trouble too.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.