我希望有人可以帮助我处理我的登录脚本。当我从 wamp localhost 运行它时,该代码运行良好,但是当它在服务器上运行时,它在我尝试登录时返回一个空白页面,谁能告诉我为什么?代码如下。
<?php
session_start();
//login script
if(isset($_REQUEST['ch']) && $_REQUEST['ch'] == 'login'){
//give your login credentials here
if($_REQUEST['uname'] == 'zipbuzz' && $_REQUEST['pass'] == 'sewilt')
$_SESSION['login_user'] = 1;
else
$_SESSION['login_msg'] = 1;
}
//get the page name where to redirect
if(isset($_REQUEST['pagename']))
$pagename = $_REQUEST['pagename'];
//logout script
if(isset($_REQUEST['ch']) && $_REQUEST['ch'] == 'logout'){
unset($_SESSION['login_user']);
header('Location:login.php');
}
if(isset($_SESSION['login_user'])){
if(isset($_REQUEST['pagename']))
header('Location:'.$pagename.'.php');
else
header('Location:admin.php');
}else{
?>
<?php
//display the error msg if the login credentials are wrong!
if(isset($_SESSION['login_msg'])){
echo 'Wrong username and password !';
unset($_SESSION['login_msg']);
}
?>
然后我将以下内容添加到需要登录才能访问的页面中。
<?php session_start();
//check logged in or not!
if(!isset($_SESSION['login_user'])){
header('Location:login.php?pagename='.basename($_SERVER['PHP_SELF'], ".php"));
}
?>