Page 1 of 1

PHP Session variables

Posted: Mon Oct 10, 2005 12:09 pm
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]

Posted: Mon Oct 10, 2005 3:50 pm
by feyd
sounds like you haven't started the session: session_start()

Session is started

Posted: Mon Oct 10, 2005 4:07 pm
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

Posted: Mon Oct 10, 2005 4:13 pm
by feyd
you have to start the session system on all pages you wish to use session data on.

Still not defined

Posted: Mon Oct 10, 2005 4:17 pm
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

Posted: Mon Oct 10, 2005 7:30 pm
by Jenk
You need to have session_start() at the top of every page, even ones that you redirect to.