Page 1 of 1

session_start() Question

Posted: Wed Jul 18, 2007 8:28 pm
by acp26b
I have a pageStart function that initializes each page that is displayed, it loads stuff like the header info and preloaded images. I am trying to implement a login and want to use session variables. The entire site has about 30-40 pages so i did not want to add permission checks to each page so i set up the checks in the pageStart function they look like this:

Code: Select all

//**************************************************************
				//Authentication:
				
					
					
					$invalid = $_SESSION['invalid'];

					if ($invalid != 0)
					{
						header("Location: http://xxx.xxx.x.xxx/xxxxxxxxx/login.php");
						exit();
					}
					
				//****************************************************************
				
	echo $pageheading;
	$pagehead = 1;
	return 	$pagehead;	

}
So my question is, what pages do i need session_start() at the top of? All that call the function? or can i just put it on top of the function? or ontop of the common.php file that the function is in?

Posted: Wed Jul 18, 2007 9:42 pm
by Phoenixheart
You must call session_start() with every page that calls to the function.

Of course, if session.auto_start is set to TRUE, then it's different story.

Posted: Thu Jul 19, 2007 6:44 pm
by acp26b
ok one more question. I will try to explain this the best i can, and will use my customer_edit.php page as an example. My html forms are on the customer_edit page and then the page posts to customer_edit_process.php, the process page handles all the db entries and what not, but the user never sees this page it sends a header and takes the user back to the customer_viewall page. Phoenixheart said, that i will just need to place session_start() at the top of each page that calls the page_start function, but since the customer does not see this page there is no call to page_start so i dont think i will need to include session_start() at the top. But i also read somewhere that you had to have it on all your pages or else the session information will be lost. So my question is will i need to include session_start() on my process pages as well?

Re: session_start() Question

Posted: Thu Jul 19, 2007 7:48 pm
by webgroundz
acp26b wrote:I have a pageStart function that initializes each page that is displayed, it loads stuff like the header info and preloaded images. I am trying to implement a login and want to use session variables. The entire site has about 30-40 pages so i did not want to add permission checks to each page so i set up the checks in the pageStart function they look like this:

Code: Select all

//**************************************************************
				//Authentication:
				
					
					
					$invalid = $_SESSION['invalid'];

					if ($invalid != 0)
					{
						header("Location: http://xxx.xxx.x.xxx/xxxxxxxxx/login.php");
						exit();
					}
					
				//****************************************************************
				
	echo $pageheading;
	$pagehead = 1;
	return 	$pagehead;	

}
So my question is, what pages do i need session_start() at the top of? All that call the function? or can i just put it on top of the function? or ontop of the common.php file that the function is in?
i think you must have an index.php that handles all the includes so that you don't have to include

Code: Select all

session_start()
in every page.

thanks... :) :) :)