Welcome! Log In Create A New Profile

Advanced

Topic 5B

Posted by allenvd 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Topic 5B
August 23, 2006 09:24AM
Completed.
Re: Topic 5B
September 20, 2006 08:30PM
Topic Completed

Remember that cookie support can easily be disabled by a user, so they are a "nice to have", therefore do not rely on them 100%
Re: Topic 5B
September 21, 2006 04:37PM
Topic 5C completed
Re: Topic 5B
September 28, 2006 02:55PM
Completed.
Re: Topic 5B
October 01, 2006 08:20PM
I am having trouble with 5B. The first steps are fine - I can set the cookie and the file is being saved in my cookies folder. There seems to be a problem with reading it though, as the variable $background is always empty. I have used "echo empty($background);" to verify this. The code is pasted below. Is there something I am missing?

I am also having a similar problem with the login code on page 371 - my auth.inc.php file cannot redirect the browser using the $_SERVER['PHP_SELF'] path but it can if I hard code the file name. Is this a related problem?

Any ideas? Thanks, Alice



My code for cookie.php is as follows:

<?php
echo empty($background);

@extract($_GET);


If ($background)
{
echo "<html>";
echo "<head><title>Selected Background Color</title></head>";
echo "<body bgcolor='$background' vlink='white'>";
echo "<a href='delete_cookie.php'>Delete Cookie</a>";
echo "</body>";
echo "</html>";
}
else
{
echo "<html>";
echo "<head><title>Select a Background Color</title></head>";
echo "<body>";
echo "<form method=GET action='setcookie.php'>";
echo "Select a background color";
echo "<br>";
echo "<input name='color' TYPE='radio' VALUE='Yellow'> Yellow";
echo "<br>";
echo "<input name='color' TYPE='radio' VALUE='Blue'> Blue";
echo "<br>";
echo "<input name='color' TYPE='radio' VALUE='Silver'> Silver";
echo "<br>";
echo "<input name='color' TYPE='radio' VALUE='Beige'> Beige";
echo "<br>";
echo "<br>";
echo "<input type='submit'>";
echo "</form>";
echo "</body>";
echo "</html>";
}
?>


My code for setcookie.php is as follows:

<?php
@extract($_GET);

switch ($color) {
case "Yellow":
$bgcolor="#FFCC00";
break;
case "Blue":
$bgcolor="#4682B4";
break;
case "Silver":
$bgcolor="#C0C0C0";
break;
case "Beige":
$bgcolor="#FFE4C4";
break;

}

//INSERT CODE HERE TO SET THE COOKIE

setcookie ("background", $bgcolor, time()+3600);

echo "<html>";
echo "<head><title>Selected Background Color</title></head>";
echo "<body bgcolor='$bgcolor'>";
echo "</body>";
echo "</html>";
?>
avatar
Mac
Re: Topic 5B
October 02, 2006 12:50PM
Just search topic 5c from semester 1 - try SESSION
Re: Topic 5B
October 03, 2006 02:12PM
Thanks, Mac. I will do so. I had already tried to do this but found that the PHP Sem 1 forum postings had disappeared from the list; they do seem to be available again now though. (Actually, I thought it was a deliberate ploy to stop us getting too much help from there for the pratical!).
Re: Topic 5B
October 03, 2006 04:42PM
Topic completed
avatar
Mac
Re: Topic 5B
October 03, 2006 06:35PM
No way Alice - this course is about you getting to like PHP, so we won't stand in your way smiling smiley
avatar Re: Topic 5B
October 03, 2006 08:47PM
All done here.
Sorry, only registered users may post in this forum.

Click here to login