<HTML ><HEAD ><TITLE >session_register</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Session handling functions" HREF="ref.session.html"><LINK REL="PREVIOUS" TITLE="session_readonly" HREF="function.session-readonly.html"><LINK REL="NEXT" TITLE="session_save_path" HREF="function.session-save-path.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.session-readonly.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.session-save-path.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.session-register" ></A >session_register</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN84574" ></A ><P > (PHP 4 )</P >session_register -- Register one or more global variables with the current session </DIV ><DIV CLASS="refsect1" ><A NAME="AEN84577" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >session_register</B > ( mixed name [, mixed ...])<BR ></BR ><P > <B CLASS="function" >session_register()</B > 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, <B CLASS="function" >session_register()</B > registers the global variable with that name in the current session. </P ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Caution</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > If you want your script to work regardless of register_globals, you need to use the $_SESSION array. All $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where register_globals is disabled. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Caution</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > This registers a <SPAN CLASS="emphasis" ><I CLASS="emphasis" >global</I ></SPAN > variable. If you want to register a session variable from within a function, you need to make sure to make it global using the <A HREF="language.variables.scope.html" ><B CLASS="command" >global</B ></A > keyword or the <TT CLASS="varname" >$GLOBALS[]</TT > array, or use the special session arrays as noted below. </P ></TD ></TR ></TABLE ></DIV ><DIV CLASS="caution" ><P ></P ><TABLE CLASS="caution" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Caution</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > If you are using <TT CLASS="varname" >$_SESSION</TT > (or <TT CLASS="varname" >$HTTP_SESSION_VARS</TT >), do not use <B CLASS="function" >session_register()</B >, <A HREF="function.session-is-registered.html" ><B CLASS="function" >session_is_registered()</B ></A > and <A HREF="function.session-unregister.html" ><B CLASS="function" >session_unregister()</B ></A >. </P ></TD ></TR ></TABLE ></DIV ><P > This function returns <TT CLASS="constant" ><B >TRUE</B ></TT > when all of the variables are successfully registered with the session. </P ><P > If <A HREF="function.session-start.html" ><B CLASS="function" >session_start()</B ></A > was not called before this function is called, an implicit call to <A HREF="function.session-start.html" ><B CLASS="function" >session_start()</B ></A > with no parameters will be made. <TT CLASS="varname" >$_SESSION</TT > does not mimick this behavior and requires <A HREF="function.session-start.html" ><B CLASS="function" >session_start()</B ></A > before use. </P ><P > You can also create a session variable by simply setting the appropriate member of the <TT CLASS="varname" >$_SESSION</TT > or <TT CLASS="varname" >$HTTP_SESSION_VARS</TT > (PHP < 4.1.0) array. <DIV CLASS="informalexample" ><A NAME="AEN84616" ></A ><P ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$barney = "A big purple dinosaur."; session_register("barney"); $_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.";</PRE ></TD ></TR ></TABLE ><P ></P ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > 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 <TT CLASS="literal" >resource</TT > in their function definition. A list of functions that return resources are available in the <A HREF="resource.html" >resource types</A > appendix. </P ><P > If <TT CLASS="varname" >$_SESSION</TT > (or <TT CLASS="varname" >$HTTP_SESSION_VARS</TT > for PHP 4.0.6 or less) is used, assign values to <TT CLASS="varname" >$_SESSION</TT >. For example: $_SESSION['var'] = 'ABC'; </P ></BLOCKQUOTE ></DIV ><P > See also <A HREF="function.session-is-registered.html" ><B CLASS="function" >session_is_registered()</B ></A > and <A HREF="function.session-unregister.html" ><B CLASS="function" >session_unregister()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.session-readonly.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.session-save-path.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >session_readonly</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.session.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >session_save_path</TD ></TR ></TABLE ></DIV ></BODY ></HTML >