Welcome! Log In Create A New Profile

Advanced

Task 5C

Posted by Johan Potgieter 
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
Task 5C
April 23, 2007 10:49PM
Completed
Re: Task 5C
April 24, 2007 11:59AM
completed.
Re: Task 5C
April 25, 2007 06:29AM
Completed this task. I personally prefer sessions over cookiesdrinking smiley
Project looks interestingeye popping smiley
Re: Task 5C
April 29, 2007 09:13PM
Completed, I agree, sessions.
avatar Re: Task 5C
May 01, 2007 09:59AM
Done.

Sessions for me also since some users do not allow cookies...

A Successful Nature Inspires Other People...
Re: Task 5C
May 05, 2007 05:01PM
Completed.
Re: Task 5C
May 06, 2007 12:39PM
All good.

The examples took a few changes to get working. Any idea when it became the norm to not have your session variables available as page variables.

J
Re: Task 5C
May 07, 2007 11:22PM
Task complted, with difficulty. I took awhile getting used to sessions but now I understand the value of this function in comparison to using cookies.
Re: Task 5C
May 07, 2007 11:30PM
Completed
Re: Task 5C
May 10, 2007 03:48PM
Hi guys. I can't seem to get "Refresh page, don't change background colour" to work. When I click on the link, the URL at the top says:
http://localhost/StudentPHP/session.php? and the background goes back to white.

Does anyone know what I'm doing wrong?


<?php
@extract($_GET);
@extract($_SESSION);

session_register("bgcolor"winking smiley;

if (isset($color)) {
switch ($color) {
case "Yellow":
$bgcolor="#FFCC00";
break;
case "Blue":
$bgcolor="#4682B4";
break;
case "Silver":
$bgcolor="#C0C0C0";
break;
case "Beige":
$bgcolor="#FFE4C4";
break;
default:
$bgcolor = "white";
break;
} // end switch
}
if (empty($bgcolor)) {
$bgcolor = "white";
}

?>


<html>
<head><title>Session Example</title></head>
<body bgcolor='<?php echo $bgcolor; ?>'>
<form method='GET' action='session.php?<?php echo SID; ?>'>
Select a background color
<br>
<input name='color' TYPE='radio' VALUE='Yellow'> Yellow
<br>
<input name='color' TYPE='radio' VALUE='Blue'> Blue
<br>
<input name='color' TYPE='radio' VALUE='Silver'> Silver
<br>
<input name='color' TYPE='radio' VALUE='Beige'> Beige
<br>
<br>
<input type='submit' value='Change background colour'>
</form>

<a href='session.php?<?php echo SID; ?>'>Refresh page, don't change background colour</a>
<br><br>
<a href='session2.php?<?php echo SID; ?>'>To other page</a>
</body>
</html>
avatar
Mac
Re: Task 5C
May 10, 2007 04:43PM
Have you looked at previous forums? This comes up every year, sooner or later smiling smiley
Re: Task 5C
May 10, 2007 06:37PM
*doh!* yawning smiley

Well, in case someone from next year's course browses here first, I might as well post the solution.

"Instead of SID I use session_id() and put a session_start() on first line of my code. Now there is no need for the session_register["bgcolor"], instead I retrieve the value with $_SESSION["bgcolor"]. " - Miekie
Re: Task 5C
May 12, 2007 05:29PM
Mac / everyone , i have a question on sessions :-

How does the forum keep me logged in each time i visit. I have looked at the forum cookie and see a session ID. On another forum i frequent the cookie contains my user name and encrypted password.

The question is , what do you think is the best way for a user to remain logged in on multiple visits to the same site. Is it possible to create a Session ID and parameters on fist visit and keep that session ID for consecutive visits into infinity. Does each new browser window create a new Session ID. Surely that would create millions of sessions on your server ?

Or - do you put the login or identifying details in a cookie , and if the cookie exists , use those details to log the client into the site and display the "welcome back" notice.

Thanks
J
Re: Task 5C
May 12, 2007 05:51PM
Done
avatar
Mac
Re: Task 5C
May 14, 2007 08:15AM
Cookies lasts until they are deleted, so to remain logged in you have to use cookies. But cookies can be problematic, since people may choose to block cookies, they can become corrupt etc etc. Sessions will always be that - a session which ends when the session ends requiring you to log in on next visit.

So its personal - I use cookies sometimes, other times not. I prefer cookies since it makes it easier next time. But it has its limits.

Here is a nice article I referenced last year with the intention to print it out sometime since it provides some other important tips as well

http://www.mikebernat.com/?a=article&id=PHP%2520Cookies%2520vs%2520Sessions%2520-%2520The%2520Breakdown
Re: Task 5C
June 01, 2007 03:29PM
Completed
Sorry, only registered users may post in this forum.

Click here to login