Remplacer session_register (php5.3)

Recif

WRInaute impliqué
Salut,

J'ai encore besoin de vos lumières :wink:

Je suis en train de remplacer tout le code "DEPRECATED" de mes scripts... Là je bute sur le remplacement de session_register() :

Code original (issu de oscommerce) :

Code:
 function tep_session_register($variable) {
    global $session_started;

    if ($session_started == true) {
      return session_register($variable);
    } else {
      return false;
    }
  }

Comment remplacer par $_SESSION ...?
Merci
 

spout

WRInaute accro
PHP:
<span class="syntaxdefault"><br /></span><span class="syntaxcomment">// L'utilisation de $_SESSION est encouragée depuis PHP 4.1.0<br /></span><span class="syntaxdefault">$_SESSION</span><span class="syntaxkeyword">[</span><span class="syntaxstring">"zim"</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">"Un envahisseur d'une autre planète."</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> </span>
http://php.net/manual/fr/function.session-register.php

Donc un truc du style (pas testé):
PHP:
<span class="syntaxdefault"><br /></span><span class="syntaxkeyword">function&nbsp;</span><span class="syntaxdefault">tep_session_register</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$variable</span><span class="syntaxkeyword">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;</span><span class="syntaxdefault">$session_started</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span class="syntaxdefault">$session_started&nbsp;</span><span class="syntaxkeyword">==&nbsp;</span><span class="syntaxdefault">true</span><span class="syntaxkeyword">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">//http://www.php.net/manual/fr/function.session-register.php#100206<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxkeyword">if&nbsp;(!isset(</span><span class="syntaxdefault">$_SESSION</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">$variable</span><span class="syntaxkeyword">]))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">$_SESSION</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">$variable</span><span class="syntaxkeyword">]&nbsp;=&nbsp;$</span><span class="syntaxdefault">$variable</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">true</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">false</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span class="syntaxdefault">false</span><span class="syntaxkeyword">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span class="syntaxdefault"> </span>
 

Recif

WRInaute impliqué
Ca y est j'ai trouvé enfin :

Code:
function tep_session_register($variable) {
        global $session_started;

        if ($session_started == true) {
          if (PHP_VERSION < 4.3) {
                return session_register($variable);
          } else {
                if (isset($GLOBALS[$variable])) {
                  $_SESSION[$variable] =& $GLOBALS[$variable];
                } else {
                  $_SESSION[$variable] = null;
                }
          }
        }

        return false;
  }

  function tep_session_is_registered($variable) {
        if (PHP_VERSION < 4.3) {
          return session_is_registered($variable);
        } else {
          return isset($_SESSION) && array_key_exists($variable, $_SESSION);
        }
  }

  function tep_session_unregister($variable) {
        if (PHP_VERSION < 4.3) {
          return session_unregister($variable);
        } else {
          unset($_SESSION[$variable]);
        }
  }
 

Discussions similaires

Haut