session_start() Question

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
acp26b
Forum Newbie
Posts: 2
Joined: Wed Jul 18, 2007 8:12 pm

session_start() Question

Post 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?
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

Post 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.
acp26b
Forum Newbie
Posts: 2
Joined: Wed Jul 18, 2007 8:12 pm

Post 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?
User avatar
webgroundz
Forum Commoner
Posts: 58
Joined: Thu Jun 21, 2007 1:20 am
Location: Philippines

Re: session_start() Question

Post 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... :) :) :)
Post Reply