Page 1 of 2
PHP session
Posted: Wed Jul 27, 2005 11:11 am
by br5dy
I'm still new with sessions....haha uh...
I got everything hooked up with my site, but I want my site to remember the session. I've read many sites and some say to set a cookie with the username and password, but I'm not sure. Must I also save the session id?
Also, when I return to my site, all of my link will have
?PHPSESSID= and then the last session id. However, my current page (home) won't have it. If I click the link it does nothing.
Thanks again

Posted: Wed Jul 27, 2005 11:41 am
by shiznatix
session_start(); at the top of each page will keep the session alive once started with somtin like
$_SESSION['foo'] = 'bar';
or wahtever else you put there. no need for cookies, cookies are client side and sessions are server side
Posted: Wed Jul 27, 2005 11:57 am
by theda
My question has always been, how the hell do I make a link that sets the session variable <_<
Posted: Wed Jul 27, 2005 2:48 pm
by timvw
Meaby that is because your question is not clear.
- A link, i presume you mean an url that is in a a-tag is nothing more than that. So it can't change the session variable.
- What is 'the session variable'?
I know you can start a session with session_start. I know you can change the sessionid by session_regenerate_id
I know you can store multiple variables in a session, by assignment
$_SESSION['key'] = 'value';
I know you can pass arguments in a URL, for
http://example.com/test.php?id=bar
I know you can use that value to change something in the session..
$_SESSION['id'] = $_GET['id'];
Posted: Wed Jul 27, 2005 4:07 pm
by theda
What I was asking, although using bad phrases... was How do I convert (This was in my original thread which has been so far ignored in the past two days...) a cookie-based website into session-based, where I can do url.com/?cheez=its and have cheez = its in the session.
Posted: Wed Jul 27, 2005 4:15 pm
by John Cartwright
Tim just explained it :\
Posted: Wed Jul 27, 2005 4:17 pm
by josh
To convert cookie site to a session site, you just change $_COOKIE to $_SESSION, that was answered in your other thread and also by tim (or at least some one else that posted the same question), you also need to add session_start() to the top of each page.
As for ?cheez=it...
page1.php
Code: Select all
session_start();
$_SESSION['cheez']='it';
echo ("<a href='page2.php'>click</a>");
page2.php
Code: Select all
session_start();
echo ($_SESSION['cheez']);
Posted: Wed Jul 27, 2005 4:53 pm
by theda
So for all my links, I have to add
Code: Select all
$_SESSION['cheez']='it';
echo ("<a href='page2.php'>click</a>");
?
->Example
Code: Select all
<p> <a href="?del=$ver">eingang</a></p>
<p> <a href="?id=news">neuigkeiten</a></p>
<p> <a href="?id=rants">reklamationen</a></p>
<p> <a href="?id=photos">fotos</a></p>
<p> <a href="?id=poems">gedichte</a></p>
<p> <a href="?id=conts">kontakte</a></p>
<p> <a href="?id=links">seiten</a></p>
<p> <a href="?id=scripts">scripts</a></p>
All my links are ?id=page, so I'd end up changing them all back to page.php and having a ton of session text?
Posted: Wed Jul 27, 2005 5:12 pm
by josh
No, the example you just posted with the ?id=something where "something" is different for each link is not fit for sessions, you'd want to use mod_rewrite to clean that up, sessions are more for storing info that's going to be the same no matter what page you pass it to, for instance the user's username, or a multi part form.
Posted: Wed Jul 27, 2005 6:27 pm
by theda
Well actually, I just remembered something really obvious: I'm not using sessions for my webpage links! <_< But I do have a few links that set cookie-variables (like ?theme=color) How would I get that to work in Sessions?
Posted: Wed Jul 27, 2005 6:30 pm
by josh
theda wrote:Well actually, I just remembered something really obvious: I'm not using sessions for my webpage links! <_< But I do have a few links that set cookie-variables (like ?theme=color) How would I get that to work in Sessions?
We've been over that, replace $_COOKIE with $_SESSION and add session_start() to the top of each page.
Here I'll even post code so we're clear:
page1.php
Code: Select all
session_start();
$color='red';
$_SESSION['color']=$color;
echo ("<a href='page.php'>click here to see what color the theme is</a>");
page2.php
Code: Select all
session_start();
echo $_SESSION['color'];
Posted: Wed Jul 27, 2005 6:46 pm
by theda
Meh... You'll have to forgive me, I just wasn't seeing a connection as to how to do it at the time <_< *kills brain*
Posted: Wed Jul 27, 2005 7:20 pm
by josh
theda wrote:Meh... You'll have to forgive me, I just wasn't seeing a connection as to how to do it at the time <_< *kills brain*
eh, that's ok.. its just that we had gone over this in this thread already.
Posted: Wed Jul 27, 2005 7:45 pm
by theda
Hey, mind if we talk over messenger? I'd probably understand things and spam a little less if I was over messenger.
Posted: Wed Jul 27, 2005 8:40 pm
by josh
Talking to me?
If so:
aim: jshpro2
msn:
jshpro2@hotmail.com
yahoo: jshpro2