View Single Post
  #2 (permalink)  
Old October 27th, 2004, 04:25 PM
droth droth is offline
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok. I found the problem. Here's the movie1.php non-working code:

---------------------------------------------------------
<?php
session_start();
$t=time()+3600;
if ( setcookie('username', 'Joe', $t) == TRUE ) {
   echo "setcookie(\'username\, 'Joe', $t) succeded";
   echo "<br>";
   $tt = $t-time();
   echo "cookie will expire in $tt seconds";
   echo "<br>";
}

echo 'Session ';
//reset($_SESSION);
print_r($_SESSION);
echo "<br>";

echo 'Cookie ';
//reset($_COOKIE);
print_r($_COOKIE);
echo "<br>";

//$_SESSION['username']='Joe12345';
$_SESSION['authuser']=1;
?>

<html>
<head>
 <title>Find my favourite movie!</title>
</head>
<body>
  <?php
  $myfavmovie = urlencode("Life of Bryan");
  echo "<a href='http://localhost/BeginningPhpApacheMySqlDevelopment/chap2/moviesite.php?favmovie=$myfavmovie'>";
  echo "Click here to see information about my favourite movie";
  echo "</a>";
  ?>
</body>
</html>
-----------------------------------------------------------------

and here is the working code:

-------------------------------------------
<?php
session_start();
$t=time()+3600;
if ( setcookie('username', 'Joe', $t) == TRUE ) {
   echo "setcookie(\'username\, 'Joe', $t) succeded";
   echo "<br>";
   $tt = $t-time();
   echo "cookie will expire in $tt seconds";
   echo "<br>";
}

echo 'Session ';
//reset($_SESSION);
print_r($_SESSION);
echo "<br>";

echo 'Cookie ';
//reset($_COOKIE);
print_r($_COOKIE);
echo "<br>";

//$_SESSION['username']='Joe12345';
$_SESSION['authuser']=1;
?>

<html>
<head>
 <title>Find my favourite movie!</title>
</head>
<body>
  <?php
  $myfavmovie = urlencode("Life of Bryan");
  echo "<a href='http://localhost/BeginningPhpApacheMySqlDevelopment/Chap2/moviesite.php?favmovie=$myfavmovie'>";
  echo "Click here to see information about my favourite movie";
  echo "</a>";
  ?>
</body>
</html>
-----------------------------------------------------------------

What?
You can't find the difference?
Here it is:

href='http://localhost/BeginningPhpApacheMySqlDevelopment/chap2/moviesite.php?favmovie=$myfavmovie'>";

href='http://localhost/BeginningPhpApacheMySqlDevelopment/Chap2/moviesite.php?favmovie=$myfavmovie'>";

"Chap2" vs. "chap2". That's it.

The cookie file is named "Chap2/" on creation. But moviesite.php was being called using "chap2/", so in moviesite.php a non-existent cookie file "chap2/" is searched for.

What are the rules governing case sensitivity of cookie files?

As far as I can see, if "chap2/movie1.php" is entered into the browser (IE6) it is changed to "Chap2/movie1.php" before loading, and that is what's used to generate the cookie file. Then if "chap2/moviesite.php" is used in movie1.php, "chap2/moviesite.php" appears in the address line when moviesite.php is loaded, and cookie file "chap2" is not found. If I place my cursor onto the address line of IE6 it selects the entire address. Then when I press enter to reload the page, IE6 reformats the address to use "Chap2" before reloading, and magic - the cookie file is found and the username is displayed.

Mark my words. Computers are truly the work of the devil.
Reply With Quote