forcing global variables
I have a friend using PHP 4.1.2 but home PC is 4.2.3
with 4.1.2 global variables are on while 4.2.3 is off
Is there anyway to force the 4.1.2 to be off (hasn't got access to php.ini)
Any code snipet that could be added to top of each script?
Mark Hensler posted this at 06:34 — 6th October 2002.
He has: 4,048 posts
Joined: Aug 2000
We'll, I've got mine stuck to off, so I can't test this script. But give this a try:
<?php
echo \"<html><body><pre>\n\";
print_r($_GET);
print_r($_POST);
echo \"<hr>\n\";
foreach ($_GET as $var=>$val) {
echo \"unsetting \$$var\n\";
${$var} = NULL;
unset(${$var});
}
foreach ($_POST as $var=>$val) {
echo \"unsetting \$$var\n\";
${$var} = NULL;
unset(${$var});
}
echo \"<hr>\n\";
foreach ($_GET as $var=>$val) {
echo \"\$$var = ${$var}\n\";
}
foreach ($_POST as $var=>$val) {
echo \"\$$var = ${$var}\n\";
}
echo \"</pre></body></html>\";
?>
Mark Hensler
If there is no answer on Google, then there is no question.
Busy posted this at 07:11 — 6th October 2002.
He has: 6,151 posts
Joined: May 2001
comes up with
<?php
<html><body><pre>
Array
(
[id] => 200
)
Array
(
)
<hr>
unsetting $id
<hr>
$id =
</pre></body></html>
?>
the [id] => 200 should equal 1, then increment and next be 2 ... but since it wont pass values onto the other page it's says at 1
Mark Hensler posted this at 07:50 — 6th October 2002.
He has: 4,048 posts
Joined: Aug 2000
The value of $_GET["id"] (and the global $id) was initially 200. But the code did unset the value of the global $id variable. Looks to me like the snippet is working.
I'm not sure what your talking about. I'm guessing you expected it to be 1? I have no idea why $id was initially 200.
Mark Hensler
If there is no answer on Google, then there is no question.
zollet posted this at 09:22 — 6th October 2002.
He has: 1,016 posts
Joined: May 2002
I _think_ you can put php_admin_value register_globals Off in .htaccess or httpd.conf to turn register_globals off for a specific site.
Mark Hensler posted this at 19:26 — 6th October 2002.
He has: 4,048 posts
Joined: Aug 2000
php_admin_flag and php_admin_value are only allowed in the httpd.conf file
php_flag and php_value are allowed in both httpd.conf and .htaccess
Busy posted this at 20:32 — 6th October 2002.
He has: 6,151 posts
Joined: May 2001
Mark, I tried it on my PC, turned globals and magic quotes on (to suit friends home php.ini) the variable thing worked on mine but things like sessions and forms didn't.
How would I go about trying these;
php_flag=0 or php_flag=off ?
How about forcing the globals on then, so he can write code on 4.2.3 to suit 4.1.2
I know security is an issue with them on but info wise he hasn't got anything worth while to anyone and using one form for emailing (that I know of, told me about)
Mark Hensler posted this at 04:51 — 7th October 2002.
He has: 4,048 posts
Joined: Aug 2000
register_globals can only be changed with php_admin_flag
the syntax is:
php_flag register_globals On
php_value include_path /path/to/html:/path/to/something/else:/and/another/path
To unset everything, try this:
<?php
$tmp = array($_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_REQUEST, $_SERVER, $SESSION);
foreach ($tmp as $tmp2) {
foreach ($tmp2 as $var=>$val) {
unset(${$var});
}
}
unset($tmp2);
unset($tmp);
?>
Mark Hensler
If there is no answer on Google, then there is no question.
Busy posted this at 23:21 — 12th October 2002.
He has: 6,151 posts
Joined: May 2001
Sorry for the delay in reply, my friend was away on business.
Mark, we tryed the above code (session is missing the underscore) worked on some but not others so have decided to go back to PHP 4.0.6 on his home machine (was what it was before he updated) while his web host is using 4.1.2
Thanks again guys
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.