a var and two pages<

liunx

Guest
How can I set a var in a page that was called by another and to make it avalaible by the page that called it.

Hope it's clear enough.use sessions.. then put the var in the _SESSION super array..

i.e
$_SESSION['varname1'] = somevalue;
$_SESSION['varname2'] = somevalue2;

then to access them from the other page, simply just

somevalue = $_SESSION['varname1'];
somevalue2 = $_SESSION['varname2'];

... note you'll need to call session_start(); at the begining of each php file

hope that helps.

-fldo I have to call sessions start to call a var or it's only necessary define the var?to access any of the session data the session has to be started right? right.. so put yer sessions_start() at the begining of everypage that needs data preserved across.

-flor make it global

$_GLOBALS['varname1'] = somevalue;

then you don't have to use sessions.doesn't the global superarray only put the variable into the global scope of the current script being excuted?

-flThat's also what I tought.

But normally, scout is a good reference.if you make it $_GLOBALS[''] it will be seen by ALL scripts. that is in php 4.1 and aboveso any "user" could access that $_GLOBALS[] array? regardless of their session data?

-flhas nothing to do with the user, it has everything to do with the script. $_GLOBALS is for every script.


An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $GLOBALS; to access it within functions or methods.

<!-- m --><a class="postlink" href="http://us2.php.net/manual/en/reserved.variables.php#reserved.variables.globals">http://us2.php.net/manual/en/reserved.v ... es.globals</a><!-- m -->"global scope of the SCRIPT"

not global scope of the whole php application (server side so when u open a NEW script it wont have those globals)

it's just a diff way of going

var $yousuck = 1;

global $yousuck;

$_GLOBALS['yousuck'] = 1;

yes? yes. I need global access throughout many different scripts that arne't all loaded in 1 request. (therefore the scope changes everytime you load an entirely new script)

-flIn my case it worked fine between two page so im happy to not have to use those stupid sessions that caused me a lot of trouble for nothing.Originally posted by forlamp
"global scope of the SCRIPT"

not global scope of the whole php application (server side so when u open a NEW script it wont have those globals)


really? I can load a global in my config and it will be there for all of the application, any script that uses that config. once you set it it goes into memory so all scripts can use it per session or per user. so yes, all of the php application for that user.
 
Back
Top