Log in form troubles

Hi, I have a quick question!
I’m working on a page which you must be logged in to view, but I was it so if you are not logged in the login form shows, and once you login, it redirects you back to the page you were at rather than the index page… Here’s the code I have written so far:

[php]<?php
require “header.php”
?>
<?php
if($userdata[‘session_logged_in’])
{
echo(‘You are logged in!’);
}
else
{
?>

You are not logged in!<br />
<form action="<?php echo($phpbb_root_path); ?>login.php" method="post" enctype="multipart/form-data">
Username: <input type="text" name="username"><br />
Password: <input type="password" name="password"><br />
<input type="hidden" name="redirect" value="../">
<input type="submit" value="login" name="login">
</form>
<?php
}

?>[/php]

Now in the redirect value, it redirects me to the index.php page, but I want it to redirect me to the page I was at that I had to be logged in to view, I’m trying to make it as a template so one can use this code for numerous pages without needed to edit the php values… is this possible, or will I have to do it manually…any solutions??

Thanks :D

u need a part checking whether the user is logged in onn all paged that require a login, anyway.
so what i would do is displaying the login on that page and not redirecting at all.

example code (need 2 be adjusted 2 ur needs):
login.inc.php:
[php]session_start();

$loginmsg=’’;
if(isset($_POST[‘login’]))
{
include_once(‘mysqlconnect.inc.php’);
/* check data /
$sql=‘SELECT name FROM users WHERE name="’.mysql_escape_string($_POST[‘user’]).’" AND pass="’.md5($_POST[‘pass’]).’"’;
$result=mysql_query($sql);
$user=mysql_fetch_assoc();
if($user)
{
$_SESSION[‘loggedin’]=true;
$_SESSION[‘user’]=$user[‘name’];
$loginmsg=‘You are logged in!’;
}
else
{
$loginmsg=‘Login failed!’;
}
}
if(!isset($_SESSION[‘loggedin’]) or !$_SESSION[‘loggedin’])
{
/
display form */
echo ‘login’;
echo $loginmsg;
echo ‘’;
echo ‘

Username:
’;
echo ‘
Password:
’;
echo ‘
’;
echo ‘’;
exit;
}
[/php]

then u just have to put include('login.inc.php'); at the top of every page that needs login, and u never leave that site to login (action="" makes u stay on the same site).

thats what i would do.
hope this helps

Sponsor our Newsletter | Privacy Policy | Terms of Service