php头不是在线工作,而是在我的本地主机上工作……为什么?
这在我的本地主机上运行得非常好,但当我在线托管时,它不会登录,并且会成功无误地回显登录。请问这是什么原因php头不是在线工作,而是在我的本地主机上工作……为什么?,php,Php,这在我的本地主机上运行得非常好,但当我在线托管时,它不会登录,并且会成功无误地回显登录。请问这是什么原因 <?php session_start(); $_SESSION['user_logged']=$user; $_SESSION['user_password']=$password; $user = $_POST["username"];
<?php
session_start();
$_SESSION['user_logged']=$user;
$_SESSION['user_password']=$password;
$user = $_POST["username"];
$password = $_POST["password"];
include("include/connect.php");
$msg = array();
if(isset($_POST['submit'])){
foreach($_REQUEST as $key=>$val){
$$key=$val;
}
if(count($msg)==0){
$sql="SELECT username, password FROM admin WHERE username='$username' && password='$password'";
$res=mysql_query($sql) OR die(mysql_error());
if(mysql_fetch_array($res)>0){
$_SESSION['user_logged']= $user;
$_SESSION['user_password']=$password;
header("location:dashboard.php");
echo "You looged in Successfully";
} else{
$msg[]='Incorrect username/password';
}
}
}
?>
下面是dashboard.php,它应该重定向到该dashboard.php
<?php
include('include/connect.php');
include('include/function.php');
if(isset($_REQUEST['mode']) )
{
$mode=$_REQUEST['mode'];
if($mode == 1)
{
$id=$_REQUEST['id'];
$sql="DELETE FROM enquiry WHERE id='$id'";
$result=mysql_query($sql);
}
}
$msg=array();
if(isset($_POST['submit'])){
$title=$_POST['news'];
$news_item=$_POST['news'];
if(empty($news_item)){
$msg[]='You must enter news in the column!';
}
if(empty($title)){
$msg[]='News Title must not be empty!';
}
else {
$sql = "SELECT * FROM news_file WHERE title='$title' ";
$res = mysql_query($sql) or die(mysql_error());
$result = mysql_fetch_array($res);
if($result > 0){
$msg[] = 'News with the same title has been added already';
} else {
$sql = "INSERT INTO news_file (title,news,date) VALUES ('$title','$news_item',Now())";
$result = mysql_query($sql);
$msg[]='News was successfully added';
}
}
}
?>
试试这个
<?php
session_start();
/*
These should be the other way round, as you are setting
the session variables with variables which have not been
initialised yet
*/
$user = $_POST["username"];
$password = $_POST["password"];
$_SESSION['user_logged']=$user;
$_SESSION['user_password']=$password;
include("include/connect.php");
$msg = array();
if(isset($_POST['submit'])){
foreach($_REQUEST as $key=>$val){
$key=$val; // Removed Erroneous double $
}
if(count($msg)==0){
$sql="SELECT
username,
password
FROM
admin
WHERE
username='$username'
AND
password='$password'";
// MySql does not accept && as a comparison operator.
$res=mysql_query($sql);
if(!$res)
{
var_dump(mysql_error());
exit;
}
else
{
if(mysql_fetch_array($res)>0)
{
$_SESSION['post'] = $_POST;
while(mysql_fetch_array($res)>0)
{
$_SESSION['user_logged']= $user;
$_SESSION['user_password']=$password;
header("location:dashboard.php");
echo "You logged in Successfully";
}
}
else
{
msg[]='Incorrect username/password';
}
}
?>
查看您为dashboard.php提供的代码,您希望重定向到的页面会有$\u POST数据。如果您已重定向到该页面,则不会有$\u POST数据可供您从服务器检索
我已经修改了上面的脚本,在会话中存储$_POST数据,因此使用它,您应该能够通过调用$_session['POST']['news']调用您的新闻项目,或者如果这太冗长,只需在dashboard.php脚本中重新分配POST数据,就像这样
$post=$\会话['post']
然后您可以使用$post['news']调用它。重定向后为什么会有echo语句?你觉得这样对吗?我只想用它来检查是否真的发生了什么,因为页面只是重新加载并停留在登录表单上。感谢与本地主机相比,您在Live Server上使用的PHP版本是什么?mysql_connect函数已经被弃用,应该用PDO或类似的函数替换。但是我在代码的其他部分使用了相同的mysql_connect,它可以工作。这也很有效,只是标题没有很好地重定向。我对此感到厌倦,它只加载一个空页面,而不进入仪表板。仪表板上的会话变量对您可用吗?如果不了解仪表板的功能,就很难解决问题的原因。我已将dashboard.php添加到脚本中,其中的标题应该重定向到该脚本。请任何对此有任何帮助的人,如果有人能够解决,将不胜感激。谢谢,我现在已经为你修改了我的答案。请让我知道这是否有帮助。