PHP4 - PHP5 Problems
- Started
- Last post
- 15 Responses
- uan
Hello,
wrote a website in php.
its really basic php. just some variables to switch language.works fine on a server with PHP4.
doesnt work at all on a server with PHP5?!?anyone had this experience yet? any solutions?
tnx.
- rabattski0
wow. weird. logically it would be the other way around but 4 not running on 5? odd. no errors?
- uan0
no, no errors...just no working...
....found something about the 'register_globals = on' setting.
i think that is the problem, but ill have to check...and debug:-].
- uan0
well in PHP4: register_globals = on by default.
in PHP5: register_globals = off by default.
thats why my code doesnt work.
- mrming0
Yep - that'll be your problem. register_globals can be bad for various security reasons. If you're writing PHP in the future try not to write scripts that depend on it.
- rabattski0
i think you can have the register_globals set to on as long as your safe_mode is on as well. that way you can bypass the safe_mode if necessary by adding a .htaccess file to your php folder containing e.g. addtype application/cgi-php php.
- unfittoprint0
Also in the last version of PHP4, register_globals were turned off for security reasons. Use $_SESSION, $_SERVER, $_GET or $_POST to pass those $variables between script pages.
- uan0
I have this problem now.
in the header i declare
if(!$lang)
{
$lang = "e";
}then i do a echo("$lang"); it works: output = e.
But then I have in a link something like
index.php?lang=$langbut the $lang variable doesnt appear, i mean on click it sends only
index.php?lang=....
how do i fix this?
- unfittoprint0
//to receive all GET variables:
foreach ($_GET as $key => $value) {
$$key = $value;
}//to receive all GET variables:
foreach ($_POST as $key => $value) {
$$key = $value;
}
- uan0
thank you unfittoprint!!
it took me some time to understand your code (I'm not very used to PHP at the moment),
but finally it helped to solve my problems!thanks!
- moth0
So it's recommended to run in safe mode with globals on?
Is that likely to trip up code in itself?
- rabattski0
yep. i would have safe_mode=on & register_globals on. if i need to bypass safe_mode i would go about it thru using a .htaccess specifying so (see prev. post). a wee little bit slower though.
- moth0
Hmm. ok. Think I need to do some further reading cos there's all sorts of stuff in php.ini relating to safe mode...
- enobrev0
it's recommended to keep register_globals off no matter what, although safe_mode is another layter of proection (which tends get in the way more than anything, imo).
unfit's function is a good way to translate the superglobals ($_GETs and $_POSTs) to local variables. To shorten it, you could use the loop once with the little known $_REQUEST superglobal ,which is both $_GET and $_POST arrays all in one.
It's probably best to just get the hang of using the superglobals themselves. In the long run it makes your code easier to read and maintain.
So when you're looking at a page of code, every time you see $_GET['var'], you KNOW it's looking at the url for it's variables. When you see $_POST vars you KNOW they are meant to be from a form. As your scripts grow, these littel hints can be really helpful for debugging and understanding.
Good luck!
- unfittoprint0
eno, you're saying I can have only one loop using $_REQUEST to retrieve url AND form vars?
Does it include anything more than those 2 arrays?nice, nice.
btw, I'll write u for an expert opinon regarding a personal project of mine.
cheers.
- enobrev0
yep, the $_REQUEST var is basically meant to catch all 'incoming' vars (non session, cookie, server - just gets and posts).
But, just to be sure, test it out by posting to a script with vars in the url as well . I know it grabs from both, like an array_merge (pretty sure), but im not sure how it handles duplicated variables and such.
echo '' . var_export($_REQUEST, 1) . '';
will show you what you need to know.
And for your personal project, write away!