Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Problem

Status
Not open for further replies.

molecul3

Technical User
Joined
Apr 17, 2003
Messages
182
Location
HK
I've created a session on all my files... below is a sample...

<?php
session_start();
header(&quot;Cache-control: private&quot;);//IE 6 fix
header (&quot;Expires: Mon, 26 Jul 1997 05:00:00 GMT&quot;);
header (&quot;Last-Modified: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;) . &quot; GMT&quot;);
header (&quot;Cache-Control: no-cache, must-revalidate&quot;); // HTTP/1.1
header (&quot;Pragma: no-cache&quot;);
if ($_SESSION['lname'] == &quot;username&quot;) {
}
else
{
die(&quot;Please <a href=\&quot;index1.htm\&quot;> Login </a>As Lecturer First!<br>&quot;);

}
?>

the problem here is there is an error when I code files that have session and I include a file that has a session also. The 2 sessions seem to clash. An error occurs. How do I fix this problem?
 
I don't understand what you are asking for.

A single browser has only 1 session at a time. You can only have 2 sessions if you have different browser instances, so I don't know how you come to the conclusion that 2 sessions clash.

Also, be aware that you can set the cache control mechanisms with the session:

Please explain more about the error.
 
Hmm... let me try to explain.

I have to files. File1.php and File2.php
Both these files have the same session code as stated on top. The problem here is when i code File1.php, i use the include(&quot;File1.php&quot;);

This is where the error occurs as the file has in a way become one and there are now 2 sessions... therefore an error is produced.
 
Here's a suggestion:

1. Put your session starting code into a separate file, I'd call it a module.
2. use include_once() to include the module in the files.

This will assure if you include a file within another file the components loaded with include_once('filePathetc') will only included once.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top