开发者

$_SESSION['userid'] works in one function and not the next

I can't understand why this don't work. First i have a function like this where the user name shows up:

if(isset($_POST['Commit'])){

if(empty($_POST['crime'])){
echo "You didn't select the type of crime you wish to do.";
}else{

   (...lots of code)

$name = $_SESSION['username'];`

Then I have another function where the username shows up blank:

if(isset($_POST['action'])){

    (...)

if(empty($_POST['car'])){
echo "You didn't select a car.";
}else{


if($row['owner'] != $_SESSION['username']){
echo "This isn't your car.";
}else{

There is allot of code that i didn't post, but you guys get the idea. Why does this happen? i thought $_SESSION was global and always available

My main php file look something like this:

require("php functions\page_functions.php"); 
require("php functions\gta_functions.php");

session_start();

class gtapage extends Page
{

        public function display()
    开发者_开发问答    {

        displayGta();
        }
}

where displayGta(); is the function from my first post


Has session_start() been called in the script that's using the second function? $_SESSION is only available on pages in which a session has been opened.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜