dongyinting3179 2018-05-02 04:49
浏览 74
已采纳

网站在localhost中运行良好,但在托管服务器中运行良好

My website works flawlessly in my XAMPP localhost, and I tried to upload it in free hosting server to test it but I encountered these errors and I dont know how to fix them, please help.

the session.php is for pages that only logged in users can see, if tried to go to e.g dashboard.php when not logged in, page will redirect to login.php

Error 1 :

Notice: Undefined index: login_user in /public_html/session.php on line 6 Go back

Error 2 :

Warning: Cannot modify header information - headers already sent by (output started at public_html/session.php:6) in public_html/session.php on line 15

And this is my session.php

<?php

session_start();

include('db.php');
$user_check=$_SESSION['login_user']; //THIS IS LINE 6
$ses_sql=mysqli_query($db,"select  username,mem_id  from  member  where  
username='$user_check'  ");
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$loggedin_session=$row['username'];
$loggedin_id=$row['mem_id'];

if(!isset($loggedin_session)  ||  $loggedin_session==NULL)
{
echo  "Go  back";
header("Location: login.php"); //THIS IS LINE 15
}

?>

And Error 3 :

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /public_html/dashboard.php on line 41

This is my dashboard.php

<?php
include('db.php');
$sql="SELECT  *  FROM  member  where  mem_id=$loggedin_id";
$result=mysqli_query($db,$sql);
?>
<?php
while($rows=mysqli_fetch_array($result)){ //THIS IS LINE 41
?>

If you noticed the open bracket in line 41, there is php code at the bottom of my dashboard page :

<?php
//  close  while  loop
}
?>

<?php
//  close  connection;
mysqli_close($db);
?>

I really dont know if this is necessary or not because Im just getting ideas from other public and open source php codes online.

  • 写回答

3条回答 默认 最新

  • doupi4649 2018-05-02 04:57
    关注
    Notice: Undefined index: login_user in /public_html/session.php on line 6 Go back
    

    It means that in $_SESSION, 'login_user' is not defined. So depending of your logic you might want to do something like

    $user_check = isset($_SESSION['login_user']) ? $_SESSION['login_user'] : '';
    

    Second error should be fixed once the first one is fixed.

    Third error : Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /public_html/dashboard.php on line 41

    It means that your query failed. Maybe because $loggedin_id is not set or for an other reason (check mysqli_error (http://www.php.net/manual/en/mysqli.error.php) You might want to fix it, and for good practice, you should check it before doing anything else. Example :

    if ($result) {
        while($rows=mysqli_fetch_array($result)){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?
  • ¥15 Arduino的wifi连接,如何关闭低功耗模式?
  • ¥15 Android studio 无法定位adb是什么问题?
  • ¥15 C#连接不上服务器,