i have a problem to redirect user to the requested page after login.
1-this are my files:login.php,register.php,protected.php,plan1.php,member.php et plan2.php,home.php
2-plan1,plan2, and member have a check before people have access.
3-when a user click on plan1 for exemple and get redirect on login.php
4-My problen is after logged in he goes directly to member.php
5-I would like that the user get redirect to plan1.php cause that's the page he wanted to visit.
i found a couple a solution but they didn't work.
///////////////////////////////////////////////////////////////////////////////////////
plan1.php
<?php
session_start();
if(!isset($_SESSION['username']))
{
header('Location: login.php');
exit;
}
?>
///////////////////////////////////////////////////////////////////////////////////////
login.php
<?php
session_start();
echo "<h1>Se connecter</h1>";
if(isset($_POST['submit']))
{
$username=htmlspecialchars(trim($_POST['username']));
$password=htmlspecialchars(trim($_POST['password']));
if($username&&$password)
{
$password=md5($password);
$connect=mysql_connect('localhost','root','');
mysql_select_db('test');
$log=mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' ");
$rows=mysql_num_rows($log);
if($rows==1)
{
$_SESSION['username']=$username;
//header ('Location: membre.php');
header('Location:membre.php'.$_GET['previouspage']);
}else echo "Username/password is not valid";
}else echo"Data missing";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form method="post" action="login.php">
<p>Votre nom d'utilisateur</p>
<input type="text" name="username" />
<p>Votre password</p>
<input type="password" name="password" />
<p>
<input type="submit" value="Connect" name="submit" />
</p>
</form>
<p><a href="register.php">Register</a></p>
<p><a href="accueil.php">Welcome</a></p>
</body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////
membre.php
<?php
session_start();
if(isset($_SESSION['username'])){
echo "Welcome" .$_SESSION['username']."<br/> <a href='logout.php'>Logout</a>";
}
else
{
header('Location:login.php');
}
?>
///////////////////////////////////////////////////////////////////////////////////////////////////
protected.php
<?php include 'login.php'; ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
Sorry you need to be a member to have access!
</body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////////
home.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p>
<?php
echo '<a href="plan1.php?previouspage='.urlencode($_SERVER['REQUEST_URI']).'">Plan1</a>';
?>
<br />
<?php
echo '<a href="plan2.php?previouspage='.urlencode($_SERVER['REQUEST_URI']).'">Plan2</a>';
?>
</p>
</body>
</html>
Thanks in advance.