PHP会话变量不起作用

时间:2016-03-04 10:56:03

标签: php .htaccess session variables

每次我使用登录脚本开始新会话时,会话变量都不起作用。在登录页面上,如果我设置了这样的会话变量:$_SESSION['user_id'] = $row_sql['id'];它可以工作,但是传递给其他pagea不会。

我还注意到,地址链接会更改域名,其中包含" www.domain.com"成为域名网站,但现在我已经将我的.htaccess文件强制重定向到www.domain.com。但是,检查我的托管服务提供商,我意识到域名显示为" domain.com"。因此,以这种或那种方式,会话变量不会传递到站点上的其他页面。

我的.htaccess文件:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

我的登录脚本:

<?php

include ("../../connect/connect.php");

$email = $_POST['email']; $pass= base64_encode($_POST['pass']);

$sql = mysqli_query($conn,"select * from users where email = '$email' and pass= '$pass' and status = 1"); 
$total_sql = mysqli_num_rows($sql); 
$row_sql = mysqli_fetch_assoc($sql);

if($total_sql==0) { 
    echo '<script type="text/javascript">alert("incorrect email or password."); window.location.href = "index.php"</script>';       
    exit;   
} 
@session_start(); 
$_SESSION['user_id'] = $row_sql['id']; 
$_SESSION['user_name'] = $row_sql['name']; 
$_SESSION['user_account'] = $row_sql['account']; 
$_SESSION['user_email'] = $row_sql['email'];

if(($row_sql['account']==1) || ($row_sql['account']==2)){
        echo '<script type="text/javascript">window.location.href = "../admin/index.php"</script>';
        exit; }elseif($row_sql['account']==3){  
        echo '<script type="text/javascript">window.location.href = "../1/index.php"</script>';
        exit;
}

?>

所有其他页面都是这样开始的,并在第8行和第34行的/home/black521/public_html/d/1/index.php中给出错误&#34;注意:未定义的索引:user_id;

<?php 
@session_start();
//-->
error_reporting(-1);
//-->
include ("../../connect/connect.php");
//--> 
$userid = $_SESSION['user_id'];

0 个答案:

没有答案