简体   繁体   中英

Strange problem with session - PHP

I have strange problem, that don't work on server:

session_start();

$quser = new Quser($_SESSION['$fb_user_id'], $pdo);

but this, seems to be OK:

session_start();

$x = $_SESSION['fb_user_id'];
$quser = new Quser($x, $pdo);

Of course, on localhost first option work fine. What is going on? Is there any restriction about that?

由于$_SESSION['$fb_user_id']$_SESSION['fb_user_id']差异,请注意变量的拼写。

Because you are using single quotes on your variable array dimension, it's looking for a dimension called '$fb_user_id' rather than your variable.

Have a go with

$quser = new Quser($_SESSION[$fb_user_id], $pdo);

You have to enable full error reporting. For instance, you can preppend this to your code:

<?php
ini_set('display_errors', TRUE);
error_reporting(E_ALL | E_STRICT);
?>

As soon as you run your code with these settings, PHP will warn you about the undefined variable your code features ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM