开发者

$_GET Breaks XML

I'm using the SimpleViewer flash image gallery on a site, and it uses an XML file for information about the images it displays.

For the site, I need to dynamically generate the XML, so I'm using a PHP file with a text/xml Content-type declared. However, for some reason when I access one of the GET variables in the $_GET array SimpleViewer tells me that there are no images in the gallery, even though when I view the source it looks the exact same and is well-formed.

Here's the code:

$photos = array(
 "1" => array("house1_1.JPG")
);
foreach($photos[$_GET["hid"]] as $p){
 echo '';
}

If I replace $_GET["hid"] with "1" then it works fine, but when I make the reference to $_GET it returns the error.

Is there some reason as to why accessing a GET variable would cause scripts linking to the XML (the SimpleViewer flash) to malfunction, and is there a way to get around this?

*Note: The "hid" GET variable is 100% sure set to "1", and there is no PHP error. Also, the output looks exactly the same for when I use $_GET["hid"] versus "1", the only difference is the SimpleViewer script refuses to see that the images are there. Also, the stuff in the empty quotes is some XML, but I don't know how to get it to appear in the tags...

Var dump of $photos and $_GET, respectively:

array(1) {开发者_如何学运维
  [1]=>
  array(1) {
    [0]=>
    string(12) "house1_1.JPG"
  }
}
array(1) {
  ["hid"]=>
  string(1) "1"
}


I would first check and make sure $_GET["hid"] is returning "1". If it's possible that it is not returning "1" then it should throw an error accessing a bad index of $photos.


Is the $_GET hid variable set in your request? If not this will trigger a PHP warning.

var_dump($_GET['hid']); to see the value of the $_GET variable and ensure it as you expect.

Also please ensure that you have error reporting set to at least E_ALL and display errors is set to yes/true to make your debugging easier.


I think you're probably having an issue with the difference between "1" and 1. When you use a get with something like ?hid=1, it's not coming through as a string, that's being converted to a number, whereas your actual array is using the string "1" as the key.

Either change your key to 1 instead of "1" or cast the hid to string.


Issue was never resolved -- I ended up having to just move on and go for a longer and less elegant solution. Oh well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜