pHp会话错误?

I've been trying to figure out why my code isn't working on my PC at home using XAMPP 1.8.2 while at work I've been using 1.7.2. I get the following error

Fatal error: Call to undefined function session_is_registered() in C:\xampp\htdocs\loginscript\session1.php on line 5

What I have on line 5.

if(!session_is_registered(username)){
header("location:index.php");
}

I would imagine it having to do something with pHp version? Cheers

A user has requested to see my code..

<?php 
session_start()
//--- Authenticate code begins here ---
//checks if the login session is true
if(!session_is_registered(username));{
header("location:index.php");
}
$username = $_SESSION['username'];

// --- Authenticate code ends here ---


 include ('header.php'); ?> 

As pointed out by Halloei in the comments, you said at home you are using Xampp 1.8.2 and at work 1.7.2 - if you have a look at the Xampp version history 1.8.2 comes with PHP 5.4 whereas 1.7.2 comes with PHP 5.3 and the session_is_registered function was DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0. This is the cause of the error you are seeing.

To correct this you can update your code to something like the following:

<?php 
session_start();

//--- Authenticate code begins here ---

//checks if the login session is true
if (!isset($_SESSION['username']))
{
    header("location:index.php");
}
$username = $_SESSION['username'];

// --- Authenticate code ends here ---

include ('header.php'); 
?> 

This uses isset to check if the value username is set in the session array.

First look at the documentation

you should add session_start() at the beginning of page

and to set a value to session your code should be something like this

$_SESSION["username"] = "John";

and to get value:

$username=$_SESSION["name"];

YOUR PROBLEML is semicolon ";":

session_start()  //error
session_start(); //true

You could just make your own session_is_registered function if this is being used widely in your site.

function session_is_registered($username)
{
     $registered = false;
     if(//Expression here to check if $username is in the $_SESSION array)
     {
          $registered = true;
     }
     return $registered;
}

Then make sure to include this function where the old registered function is being used. Be warned though if you move this function to an older version of PHP it might throw an error since this function is still available in older versions.

your code is this

session_start()
//--- Authenticate code begins here ---
//checks if the login session is true
if(!session_is_registered(username));{
header("location:index.php");
}

and you need to rectify the colon like this colon after session_start and no colon after if condition

session_start();
//--- Authenticate code begins here ---
//checks if the login session is true
if(!session_is_registered(username)) {
header("location:index.php");
}