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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sessions problem

Status
Not open for further replies.

meeble3

Programmer
Nov 8, 2004
52
GB
I have done a small site with sessions. If you log in then go straight to the page that only lets you see it if you are logged in, that is fine.

If you log in then go round the site THEN go to the special page it says you are logged out.

How do you keep track all the way round?

I thought you just had to have:

<?
session_start();
?>

at the top of each page?

Cheers

James
 
yea you need session_start(); at the top of each page.

what i do is put session_start(); at the top of my config.php and then include that in each page of my site.

my config includes db connections, date, time and other functions for my site!

Click Here for more info

have a look there for more info

Regards,

Martin

Gaming Help And Info:
 
Code:
<?php
session_start();

//set a session called user
$_SESSION['user'] = "TestUser";

//echo $_SESSION['user'];
?>
<a href="page2.php">Next Page</a>

-----------PAGE 2-----------
<?php
session_start();

echo $_SESSION['user'];

?>

does this work for you?

remember: you need session_start(); at the top of each page

Regards,

Martin

Gaming Help And Info:
 
If you have a paranoid firewall, you might need to include the SID in the href, form action, or similar:
Code:
<?php
session_start();

//set a session called user
$_SESSION['user'] = "TestUser";
?>
<a href="page2.php?<?=SID?>">Next Page</a>

-----------PAGE 2-----------
<?php
session_start();

echo $_SESSION['user'];
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top