Hi all,
I am very new to php and am just playing at the moment to get my head around things. I am trying to set a cookie with the following script and it just doesnt seem to be working!!! here is the script:
<?php
setcookie('username', 'Joe', time()+60);
session_start();
$_SESSION['authuser']=1;
?>
<HTML>
<HEAD>
<TITLE>Find my Favourite Movie!</TITLE>
</HEAD>
<BODY>
<?php
$myfavmovie=urlencode("Life of Brian");
echo "<a href='http://217.41.12.252/cameron/docs/moviesite.php?favmovie=$myfavmovie'>";
echo "Click here to see information about my favourite movie!";
echo "</a>";
?>
</BODY>
</HTML>
I have tried using " quotation marks instead of ' i have also tried putting the cookie after the session_start command, i have even tried assigning the value to a variable instead of using the 'Joe' string and it still refuses to set the cookie!!!!! I have also double checked that the browser i am using to view the website allows cookies.
I use the following script to check whether the cookie has been set:
<?php
session_start();
//check to see if user has logged in with a valid password
if ($_SESSION['authuser']!=1) {
echo "Sorry, but you dont have permission to view this page.";
exit();
}
?>
<HTML>
<HEAD>
<TITLE>My Movie Site - <?php echo $_REQUEST['favmovie']?></TITLE>
</HEAD>
<BODY>
<?php
print_r($_COOKIE);
?>
</BODY>
</HTML>
All this returns however is the following:
Array ( [PHPSESSID] => ec94480afb47cc8aa629e72eb9f31032 )
which (with my limited knowledge ha ha!!) i can work out is only the session ID!!
Can anybody help me figure this one out?
Thanks in advance