Protecting pages, need to be logged in to view.
Moderator: General Moderators
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
1. How would i add users to this?
yeah thats true, i just need to know thee 3 things.
would it be elseif?
2. to logout, can i just add
to login.php and the logout link would be,
<a href=login.php>logout</a>?
3. how can i keep them logged in if they go to a unprotected page?
yeah thats true, i just need to know thee 3 things.
Code: Select all
session_start();
if (empty($_POST['user']) || empty($_POST['pass']))
die('GO AWAY');
if ($_POST['user'] == 'test_user' && $_POST['pass'] == 'test_pass')
{
$_SESSION['log'] = true;
echo '<meta http-equiv="refresh" content="0;url=secure_page.php">';
}
else
die('GO AWAY');2. to logout, can i just add
Code: Select all
session_destroy();<a href=login.php>logout</a>?
3. how can i keep them logged in if they go to a unprotected page?
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
nickman013 wrote:how can i keep them logged in if they go to a unprotected page?
Code: Select all
session_start();
if (empty($_POST['user']) || empty($_POST['pass']))
die('GO AWAY');
if ($_POST['user'] == 'test_user' && $_POST['pass'] == 'test_pass')
{
$_SESSION['log'] = true;
echo '<meta http-equiv="refresh" content="0;url=secure_page.php">';
}
else
die('GO AWAY');- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
anybody?nickman013 wrote:1. How would i add users to this?
yeah thats true, i just need to know thee 3 things.
would it be elseif?Code: Select all
session_start(); if (empty($_POST['user']) || empty($_POST['pass'])) die('GO AWAY'); if ($_POST['user'] == 'test_user' && $_POST['pass'] == 'test_pass') { $_SESSION['log'] = true; echo '<meta http-equiv="refresh" content="0;url=secure_page.php">'; } else die('GO AWAY');
2. to logout, can i just addto login.php and the logout link would be,Code: Select all
session_destroy();
<a href=login.php>logout</a>?
3. how can i keep them logged in if they go to a unprotected page?