PHP 登录系统 ~ session.register 和 session.start 错误 [英] PHP Login System ~ session.register and session.start errors

查看:48
本文介绍了PHP 登录系统 ~ session.register 和 session.start 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 php 新手,我想在这里使用登录系统:

I'm newish to php and i'm trying to use a login system here:

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1"     bgcolor="#CCCCCC">
<tr>
<form action="/?module=admin&n=checklogin" method="post" enctype="multipart/form-data"     name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Administrator Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input type="text" name="myusername" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td> <button type="submit" name="Submit">Login</button>
<img src="../images/ajax-loader.gif" width="16" height="16" style="display: none"/>
<script>
$("button").click(function () {
$("img").show("slow");
});
</script>
</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

这是checklogin.php的代码

This is the code for checklogin.php

<?php
error_reporting(E_ALL);
$host="localhost"; // Host name 
$username="david_bpd"; // Mysql username 
$password="documents123456"; // Mysql password 
$db_name="david_bpd"; // Database name 
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die(mysql_error()); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)    
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row


if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
echo "<meta http-equiv='refresh' content='0;url=/?module=admin&n=Login_success'/>";
}
elseif($count==0) {
echo "<meta http-equiv='refresh' content='0;url=/?module=admin&n=Login_Unsuccessful'/>";
}

?>

但是每当我尝试使用正确的凭据时,我都会收到这些错误:

But whenever I try to loin with the correct credentials i get these errors:

Deprecated: Function session_register() is deprecated in /home/david/public_html/bowlplexdoubles/admin/checklogin.php on line 45

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/david/public_html/bowlplexdoubles/index.php:12) in /home/david/public_html/bowlplexdoubles/admin/checklogin.php on line 45

Deprecated: Function session_register() is deprecated in /home/david/public_html/bowlplexdoubles/admin/checklogin.php on line 46

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively in Unknown on line 0

我不知道接下来要做什么

I don't know what to do next

任何帮助将不胜感激,

谢谢

推荐答案

被弃用"的东西意味着有一种新的/更好的做事方式.在这种情况下,您可以使用

Something being "deprecated" means that there is a new/better way to do things. In this case, instead of doing session_register you can just create a variable using

$_SESSION['someKey'] = someValue;

然后在加载管理页面后,您可以执行以下操作

Then upon loading the admin page you can do the following

if (isset($_SESSION['someKey']) {
    if ($_SESSION['somekey'] == someValue) {
        //User should be allowed to be on page
    }
    else
        Header("Location: someotherpage.php");
}
else
    Header("Location: someotherpage.php");

这篇关于PHP 登录系统 ~ session.register 和 session.start 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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