PDA

View Full Version : Very Basic Sessions Help - V V Desperate


hoodedclaw
09-02-2007, 12:56 AM
i have read about session over and over and i cant get the following script to pass the data nike from page 1 to page 2. here are my scripts.

page1.php

<? session_start();

include "Header.php";

$SESSION['brandname'] = "nike";
echo $SESSION['brandname']; //prints nike
echo session_id(); // prints the session id
?><a href="page2.php?">go to page 2</a>

<? include "Footer.php"; ?>

and this is page 2

<? session_start();

include "Header.php";

echo session_id(); ///this prints the same session id as page 1
echo $SESSION['brandname']; ///this prints nothing - this is my main problem - please someone help :((
$testsesh = $SESSION['brandname'];
echo "$testsesh"; ///this prints nothing,
?>
<a href="page1.php">go to page 1</a>
<? include "_Footer.php"; ?>

pls help - have i misunderstoof how sessions work? I've been trying to do this for months now and now im desperately close to tears. My mainn problem is just understand how i transfer the values of variables on one page onto the next. I thought this was going to be simple, but I've been trying for so long now its ridiculous. years, literally

Also, If i block all cookies, On the first visit to page 1, it echo's a session_id(). if i use the link to go to page 2, the URL in my browser shows it has automaically added the session ID onto the end (i.e www.sugar.com/page1.php?PHPSESSHID=343442......) it shows also the same session ID as page 1 and the session ID carries on the same as i follow the links in a circle, BUT if i use the browser button to go back to first page 1 where the SESSION_ID wasnt originally typed into the url (sugar.com/page1.php), then a new session ID is made.

also, this might seem like a daft question, please ignore it if it is but if i want people to be able to browse the site and not use cookies but sessions instead, are all my urls for different sections of the site going to have a session ID stuck on the end? if this is the simplest way then thats my way

I'm a bit of a noob, if you havent guessed already (well noob minded, but ive been doing it for years lol - just a bit slow basically) but i just cannot get my head around this. Please assume i know very little :D - very much appreciatte any help. i am desperate - extremely desperate its for terminally ill person - ps , the header and footer files just have html and image s etc, nothing active.

areidmtm
09-02-2007, 09:19 AM
To start your session, use this


ini_set('url_rewriter.tags','');
session_start ();
header('Cache-control: private');


Then to call or set the session, use this
$_SESSION['brandname']

hoodedclaw
09-02-2007, 12:32 PM
thats sorted the session ID issue, many thanks for that, but i still cant seem to call the variable.

how would you change my script on page 2 to show the brand "nike"? becuase every tutorial i have read indicates that this should work, but alas no...

areidmtm
09-02-2007, 02:33 PM
It should work.


$_SESSION['brandname'] = "nike";

echo $_SESSION['brandname'];


You have to remember to start the session one every new page. But it looks like you're doing that.

Remember the underscore