PHP Classes

Registering Globals

Recommend this page to a friend!

      Gvar  >  All threads  >  Registering Globals  >  (Un) Subscribe thread alerts  
Subject:Registering Globals
Summary:How do you register variables that are not from a form?
Messages:3
Author:John Sims
Date:2007-01-23 13:49:57
Update:2007-01-24 02:00:13
 

  1. Registering Globals   Reply   Report abuse  
Picture of John Sims John Sims - 2007-01-23 13:49:57
I am very new to PHP. With everyone turning global varibales off in the php.ini for security, I am having trouble understanding how to set and pass variables from one program to another that are not going through a FORM.

Example:

program1.php

$error_log = "9";



program2.php

if ($error_log == "9")
{
print "okay";
}
else
{
print "BAD";
}


That is a crude example but it shows that a variable is set in one program and then used in another. I really do not see how it is set in program1.php and then used in program2.php.

I have read several classes in PHPClasses and on php.org and it really doesn't make sense. Most all deal with when it is coming from a FORM.

Thank you for your help.

John

  2. Re: Registering Globals   Reply   Report abuse  
Picture of João Romão João Romão - 2007-01-23 14:11:14 - In reply to message 1 from John Sims
If you have the two files and want the variables pass from one to another with register_globals off, do not expect some kind of magic.
You must send the variables in post or get method.

Exemple using get method (Passing vars by URL)
<?php
//page1.php

$x = "hello";
echo "<a href=\"page2.php?x=$x\">Go</a>";
?>

<?php
//page2.php

$x = $_GET['x'];

if($x == "hello") {
echo "Ok";
} else {
echo "Not Ok!";
}
?>

Is basic!

  3. Re: Registering Globals   Reply   Report abuse  
Picture of John Sims John Sims - 2007-01-24 02:00:13 - In reply to message 2 from João Romão
Excellent. I understand the syntax. That was what I am missing. Too me that is magic when you understand the syntax to make it work.

Thank you for your quick response.

John Sims