0

I have 1 problem after upgrade my server to php 5.4

In our web site we are using register globals and this is removed from php 5.4

we solve this issue by using this code :

foreach ($_REQUEST as $key => $val) {
    ${$key} = $val;
} 

Its working fine if $val is English but if $val is Arabic lang this code return as empty val

I tried to use: urlencode() and htmlspecialchars() but not solve this issue.

hakre
  • 193,403
  • 52
  • 435
  • 836
Sky
  • 29
  • 5
  • This code works fine. No need to use `urlencode/urldecode` or anything if you just sty with UTF-8… `foreach( $_REQUEST as $key => $val ) { ${$key} = $val; var_dump( ${$key} ); }` => `test.php?name[]=عالية` Please do also read that post: [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – feeela Feb 18 '14 at 23:56
  • 3
    Also you don't need that loop. `extract($_REQUEST);` does the same thing, although either method invites people to overwrite your global variables. – miken32 Feb 18 '14 at 23:57
  • that is right,, the problem was from page charsets,, when i changed to utf-8 this problem is solved,, many thanks – Sky Feb 19 '14 at 01:33
  • Your question is unclear. Variables in PHP do not have any language. So that you describe that `$val` is English or that `$val` is Arabic language, is imprecise in a programming context. You have to provide example URIs and you have to share the original code accessing those variables and share the character-encoding of those php-files. – hakre May 04 '14 at 09:48
  • References: http://rosettacode.org/wiki/Unicode_variable_names#PHP - [Enable register_globals in PHP 5.4](http://stackoverflow.com/q/16706098/367456) – hakre May 04 '14 at 09:55

2 Answers2

0

Don't try to randomly call any functions. PHP does not detect any encoding. Every character is simply a sequence of bytes, with "zero" bytes having no special meaning. So essentially there shouldn't be any reason for the failure you are observing.

Do some debugging. var_dump($_REQUEST) would be in order, preferrably in a simplified testcase with only one value. If you need to detect any non-printable bytes, use echo urlencode($value) to get to the hex values quickly - but this is only for debugging! It won't help with the issue, i.e. url-encoding the value will not make it usable again for your application (the same applies to using htmlspecialchars(), which is not helping anything).

Also dump $val in your code. If it really is empty, then urlencode() or htmlspecialchars() will not change it, the error is occurring before that.

Your question yet does not reveal any more info, so please do these value dumps - and if you cannot figure it out yourself then, update your question with these dumps for all to see.

Sven
  • 69,403
  • 10
  • 107
  • 109
-1

Try adding this to your header.

<META HTTP-EQUIV="Content-Type"  CONTENT="text/html; CHARSET=iso-8859-6">
user2751638
  • 47
  • 1
  • 6
  • Randomly adding an encoding header is likely to make things worse. Besides: UTF-8 is the better alternative to be used. – Sven Feb 19 '14 at 00:02
  • that is right,, the problem was from page charsets,, when i changed to utf-8 this problem is solved,, many thanks – Sky Feb 19 '14 at 01:34