suche nach in der

session_save_path> <session_register_shutdown
Last updated: Fri, 18 May 2012

view this page in

session_register

(PHP 4, PHP 5 < 5.4.0)

session_registerRegistriert eine oder mehrere globale Variablen in der aktuellen Session

Beschreibung

bool session_register ( mixed $name [, mixed $... ] )

session_register() akzeptiert eine variable Anzahl von Argumenten, die jeweils entweder eine Zeichenkette sein können, die den Namen einer Variablen trägt, oder ein Array, das aus solchen Variablennamen oder anderen Arrays besteht. Für jeden Namen registriert session_register() die globale Variable mit diesem Namen in der aktuellen Session.

Sie können eine Session-Variable auch erzeugen, indem Sie das entsprechende Element des $_SESSION- oder (PHP <= 4.1.0) $HTTP_SESSION_VARS-Arrays setzen.

<?php
// Sie sollten session_register() nicht verwenden
$barney "A big purple dinosaur.";
session_register("barney");

// Ab PHP 4.1.0 ist die Verwendung von $_SESSION vorzuziehen
$_SESSION["zim"] = "An invader from another planet.";

// Die alte Methode war, $HTTP_SESSION_VARS zu verwenden
$HTTP_SESSION_VARS["spongebob"] = "He's got square pants.";
?>

Wenn session_start() nicht vor dieser Funktion aufgerufen wurde, erfolgt ein impliziter Aufruf von session_start() ohne Parameter. $_SESSION ahmt dieses Verhalten nicht nach und benötigt den Aufruf von session_start() bevor es verwendet wird.

Warnung

Diese Funktion ist seit PHP 5.3.0 DEPRECATED (veraltet). Sich auf diese Funktion zu verlassen ist in keiner Weise empfehlenswert.

Parameter-Liste

name

Eine Zeichenkette, die den Namen einer Variablen trägt, oder ein Array, das aus solchen Variablennamen oder anderen Arrays besteht.

...

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Anmerkungen

Achtung

Wenn Sie wollen, dass ihr Script unabhängig von der Einstellung von register_globals funktioniert, müssen Sie stattdessen das Array $_SESSION verwenden, weil $_SESSION-Einträge automatisch registriert werden. Wenn Sie in Ihrem Script session_register() verwenden, funktioniert es nicht in Umgebungen, in denen die PHP-Anweisung register_globals deaktiviert ist.

Hinweis: register_globals: Wichtiger Hinweis

Seit PHP 4.2.0 ist die Standardeinstellung für die Konfigurationsoption register_globals off. Die PHP-Community ermutigt alle, sich nicht auf diese Option zu verlassen und Alternativen wie superglobals zu verwenden.

Achtung

Diese Funktion registriert eine globale Variable. Wenn Sie eine Session-Variable innerhalb einer Funktion registrieren wollen, müssen Sie sicherstellen, dass Sie sie unter Verwendung des global-Schlüsselworts oder des $GLOBALS[]-Arrays global machen oder die nachstehend vermerkten speziellen Session-Arrays verwenden.

Achtung

Wenn Sie $_SESSION (oder $HTTP_SESSION_VARS) verwenden, sollten Sie nicht session_register(), session_is_registered() und session_unregister() verwenden.

Hinweis:

Gegenwärtig ist es nicht möglich, Ressourcen-Variablen in einer Session zu registrieren. Zum Beispiel können Sie nicht erwarten, dass die als Session-Variable gespeicherte Verbindungs-Kennung der zu einer Datenbank aufgebauten Verbindung bei der nächsten Wiederherstellung der Session noch gültig ist. PHP-Funktionen, die eine Ressource zurückgeben, können daran erkannt werden, dass sie einen Rückgabewert resource in ihrer Funktionsdefinition haben. Eine Liste der Funktionen, die Ressourcen zurückgeben befindet sich im Anhang Liste von PHP Ressourcen.

Bei Verwendung von $_SESSION (oder $HTTP_SESSION_VARS bei PHP 4.0.6 oder niedriger) weisen Sie $_SESSION einen Wert zu, also $_SESSION['var'] = 'ABC';

Siehe auch



add a note add a note User Contributed Notes
session_register
guideng at unlv dot nevada dot edu
01-Jun-2006 10:10
Make sure you put session_start() at the beggining of your script.

My sessions kept unsetting and I finally figured out why.

On my script, session_start() has to be said and uses cookies to set the session.

But I was outputting html prior to calling session_start(), which prevented it from succeeding becouse it uses the header function to place the cookies.

Once html has been outputed, session_start() can't use the header function to set cookies, hence session_start() fails and no session can be started.
martijn at brothersinart dot net
11-Apr-2006 11:04
Please note that if you use a "|" sign in a variable name your entire session will be cleared, so the example below will clear out all the contents of your session.

<?php
session_start
();
$_SESSION["foo|bar"] = "foo";
?>

It took me quite some time finding out why my session data kept disappearing. According to this bugreport this behaviour is intended.
http://bugs.php.net/bug.php?id=33786
hairguy
20-Mar-2006 07:53
I wasted about two days trying to figure out why some of my session data was being lost.  The problem occurred intermittently and I was nearly convinced it had to be a PHP bug.

Since my session data was being stored in mysql, I finally thought to check the definition of the session table.  The session data was stored in a column of type 'text' (which can only hold 65,535 bytes of data).

Changing the session column to type 'mediumtext' (which can hold 16,777,215 bytes) solved the problem.

Perhaps this tip will help someone else who may be experiencing similar session loss problems.
creepers at businessrealmz dot com
27-Feb-2006 06:49
sometimes you know everything was right but you still get an error Cannot send session cache limiter - headers already sent (output started at blah blah...; you may spend an hour until you discover that your php tag  was at the second line of your script. this is true specially when you are under pressure..i hope this will help...
mikej
21-Nov-2004 10:40
I've noticed that if you try to assign a value to a session variable with a numeric name, the variable will not exist in future sessions.
For example, if you do something like:
session_start();
$_SESSION['14'] = "blah";
print_r($_SESSION);

It'll display:
Array ( [14] => "blah" )

But if on another page (with same session) you try
session_start();
print_r($_SESSION);

$_SESSION[14] will no longer exist.

Maybe everyone else already knows this, but I didn't realize it until messing around with a broken script for quite a while.
baldanders
12-Nov-2004 08:05
If you are using sessions and use session_register()  to register objects, these objects are serialized automatically at the end of each PHP page, and are unserialized automatically on each of the following pages. This basically means that these objects can show up on any of your pages once they become part of your session.
dominik-ruess at gmx dot de
13-Dec-2003 11:58
Do not even think of using "global" together with "$_SESSION":

<?php

// Will only work on some servers (or some PHP-Versions - I don't know):
function test()
{
      global
$_SESSION;

     
$_SESSION["test"]=1;
}

// correct way:
function test()
{
     
$_SESSION["test"]=1;
}
?>

took me hours to recognize :/
gianni_t76 at yahoo dot it
05-Aug-2003 09:42
You don't need to serialize an object before adding it to a session var

example:

include("class.exmaple.php");
$obj = new exampel ();
$_SESSION['obj']=$obj;

and to resume the object:

include("class.example.php");
$obj = $_SESSION['obj']);
ice at thesurf dot no-ip dot com
02-Apr-2003 02:09
If you use objects it is alsways a good idear to make a var or array that hold your object-handler

exampel:
include("class.exmaple.php");
$obj = new exampel ();

$se_obj = serialize($obj);

$_SESSION['se_obj']=$se_obj;

when you then got on the next page and so a start_session()
and you don't habe includet the classdescription, your object will still not break.
Just do a
include("class.example.php");
$obj = unserialze($_SESSION['se_obj']);

and all is fine.
This is a preaty good trick if you do some includings in the next page an use the object in a file you include :)

session_save_path> <session_register_shutdown
Last updated: Fri, 18 May 2012