Forum Moderators: coopster

Message Too Old, No Replies

Session based site

Do you need the <? session_start()?> tag at the start of all pages?

         

appleg5ive

9:05 am on May 4, 2004 (gmt 0)

10+ Year Member



Do you need to have the <? session_start()?> at the top of every page in a session based site? Or is there something different to put at the top of everypage after login?

jatar_k

5:19 pm on May 4, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



[ca.php.net...]
Note: If you are using cookie-based sessions, you must call session_start() before anything is outputted to the browser.

[ca.php.net...]

Also note that you must start your session using session_start() before use of $_SESSION becomes available.

so, yes.

httpwebwitch

7:36 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is a php.ini setting that autostarts the session on every page. But I use session_start() for scalability in case the code is moved to another server, or if someone mucks about with the php.ini without telling me. It's a good habit.

DrDoc

10:23 pm on May 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Still, there's another way around it, which may be preferrable.
Basically, just assign a file as to be auto prepended, then have this script call session_start() for you ;)

That way you don't have to go through and edit all your pages :)

lildemon

11:45 pm on May 6, 2004 (gmt 0)

10+ Year Member



I have to go with DrDoc on that one, since my whole site is written with a set of pre-pended and appended files (In a manner of speaking, anyhow, I use the include function since I don't have access to any other method of appending files on my server)

My normal files looks something like this:

<?php include('/some/path/to/prepend.inc');?>

Main content.... Can have anything here.

<?php include('/some/path/to/append.inc');?>

This way all my layout can be modified from a total of 3 files: prepend, append and my css file... And adding something like "session_start();" means adding one line to one file.