doufeng2877 2016-04-15 13:34
浏览 37

PHP Session 5.4到5.6

I have created a website lately with a group of students, but were having some troubles. We created the website in php 5.4 on a localhost and it worked perfectly. But now we wanted to get the site online and the webhosting is using a different version of php(5.6). So now the session does not start. It redirects us to the homepage, but we are not logged in. We were thinking that it was because of the version of php, since it did work at first.

<?php
include_once 'connect.php';
session_start();// Starting Session
// Storing Session
$user_check=$_SESSION['gebruiker'];
// SQL Query To Fetch Complete Information Of User
$ses_sql="select email_adres from gebruiker where email_adres='".$user_check".'";
$row = mysqli_fetch_assoc($ses_sql);
$login_session =$row['username'];
if(!isset($login_session)){
    header('Location: login.php'); // Redirecting To Home Page
}
else{
    header('Location: acountgegevens.php');
}
?>


<?php
include_once 'connect.php';
function logincheck(){
    if(isset($_POST['submit'])){

        $error = 0;
        // declare variables
        $email = null;
        $password = null;

        // check if email address has been set
        if (isset($_POST['email_adres']) && 
           !empty($_POST['email_adres'])) {
            $email = addslashes($_POST['email_adres']);
        }

        // check if password has been set
        if (isset($_POST['password']) && !empty($_POST['password'])) {
            $password = md5($_POST['password']);
        }
        if ($email == null || $password == null) {
            $error = 1;
        }

        // query database for user credentials
        $db = new PDO('**');
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        $statement = $db->prepare("SELECT * 
                                   FROM gebruiker 
                                   WHERE email_adres = :email 
                                     AND wachtwoord = :password 
                                   LIMIT 1");
        $statement->execute(array(':email' => $email, ':password' => $password));

        $result = $statement->fetch(PDO::FETCH_OBJ);

        if (!$result) {
            $error = 1;
        } else {
            session_start();
            $_SESSION['gebruiker'] = $email;

            var_dump($_SESSION);

?>
<script>location.href='index.php'</script>
<?php

        }
        return $error;
    }
}
?>

These two files are included, but we cant figure it out.

Could someone help?

  • 写回答

1条回答 默认 最新

  • dpj0015 2016-04-15 13:45
    关注

    I would hazzard a guess that your connect.php has not been changed to match the hosting companies host/user/password and therefore is outputting an error message.

    This of course means that session_start() , which was placed after the connect.php and therefore after your script has attempted to send something to the browser, will not work.

    You are only seeing the result of the failed session_start() but I would check the connect.php is configured correctly for its new hosting location

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题