Jump to content

globals


jagguy

Recommended Posts

Hi,

 

I want to have a variable set in 1 script that can be used in all other scripts eg a global variable.

 

I need a global variable to tell me if someone has logged in  from every page and the url the site is located on for header redirects.

 

I don't understand $GLOBAL and i tried

  $my_var="http://dog";

global $my_var;

 

and echo $my_var in another script as it fails.

 

 

Link to comment
https://forums.phpfreaks.com/topic/59610-globals/
Share on other sites

the global command is used to grab variables that are outside, for example, a function. to make it global you could use the $_SESSION global and then have session_start() at the top of each page.

 

session_start();

$_SESSION['my_var'] = "http://dog";

echo $_SESSION['my_var'];

 

read up about sessions...

Link to comment
https://forums.phpfreaks.com/topic/59610-globals/#findComment-296452
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.