Forum Moderators: coopster

Message Too Old, No Replies

sessions issue

         

kumarsena

8:35 am on Sep 25, 2004 (gmt 0)

10+ Year Member



hey guys,

got a little problem with a session script. used to work all those months ago...

anywa using sessions to let the site visitor choose aa skin for my site. the code is as follows:

to set session:

<?php
session_start();

//check if 'skin' is set
if(!isset($_GET['skin']))
{
$skin = 'flyaway_yellow3.css';
}

else{
$skin = $_GET['skin'];
}

// Register session key with the value
$_SESSION['skin'] = $skin;

header("Location: " . $_SERVER['PHP_SELF']);

?>

on each skinnable page:

<?php
session_start();

//session code
//header('Cache-control: private'); //IE 6 Fix

if ( isset($_SESSION['skin']) ) {

$skin = $_SESSION['skin'];
}

else {
$skin = "flyaway_yellow3.css";

}

//end session code

//start art code
if(isset($_GET['art']))
{

if ($_GET['art']=='index.php3')
{
$art='index.txt';
}

else
{
$art= $_GET['art'];
}
}

else{
$art='index.txt';
}

?>

dont think the last bit here is relevant, but i put it here just in case. using it to load content.

so far i dont think ive done anything wrong. but i get the following messege from firefox and ie doesnt even load....well it takes forever and i never bothered to wait..any help aprecited. is it that the header redirection is somehwat 'wrong' here?

this is the messege from ff:

redirection limit for this url exceeded. unable to load requested page. this may be caused by cookies thta are blocked.

thanks
kumar

kumarsena

8:37 am on Sep 25, 2004 (gmt 0)

10+ Year Member



just a tought...

this is the links im using to call the script to set the session...

<p>
<a href="setskinvalue.php3?skin=boeing.css">
Boeing</a>

<br />
<a href="setskinvalue.php3?skin=flyaway_yellow3.css">
Fly Away</a>
</p>

looking at ies behaviour, it seems like its entered a forever loop. so maybe im not understanding the use of

header("Location: " . $_SERVER['PHP_SELF']);

mincklerstraat

8:59 am on Sep 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like you might be right, k. The location header sends your user's browser to the address indicated. And $_SERVER['PHP_SELF'] is the address of the script that was called by the browser. So your user gets continually resent to the same page - yes, a loop. What you might want to do is check if the session value is the same as the value that's input there - i.e., if no value is given, and the session value is set as that flyawayyellow.css or whatever, or if there is no session value available, the script doesn't send location headers to itself, but instead to some other page. In fact, for this script, there seems like there's no reason to give location headers to the same script at all - this might be a remnant from a time that this file was somehow or other included from a different script or file, in which case the php_self variable would have been that other file from which this script was included.

What I'd do if I were you is: make the link to switch skins point to this page, with not only the new skin set as a parameter, but also the originating page set as a parameter. Make the location header then point to this originating page; and if for some reason it's not set, make it point to the home page or an error page.

You've been learning a lot of php lately, kumarsena! ;)

kumarsena

9:14 am on Sep 25, 2004 (gmt 0)

10+ Year Member



what i was trying to do here was to redirect to the page that the user called teh script from. i dont thnik i planned ti properly though cause i only have one page -index.php. the content is 'included'. so i guess i want to redirect to the index page but with &art (thats the content, articles if u like) set to whatever is already set.

that should work i guess.

thanks alot for ur input there...ill look into ur suggestions.

yeah, alot of php, the well of php never seems to empty, so iguess its a lifelong learning process...he he he

kumarsena

9:30 am on Sep 25, 2004 (gmt 0)

10+ Year Member



thank you so much minckler, it is now working...appreciated...

once again thanks...i just had to keep the value for art, so thta whatever the info was current was once agin loaded..

kumar