Welcome! Log In Create A New Profile

Advanced

Task 5B-1

Posted by Christopher 
Announcements Last Post
Announcement : Programming Students at UNISA School of Computing 06/19/2019 02:01PM
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
Task 5B-1
March 05, 2008 04:07PM
Done

Im using ie and mozila firefox and neither one downloads the cookie to c:\windows\cookies as stated in the manual.
IE downloads it to C:\Documents and Settings\ChristopherW.MOBS\Local Settings\Temporary Internet Files\
Not sure where Firefox downloads it to!
Re: Task 5B-1
March 05, 2008 04:28PM
Not sure but think Firefox stores all cookies in a file called "Cookies" in C:\Documents and Settings\ChristopherW.MOBS\Application Data\Mozilla\Firefox\Profiles\4dwfo577.default

You can view your cookies if you go Tools-> Options
Re: Task 5B-1
March 05, 2008 04:30PM
Second time lucky!

Not sure but think Firefox stores all cookies in a file called "Cookies" in C:\Documents and Settings\ChristopherW.MOBS\Application Data\Mozilla\Firefox\Profiles\4dwfo577.default

You can view your cookies if you go Tools-> Options -> Privacy -> Show cookies
Re: Task 5B-1
March 22, 2008 01:59PM
Finally found my cookies file as well!

I tested my script - and on refresh, the page didn't pick up the cookie and show the delete cookie link. I then read one of the 2007 forums and one guy said that we had to query the $_COOKIE autoglobal because the $background variable is not automatically defined.

So I included the code below (which he gave) just above the if statement on cookie.php and woweeee the code worked. But to be honest I am confused as to what this line of code actually says in english! I know the first part checks to see if the variable has been set but I am lost from the question mark onwards..and what is the semi-colon for?

isset ($_COOKIE['background']) ? $background = ($_COOKIE['background']) : $background="";
Re: Task 5B-1
March 22, 2008 02:05PM
Also, could this line of code be condensed in any way?
avatar
Mac
Re: Task 5B-1
March 23, 2008 11:39AM
There are many ways to write PHP code. We stay with what is in the manual, otherwise this course will continue for ever and we will stray into an advanced course.

$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];

// The above is identical to this if/else statement

if (empty($_POST['action'])) {
$action = 'default';
} else {
$action = $_POST['action'];
}


Stay with PHP4 and the basics for now.

Why? See http://www.gophp5.org/

5 is only now being pushed over 4.
Re: Task 5B-1
March 27, 2008 07:58AM
Thanks Mac, trying to do this the php 4 way exactly as it is in the manual but can't get it to work. The colour changes but when I go back and reresh I dont get the delete cookie link. It will only work when I put this code in, which is PHP5.

isset ($_COOKIE['background']) ? $background = ($_COOKIE['background']) : $background="";

This is my code for cookie.php

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>";
}
?>
avatar
Mac
Re: Task 5B-1
March 27, 2008 08:00AM
But is XAMPP set to version 5 or to version 4?
Re: Task 5B-1
March 27, 2008 08:34PM
Completed hot smiley
Re: Task 5B-1
March 29, 2008 10:25AM
It was set to version 5, changed it to 4 and it still doesnt work..doh!
avatar
Mac
Re: Task 5B-1
March 31, 2008 12:49PM
//Code for cookie.php

<?php
if(isset($_COOKIE['background'])){
$background = $_COOKIE['background'];
}
else {
$background="";
}
if(isset($background)) //or just 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>";
}
?>
</table>

//code for setcookie.php - note there is NO space in the code anywhere from the first <?php tag right up to setcookie. If there is a single space, then you'll get a header error.


<?php
$color=$_GET['color'];
switch ($color) {
case "Yellow":
$bgcolor="#FFCC00";
break;
case "Blue":
$bgcolor="#4682B4";
break;
case "Silver":
$bgcolor="#C0C0C0";
break;
case "Beige":
$bgcolor="#FFE4C4";
break;
}
setcookie ("background", $bgcolor, time()+3600);
echo "<html>";
echo "<head><title>Selected Background Color</title></head>";
echo "<body bgcolor='$bgcolor'>";
echo "</body>";
echo "</html>";
?>

This must work.
JwV
Re: Task 5B-1
April 16, 2008 09:09AM
Hi all

Also had a problem with this task. Will try it this evening. Hope it will work. Am currently running in php5 mode, so I hope it will work. Google here I come.
Re: Task 5B-1
April 18, 2008 01:13PM
done
JwV
Re: Task 5B-1
April 22, 2008 09:08AM
Yeah, it works. Thank goodness.
Re: Task 5B-1
April 26, 2008 12:51PM
Completed
Re: Task 5B-1
May 13, 2008 01:48PM
Done
Anonymous User
Re: Task 5B-1
May 25, 2008 05:48PM
Done
Sorry, only registered users may post in this forum.

Click here to login