Confused about sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kral_majales
Forum Commoner
Posts: 36
Joined: Wed Nov 24, 2004 2:47 pm
Location: Dorset, UK

Confused about sessions

Post by kral_majales »

A while ago, I made a user login system for a site of mine. It was my first attempt at something like that in php, and not surprisingly, it didn't work properly!

I was using sessions for the users, and that's where I think the problems came from. When a user logged in, they logged in fine, then, when they went to another page, they were logged in as one of the other users! This was a really weird problem. I then switched over to using cookies instead, and it all worked perfectly (so it wasn't too much of a failure!).

I think part of the problem comes from my own confusion about sessions. This time round, I'd like to send the session id from one page to another using the SID value appended to the url. Once I've done that, how do I then access that session id on the next page that the user goes to and tell the script to use that session? Or is it done automatically?

any help would be greatly appreciated!

K
PanK
Forum Commoner
Posts: 36
Joined: Mon Nov 22, 2004 1:24 pm
Location: Richmond Hill, ON, Canada

Post by PanK »

Once you opend session you have it in the window.
so, when you go to another page, to check if session openned, you write:

Code: Select all

<?php
if (!isset($_SESSION["person_id"])){
	header ("Location: /login.php");
	exit;
	}

?>
kral_majales
Forum Commoner
Posts: 36
Joined: Wed Nov 24, 2004 2:47 pm
Location: Dorset, UK

Post by kral_majales »

ahh ok so you don't need to get the session id manually and put it into the script if the id has already been supplied in the url? cunning!

i expect this was why it didn't work for me before. it worked on my pc here, but once i uploaded it to my servers online, it didnt work at all!

cheers,

K
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

[absolutely off-topic]
2kral_majales: Aren't you czech? Determining by your nick..?
[/off-topic]
Sorry for off-topic post ;)
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

just yesterday some asked a question similar to this.
it may be helpfull to you

http://codewalkers.com/forum/index.php? ... lm=default
Last edited by rehfeld on Wed Nov 24, 2004 3:29 pm, edited 1 time in total.
kral_majales
Forum Commoner
Posts: 36
Joined: Wed Nov 24, 2004 2:47 pm
Location: Dorset, UK

Post by kral_majales »

MarK (CZ) wrote:[absolutely off-topic]
2kral_majales: Aren't you czech? Determining by your nick..?
[/off-topic]
Sorry for off-topic post ;)
no worries, I'm english though, sorry to say! i got the name from a poem i read years ago, by alan ginsberg i think... :D

P
kral_majales
Forum Commoner
Posts: 36
Joined: Wed Nov 24, 2004 2:47 pm
Location: Dorset, UK

Post by kral_majales »

rehfeld wrote:just yesterday some asked a question just like this

...
lol, it looks like i'm not the only one who has been confused by that, i feel less stupid now!

thanks for the help! :lol:

K
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

kral_majales wrote:
MarK (CZ) wrote:[absolutely off-topic]
2kral_majales: Aren't you czech? Determining by your nick..?
[/off-topic]
Sorry for off-topic post ;)
no worries, I'm english though, sorry to say! i got the name from a poem i read years ago, by alan ginsberg i think... :D

P
He wrote it just in the plane when he was leaving CZ after czech university students named him "King of majales" (if I remember well my literature class :D ). So I thought you could be czech ;)
Ok, back on topic.
kral_majales
Forum Commoner
Posts: 36
Joined: Wed Nov 24, 2004 2:47 pm
Location: Dorset, UK

Post by kral_majales »

MarK (CZ) wrote: He wrote it just in the plane when he was leaving CZ after czech university students named him "King of majales" (if I remember well my literature class :D ). So I thought you could be czech ;)
Ok, back on topic.
ah yeah, that's the one, i remember now! if i remember correctly, it's a pro-peace poem, which was perhaps one of the reasons i liked it. i'm gonna go upstairs and find the book it's in now, lol!

K
Post Reply