I want to use session variables in the pages that I am setting up as a means to tell if a user is logged in. Once a user's submitted info is matched to a database I want to set the session variable to 1. I want this variable to follow them through out all the pages until they click a button to logout. I can't get the session variable to go accross pages. Here is what I have done so far.
<html>
<head>
<title>Count_me.php</title>
</head>
<body>
<?php
session_start();
session_register('count');
$count++;
echo "<p>You've been here $count times. Thanks!</p>";
echo ("<a href='http://www.htmlforums.com/archive/index.php/count_me2.php'>link</a><br />");
?>
</body>
</html>
<html>
<head>
<title>Count_me2.php</title>
</head>
<body>
<?php
$count=$_SESSION['count'];
echo "<p>You've been here $count times. Thanks!</p>";
?>
</body>
</html>
If I refresh the first one the counter works fine, but if I try to follow the link the variable is not available in the second page. Any thoughts?you have to have session_start() in any page u want the session variable avaliable to
ex.:
<html>
<head>
<title>Count_me2.php</title>
</head>
<body>
<?php
session_start();
$count=$_SESSION['count'];
echo "<p>You've been here $count times. Thanks!</p>";
?>
</body>
</html>session_start has to be before any html is outputted to the screen. it cannot be anywhere else
<?php
session_start();
?>
<html>
<head>
<title>Count_me2.php</title>
</head>
<body>
<?php
$count=$_SESSION['count'];
echo "<p>You've been here $count times. Thanks!</p>";
?>
</body>
</html>Thanks for your help, that was a :doh: moment
<html>
<head>
<title>Count_me.php</title>
</head>
<body>
<?php
session_start();
session_register('count');
$count++;
echo "<p>You've been here $count times. Thanks!</p>";
echo ("<a href='http://www.htmlforums.com/archive/index.php/count_me2.php'>link</a><br />");
?>
</body>
</html>
<html>
<head>
<title>Count_me2.php</title>
</head>
<body>
<?php
$count=$_SESSION['count'];
echo "<p>You've been here $count times. Thanks!</p>";
?>
</body>
</html>
If I refresh the first one the counter works fine, but if I try to follow the link the variable is not available in the second page. Any thoughts?you have to have session_start() in any page u want the session variable avaliable to
ex.:
<html>
<head>
<title>Count_me2.php</title>
</head>
<body>
<?php
session_start();
$count=$_SESSION['count'];
echo "<p>You've been here $count times. Thanks!</p>";
?>
</body>
</html>session_start has to be before any html is outputted to the screen. it cannot be anywhere else
<?php
session_start();
?>
<html>
<head>
<title>Count_me2.php</title>
</head>
<body>
<?php
$count=$_SESSION['count'];
echo "<p>You've been here $count times. Thanks!</p>";
?>
</body>
</html>Thanks for your help, that was a :doh: moment