Forum Moderators: coopster

Message Too Old, No Replies

Checking sessions

         

electricocean

4:36 am on May 7, 2005 (gmt 0)

10+ Year Member



Hi, I was wondering if there is a way to check the sessions to see if someone has skipped to the next page w/o typing there name. And if they never typed in their name and went to the next page the page would redirect the page to the name login.

my code: ENTERING NAME

<?php
$login = $_GET['op'];

if($login == 'login'){
session_start();
header("Cache-control: private");

$name = $_POST['name'];
$_SESSION['name'] = $name;

echo "Your name is: ";
echo $_SESSION['name'];
echo ", <a href=\"ses.php\">proceed</a>?";
}
else{
$login = null;
echo "<strong>Step 2 - Register Session </strong><br />";
}
?>

<FORM METHOD="POST" ACTION="?op=login">
Enter your Name: <input type="text" name="name">
<input type="SUBMIT" value="Submit">
</FORM>

NEXT PAGE: ses.php

<body>
<?php
session_start();
header("Cache-control: private");
?>
<p></p><font size="30">Hey, <?php echo $_SESSION['name'];?><br>It's you again!</font></P>
<p>Logout: go to:<a href="die.php?back=test_error.php">Admin login</a> or <a href="die.php?back=../../../index.php">Home</a>.</p>
</body>

but this just just prints the text w/o out a name if they did not enter a name.

If anyone can help that would be great.

thanks,
electricocean

anshul

7:27 am on May 7, 2005 (gmt 0)

10+ Year Member



Ideas ( I'll don't write code here ):
Use login page, set $_SESSION[]/$_COOKIE[] variables. Check these on all pages that require logged in to view. See header, session, cookie functions in PHP documentation.

Stormfx

7:37 am on May 7, 2005 (gmt 0)

10+ Year Member



Not totally sure what trying to do, so I'll guess. :)

In ses.php put:


if (!isset($_SESSION['name']) ¦¦ empty($_SESSION['name'])) {
header('Location: [mysite...]
exit;
}

Make sure you put it at the top, before any output :)

electricocean

8:26 pm on May 7, 2005 (gmt 0)

10+ Year Member



Hi,
Stormfx's way worked really well... thanks

electricocean

Stormfx

11:14 pm on May 7, 2005 (gmt 0)

10+ Year Member



I imagine you'll have to tweak it some, but.. You're welcome :)