php代码重定向到请求登录的页面 [英] php code to redirect to page from where login requested

查看:69
本文介绍了php代码重定向到请求登录的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些代码重定向到请求登录的页面.
但是代码根本不起作用.

请帮忙.
login.php:

I am using some code to redirect to the page from where login is requested.
But the code is not working at all.

please help.
login.php:

<?php



// Inialize session

session_start();



// Check, if user is already login, then jump to secured page

if (isset($_SESSION['username'])) {

header('Location: '.$_REQUEST['from']);



}



?>
<html>

<head>
<title>Kanu Bhawan - Member Login</title>
</head>

<body>

<h3>User Login</h3>

<table border="0">
<form method="GET" action="loginproc.php">
<tr><td>Username</td><td>:</td><td><input type="text" name="email" size="20"></td></tr>
<tr><td>Password</td><td>:</td><td><input type="password" name="password" size="20"></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td><input type="submit" value="Login"></td></tr>
<input type="hidden"  name="id">
</form>
</table>

</body>

</html>



?>


loginproc.php



?>


loginproc.php

<?php

session_start();
require "config.php"; 
$login = mysql_query("SELECT * FROM members WHERE (email = '" . mysql_real_escape_string($_POST['email']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')");

// Check username and password match
if (mysql_num_rows($login) == 1) {
// Set username session variable
$_SESSION['username'] = $_POST['email'];
// Jump to secured page
header('Location: '.$_GET['from']);

}
else {
// Jump to login page
header('Location: login.php');
}

?>



fullprofile.php



fullprofile.php

<?php

// Inialize session
session_start();

// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['username'])) {
header('Location: login.php?from='.rawurlencode($_SERVER['REQUEST_URI'])); 
}

?>
<html>

<head>
<title>Secured Page</title>
</head>

<body>

<p>This is secured page with session: <?php echo $_SESSION['username']; ?>
<br>You can put your restricted information here.</p>
<p><a href="logout.php">Logout</a></p>

</body>

</html>

please help

推荐答案

_SESSION ['username']))) { 标题(位置: ".
_SESSION['username'])) { header('Location: '.


_REQUEST ['from']); } ? > < html > < 头部 > < 标题 > Kanu Bhawan-会员登录< /title > < /head > < 正文 > < h3 > 用户登录< /h3 > < =" 0" < 表单 =" GET" 操作 loginproc.php " < tr > < td > 用户名< > td < /td > < ; td > < 输入 类型 =" 名称 =" 大小 =" < > < /tr > < tr > < td > 密码< > td < /td > < ; td > < 输入 类型 =" 名称 =" 大小 =" < > < /tr > < tr > < td > < > td > & nbsp; < /td > < td > < 输入 类型 =" 提交" 登录" < > /tr > < 输入 =" 隐藏" =" id" < /form > < /table > < /body > < /html >
_REQUEST['from']); } ?> <html> <head> <title>Kanu Bhawan - Member Login</title> </head> <body> <h3>User Login</h3> <table border="0"> <form method="GET" action="loginproc.php"> <tr><td>Username</td><td>:</td><td><input type="text" name="email" size="20"></td></tr> <tr><td>Password</td><td>:</td><td><input type="password" name="password" size="20"></td></tr> <tr><td>&nbsp;</td><td>&nbsp;</td><td><input type="submit" value="Login"></td></tr> <input type="hidden" name="id"> </form> </table> </body> </html>



?>


loginproc.php



?>


loginproc.php

<?php

session_start();
require "config.php"; 


登录 = mysql_query(" .mysql_real_escape_string(
login = mysql_query("SELECT * FROM members WHERE (email = '" . mysql_real_escape_string(


这篇关于php代码重定向到请求登录的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆