Welcome! Log In Create A New Profile

Advanced

TASK 5C

Posted by sandile 
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
August 08, 2007 05:47PM
Struggled a bit with this task, but after reading pages 47-49 of the PHP book I got the solution. So TASK 5C completed.smileys with beer The trick is to recognise that register_globals is set to "off" thus you shouldn't use session_register(). Instead, use session_start() and refer to $bgcolor as $_SESSION['bgcolor'] and use session_id() instead of SID.

I also found a posting by Therese from PHP Sem 1 particulary useful.

Out of the 4 methods I learnt for passing variables between webpages (via URL, using Forms, Cookies and Sessions) I must say that I enjoyed the Session method the most.

And now for MySQL DATABASES...
avatar
Mac
Re: TASK 5C
August 08, 2007 07:26PM
Sandile - you rock!! If I didn't know any better, I would have sworn you are a pro. Point is, there is a wealth of information available on previous PHP forums. And trust me, you can't google or rely on forums, you're PHP dead.
Re: TASK 5C
August 09, 2007 12:41PM
Thanx Mac for the vote of confidence.

I did say that I was taking leave from work just to focus on this PHP course. So these days I'm PHP'd-in 24/7.

I know you said we'll get details of the project 1.5 months before the due date (9 Nov 2007).
Question - Suppose someone successfully finishes all the tasks, say today or tomorrow. Does that mean he has to wait for Sept/Oct to get a sneak preview of the project?
avatar
Mac
Re: TASK 5C
August 09, 2007 05:52PM
Nothing stops us from making the project available. But generally, we want you to focus in the exercises first.... so the 1st person has reached the last exercise, it will be made avialable
Re: TASK 5C
August 24, 2007 10:17AM
clearly Sandile is leading the pack thumbs up smiley

sessions are fun, however, on a personal note, i only use them when necessary. for a few reasons.

they COULD b a security risk.

they use memory.

what if had a variable $x and you stored it in a session and in a database. then someone changed it in the database but you use the variable from the session and then save it to the database whereby over writing the old updated $x. that might be an issue...

now dont get me wrong, i do love and use session variables, but i guess what i am trying say is, just make sure there are no conflicts of interest when using them

Gilham
Re: TASK 5C
August 24, 2007 06:45PM
On the memory issue - true - session data is stored on the server - this may have a memory overhead.

On security - I believe sessions are more secure since data is not transmitted between the client and server many times like in cookies. Remember that cookie data sits on the client side but session data sits on the server.

Another beauty of sessions is that they will work even if the user's browser doesn't accept cookies.

In addition session variables are normarly used for short term storage as they expire between visits to pages. So if you wanted to create a variable $x to be stored in a database for later use then it wouldn't be advisable to store the variable in a session.
Re: TASK 5C
August 29, 2007 08:41AM
I agree with Sandile as well the sessions should be secure due to no transmission between the client and server many times...

but the sessions are really fun and enjoyable...

im almost there i couldnt use a pc for a while so i might be a little behind..catching up though smile
Re: TASK 5C
September 03, 2007 10:49AM
Task 5C Completed...
Re: TASK 5C
September 03, 2007 11:13AM
from an SEO point of view, instead of using <b></b> rather use <strong></strong>

it has the same effect however; search engines prefer the "strong" to the "b"...
Re: TASK 5C
September 10, 2007 05:50PM
5C Completed - Tanx 4 the tips Sandile
Re: TASK 5C
September 10, 2007 08:41PM
You're welcome!
Re: TASK 5C
September 13, 2007 01:15PM
Yerrrrrr! I have to admit this task was trickyangry smiley & interestinghot smiley.

After making alteration like Sandile said, by the way thanks, it started making since.

TASK COMPLETED!!!!smileys with beer
Re: TASK 5C
September 14, 2007 09:27AM
Yes, thanks Sandile. I sat with this last night and just couldn't get it to work. Had the session_start() and the $_SESSION[] going, but seem to have missed the session_id() smiling bouncing smiley

Will give it another shot tonight.
Anonymous User
Re: TASK 5C
September 16, 2007 08:31PM
Task 5C done.
Re: TASK 5C
September 28, 2007 09:21AM
So, this task is pretty much done, but I'm having 1 small issue(maybe only perceived?). I get the page to change colours, and changes are stored in the session as well as passed to the 2nd page. The issue I have is that I can't get the refresh to do what I think it's intention is, namely to change the colour back to that which is stored in the session variable. Or maybe the issue lies in the fact that the colour is always written to the session?

My code:
_____________________________________________________________________
<?php
session_start();
$color = $_GET['color'];

if (isset ($color)) {
switch ($color) {
case "Yellow":
$_SESSION['bgcolor']="#FFCC00";
break;
case "Blue":
$_SESSION['bgcolor']="#4682B4";
break;
case "Silver":
$_SESSION['bgcolor']="#C0C0C0";
break;
case "Beige":
$_SESSION['bgcolor']="#FFE4C4";
break;
default:
$_SESSION['bgcolor'] = "white";
break;
} // end switch
}
if (empty ($_SESSION['bgcolor'])) {
$_SESSION['bgcolor'] = "white";
}
?>
<html>
<head><title>Session Example</title></head>

<body bgcolor='<?php echo $_SESSION['bgcolor']; ?>'>

<form method=GET action='session.php?<?php echo session_id(); ?>'>
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 color'>
</form>
<a href='session.php?<?php echo session_id(); ?>'>Refresh page, Dont change background color</a>
<br><br>
<a href='session2.php?<?php echo session_id(); ?>'>To other page</a>


</body>
</html>

_________________________________________________________________________________

Help please smile
Re: TASK 5C
September 28, 2007 12:33PM
hey tobler

your php code is perfect!!! smiling smiley

i believe that there are just quotes missing from method=GET

it should be method="GET" otherwise its perfect!!!

i prefer using double quotes for html.

also what i did is i put an at sign "@" before the input variable just to suppress any know errors.

what i would like to know is, is this bad coding practice?

Please see the code below:
-------------------------------------------------

<?php
session_start();
$color = @$_GET['color'];

if (isset ($color)) {
switch ($color) {
case "Yellow":
$_SESSION['bgcolor']="#FFCC00";
break;
case "Blue":
$_SESSION['bgcolor']="#4682B4";
break;
case "Silver":
$_SESSION['bgcolor']="#C0C0C0";
break;
case "Beige":
$_SESSION['bgcolor']="#FFE4C4";
break;
default:
$_SESSION['bgcolor'] = "white";
break;
} // end switch
}
if (empty ($_SESSION['bgcolor'])) {
$_SESSION['bgcolor'] = "white";
}
?>
<html>
<head><title>Session Example</title></head>

<body bgcolor="<?php echo $_SESSION['bgcolor']; ?>">
<form method="GET" action="session.php?<?php echo session_id(); ?>">
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 color">
</form>
<a href="session.php?<?php echo session_id(); ?>">Refresh page, Dont change background color</a>
<br><br>
<a href="session2.php?<?php echo session_id(); ?>">To other page</a>
</body>
</html>
Re: TASK 5C
September 28, 2007 01:13PM
Thanks Super G. I had left the PHP for a week, looked at it again last night & finally figured the code. Now I can get to the db stuff.
Re: TASK 5C
September 28, 2007 02:33PM
awesome!!!
Re: TASK 5C
September 28, 2007 02:51PM
That's what I thought after the struggle. Considering that using sessions will be an integral part of the project I suppose we will need to be able to use them!
Re: TASK 5C
October 13, 2007 02:18PM
Task 5 C done, not an easy one, had me going for a while, cool though.
Re: TASK 5C
November 18, 2007 04:42PM
Thank Sandile, I think that I would have really struggled here if it wan't for your comments - task completed
Sorry, only registered users may post in this forum.

Click here to login