PHP Session variables

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
murph2481
Forum Newbie
Posts: 20
Joined: Mon Jun 27, 2005 1:48 pm

PHP Session variables

Post by murph2481 »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I am trying to set the a user varible to filter results on a table.  It works when i come from a form via http post but when i do a redirect to this page it says _session is undefined.  But i just defined it when i first ran through and it shouldn't lose it's value because it is a session variable.  Someone please help...

Code: Select all

<? if (isset($_POST['GetUser']))
	{
		$_SESSION['userid'] = $_POST['User'];
		if ($_POST['User'] <> 0){$_SESSION['filter'] = ' where owner_id = ' . $_POST['User'];}
	}
?>

<?
	$query = 'select * from Project_List '. $_SESSION['filter']  . ' order by CUSTOMER_NAME asc';	
?>
Thanks in advance,
Dan


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sounds like you haven't started the session: session_start()
murph2481
Forum Newbie
Posts: 20
Joined: Mon Jun 27, 2005 1:48 pm

Session is started

Post by murph2481 »

I have started the session using that command.

Can i not set a varible on one page and use it on another? without going through a post or a get?

Dan
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have to start the session system on all pages you wish to use session data on.
murph2481
Forum Newbie
Posts: 20
Joined: Mon Jun 27, 2005 1:48 pm

Still not defined

Post by murph2481 »

Alright I tried putting the session_start() on all pages that are referring to that $_SESSION['name'] and still no luck. It does work the first time i come into the page via a form post.

But when i redirect to the URL in the same session it says variable is not defined...

I know in ASP i could do a session("name") = request.form("txtname") and that session("name") i could call from any page no matter how i got there.

Please help this is driving me up the wall :x

Dan
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

You need to have session_start() at the top of every page, even ones that you redirect to.
Post Reply