Lucashasnoname, also works fine without the session_register line, so I suspect it does nothing.
session_register
(PHP 4, PHP 5)
session_register — Register one or more global variables with the current session
Description
session_register() accepts a variable number of arguments, any of which can be either a string holding the name of a variable or an array consisting of variable names or other arrays. For each name, session_register() registers the global variable with that name in the current session.
You can also create a session variable by simply setting the appropriate member of the $_SESSION or $HTTP_SESSION_VARS (PHP < 4.1.0) array.
<?php
// Use of session_register() is deprecated
$barney = "A big purple dinosaur.";
session_register("barney");
// Use of $_SESSION is preferred, as of PHP 4.1.0
$_SESSION["zim"] = "An invader from another planet.";
// The old way was to use $HTTP_SESSION_VARS
$HTTP_SESSION_VARS["spongebob"] = "He's got square pants.";
?>
If session_start() was not called before this function is called, an implicit call to session_start() with no parameters will be made. $_SESSION does not mimic this behavior and requires session_start() before use.
Parameters
- name
-
A string holding the name of a variable or an array consisting of variable names or other arrays.
- ...
-
Return Values
Returns TRUE on success or FALSE on failure.
Notes
If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled.
Note: register_globals: important noteAs of PHP 4.2.0, the default value for the PHP directive register_globals is off, and it was completely removed as of PHP 6.0.0. The PHP community discourages developers from relying on this directive, and encouragees the use of other means, such as the superglobals.
This registers a global variable. If you want to register a session variable from within a function, you need to make sure to make it global using the global keyword or the $GLOBALS[] array, or use the special session arrays as noted below.
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().
Note: It is currently impossible to register resource variables in a session. For example, you cannot create a connection to a database and store the connection id as a session variable and expect the connection to still be valid the next time the session is restored. PHP functions that return a resource are identified by having a return type of resource in their function definition. A list of functions that return resources are available in the resource types appendix.
If $_SESSION (or $HTTP_SESSION_VARS for PHP 4.0.6 or less) is used, assign values to $_SESSION. For example: $_SESSION['var'] = 'ABC';
session_register
04-May-2008 02:16
09-Apr-2008 06:06
This worked fine; it seems that session_register() works with register_globals off. I will try this again on a server on which I can edit the php.ini file.
<?php
session_start();
error_reporting(E_ALL);
ini_set('register_globals', 0);
echo "HI <br />";
session_register("User");
$_SESSION["User"] = "Hello";
echo $_SESSION["User"];
//Output: Hello
?>
01-Jun-2006 09: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.
11-Apr-2006 10: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
20-Mar-2006 06: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.
27-Feb-2006 05: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...
21-Nov-2004 09: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.
12-Nov-2004 07: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.
