downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

session_save_path> <session_regenerate_id
Last updated: Fri, 27 Nov 2009

view this page in

session_register

(PHP 4, PHP 5)

session_registerGeçerli oturuma bir veya daha fazla küresel değişkeni kaydeder

Açıklama

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

session_register() işlevi değişken sayıda değiştirge kabul eder. Tek bir değişkenin ismini içeren bir dizge olabileceği gibi, değişken isimlerini veya diğer dizileri içeren bir dizi olabilir. İşlev, belirtilen her isim için aynı isimdeki bir küresel değişkeni oturum değişkeni haline getirir.

Bir oturum değişkenini $_SESSION veya $HTTP_SESSION_VARS (PHP < 4.1.0) dizisinin bir üyesi olarak da oluşturabilirsiniz.

<?php
//session_register() kullanımı artık önerilmiyor
$barney "Devasa pembe bir dinazor.";
session_register("barney");

// PHP 4.1.0'dan itibaren, $_SESSION tercih ediliyor
$_SESSION["zim"] = "Başka bir gezegenden bir istilacı.";

// Eski yol, $HTTP_SESSION_VARS kullanmaktı
$HTTP_SESSION_VARS["spongebob"] = "O bir kare pantolon giyiyor.";
?>

Bu işlevden önce bir session_start() çağrısı yapılmazsa örtük olarak değiştirgesiz bir session_start() çağrısı çağrısı yapılır. $_SESSION kullanacaksanız bu davranışın size bir faydası olmaz ve önce bir session_start() çağrısı yapmanız gerekir.

Uyarı

Bu işlevin kullanımı PHP 5.3.0'dan beri ÖNERİLMEMEKTEDİR ve PHP 6.0.0'da tamamen KALDIRILACAKTIR. Bu işleve kesinlikle güvenmemelisiniz.

Değiştirgeler

isim

Tek bir değişkenin ismini içeren bir dizge veya değişken isimlerinden ve diğer dizilerden oluşan bir dizi.

...

Dönen Değerler

Başarı durumunda TRUE, başarısızlık durumunda FALSE döner.

Notlar

Dikkat

Betiğinizin register_globals yönergesinin değerine aldırmaksızın çalışmasını isterseniz, bu işlev yerine $_SESSION dizisini kullanmalısınız; $_SESSION girdileri özdevinimli olarak oturum değişkenleri haline gelirler. Betiğiniz session_register() işlevini kullanacaksa, register_globals PHP yönergesinin değerinin On olmadığı yerlerde çalışmayacaktır.

Bilginize: register_globals için önemli bilgi
PHP 4.2.0'dan itibaren, register_globals yönergesinin öntanımlı değeri off olup PHP 6.0.0'dan itibaren tamamen kaldırılmıştır. PHP topluluğu, geliştiricilere, bu yönergeyi kullanmaktan vazgeçmelerini ve yerine süper küreselleri tercih etmelerini önermektedir.

Dikkat

Bu işlev bir küresel değişkeni kayıtlı hale getirir. İşlevi bir oturum değişkenini kayıtlı duruma getirmek için kullanacaksanız değişkeni önce global anahtar sözcüğüyle veya $GLOBALS[] dizisinde belirterek bir küresel değişken haline getirmelisinz. Daha da iyisi özel oturum dizilerini kullanmaktır.

Dikkat

$_SESSION (veya $HTTP_SESSION_VARS) dizisini kullanıyorsanız, session_register(), session_is_registered() ve session_unregister() işlevlerini kullanmayın.

Bilginize: resource türünden değişkenleri bir oturumun kayıtlı değişkeni yapmak mümkün değildir. Örneğin, bir veritabanını bağlantısı oluşturup bunun bağlantı kimliğini bir oturum değişkeninde saklayamazsınız. Çünkü oturum tekrar oluşturulduğunda bu bağlantının geçerli kalacağı beklenemez. Bir özkaynak döndüren PHP işlevleri, işlev tanımında resource türünde bir değer döndüren işlevler olup bunların bir listesi eklerdeki Özkaynak Türlerinin Listesi bölümünde bulunabilir.
Eğer $_SESSION (veya PHP 4.0.6 ve öncesinde $HTTP_SESSION_VARS) kullanılıyorsa, değerler $_SESSION dizisine şöyle atanır: $_SESSION['var'] = 'ABC';

Ayrıca Bakınız



session_save_path> <session_regenerate_id
Last updated: Fri, 27 Nov 2009
 
add a note add a note User Contributed Notes
session_register
Scarab
13-Nov-2009 09:14
If you want to store an  object into the session, you have to check up that object can be serialized at all.
For example, if your object contains aggregated PDO object (which can't be serialized), you will get an error and no data would be stored.
rob at akrabat dot com
14-Aug-2009 09:18
if you remove session_register() calls and replace with $_SESSION assignments, make sure that it wasn't being used in place of session_start(). If it was, you'll need to add a call to session_start() too, before you assign to $_SESSION.
david dot demri at gmail dot com
26-May-2009 02:15
If you have an old code with a lot of call to the function session_register(), and you would like to make it compatible with PHP5 or PHP6, instead of rewriting all your code by replacing this function by $_SESSION['var']="val"; you could use the function set_session_vars(), that is used exactly the same way than session_register() (but there is no implicit call to session_start() ).

<?php
function set_session_vars() {
   
$nb_args=func_num_args();
   
$arg_list=func_get_args();
    for(
$i=0;$i<$nb_args;$i++) {
        global $
$arg_list[$i];
       
$_SESSION[$arg_list[$i]] = $$arg_list[$i];
    }
}
?>
kavih7 at yahoo dot com
19-May-2009 11:15
For those of you who use this function (session_register that is), even though the manual does specify that this function implicitly calls session_start(), I just wanted to reiterate that fact. It is also important to know that if you ever switch from session_register to using $_SESSION, make sure to call session_start before adding items to the $_SESSION variable, because unlike session_register, no implicit call to session_start is done.

Another reason I explain this is because I ran into a problem in which you can add items to the $_SESSION variable all you want, but if session_start is not called before adding them, they will not actually be saved to the session. Using the same code, though, and replacing the $_SESSION assignments with session_register without calling session_start WILL save that info to the session.

It would be nice to have PHP check for writes to the $_SESSION variable and complain with a warning if session_start hasn't been called.
guideng at unlv dot nevada dot edu
01-Jun-2006 08: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 09: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
mikej
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.
baldanders
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.

session_save_path> <session_regenerate_id
Last updated: Fri, 27 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites