Php pop up window broken. Help?

I have php 5 installed for now, but I’m finding that the javascript pop up window is no longer transferring the data to the pop up window. It is supposed to display a larger image than the thumbnail upon click. I am not sure if this broke in php5 or not, but I’m trying to repair some older sites.What happens is that the pop up window opens, but the data is not transferred to it. This is the code in the catalog page:

<p align="center">
<a href="#" o click="MM_openBrWindow('<?php echo "show_image.php?img={$row_viewall['pictures']}"; $img = $row_viewall['pictures'];?>','','toolbar=yes,scrollbars=yes,resizable=yes,width=550,height=500');return false"> 
<img src='<?php echo $row_viewall['thumbnail']; ?>' alt="<?php echo $row_viewall['item_name']; ?>" border="0" /></a><br />

<span class="under"><?php echo $row_viewall['item']; ?></span> 

Where pictures is the field for the larger image the thumbnail is what it says. The popup window code is below. Would appreciate if you can help me figure out what is no longer allowed. It used to work just fine.

 <?php $id1 = basename($img, '.gif');
$id2 = basename($id1, '.jpg');
$iden = basename($id2, 'images/');

<script language="JavaScript" type="text/JavaScript">
function open_on_entrance(url,name)

popupWin ='show_image.php','Enlarged_View', ' resizable, width=400,toolbar=0,height=450,left=100,top=100')
<title>Large View of <?php echo $iden; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body >
<div align="center">
Large View of Item no. <?php echo $iden; ?> </p>

<p><img src="<?php echo $img; ?>"><br>
<a href="javascript:window.close()" onMouseOver="window.status='Close Window';return true" onMouseOut="window.status='';return true"><em> Close 
Window </em></a></p></div>


Presuming that the second section of code is your show_image.php, is the code to extract $img from the URL somewhere else, and is it working correctly?

I’ve a vague idea that someone mentioned that very early versions of PHP would automatically parse URL variables into internal variables of the same name, but I can’t find a reference to it, I’d always expect to see it extracted from the appropriate superglobal array, $_GET in this case.

There are a lot of “flavours” of PHP 5, from 5.1 to 5.6.

Which version exactly are you using?

PHP Version 5.6.38 and adding $_GET[$img]; to the pop up window (show_image.php) did not work.

The img shows correctly in the base page

Can you show exactly what you did? Note that it should be $_GET['img'] - remember, $img does not exist in show_image.php unless you create it somewhere.

ETA - is the image URL-friendly when it is stored?

HI, it exists in on the catalog page: $img = $row_viewall[‘pictures’];? in the first line

I placed $_GET[$img]; in the first line of show_image.php page

Yes, but not in the completely separate show_image.php script, where you are trying to use it. You’re passing the value of that variable through in the URL, but not the name of it. In this section of code:

<a href="#" o click="MM_openBrWindow(
   '<?php echo "show_image.php?img={$row_viewall['pictures']}";
   $img = $row_viewall['pictures'];?>'
   return false"> 

you are assigning it a value immediately after you echo the value as part of the URL, but only within this specific script. In fact if this is a catalogue of images, perhaps this bit of code is inside a loop, which means that the value of $img is changed for each iteration of the loop.

That’s not the correct syntax. Have a look at the post above. In order for that line to work, you first have to have a value in $img. As you said that’s the first line of the script, there can’t be any lines before it to have assigned $img any kind of value, so that equates to $_GET[''], which might give an undefined index error.


o click="MM_openBrWindow

should be



I’m presuming that, too - OP says that the window opens, so it must be just a thing from copy/paste onto here.

1 Like

i think the editor of my post did that. yes it is onclick in the script

I appreciate the help. The frustrating thing is that it used to work just fine. So I’m not sure what I need to add to get the variable to pass through. It is in a loop of catalog images, so it has to post the current image value on click. However, if I place the GET after the first line, the $img variable is already assumed, which is no longer working. It isn’t being passed.

What do you suggest? The other thing I thought of might be a complete php hover solution, if that is possible. But couldn’t find an example that would eliminate the need for a pop up. But if it relies on scripts, I might have the same issue.

As in my earlier post, you need to get the value from the URL:

<?php $id1 = basename($_GET['img'], '.gif');

I did mention that I’ve a vague idea that (very) old versions of PHP didn’t need this, that they would automatically parse out parameters into variables. I tried a bit of a search to see if I’d imagined it, but I didn’t get very far. That would certainly explain why it used to work, though.

Thanks It didn’t work. :frowning: nor did $_GET[$img]

No, well, that won’t work as we’ve said.

When you hover over the link, what does the URL show? That is, is the value for the img parameter as you would expect?

The url is the currentpage.php# which is the href link # in the onclick script. Doesn’t show an img parameter.

That suggests that there is nothing in your $row_viewall['pictures'] variable, unless the fact that it’s an onclick handler rather than a “normal” a href URL that is blocking it.

If you right-click and view source in your browser, has it put a value that you expect into the link?

yes it is there:

<a href="#" 
return false">
 <img src="" alt="R-227A-01" border="0">

OK. Can you modify the start of your show_image.php file to read like this, then show the results when you click on the link please?


Or, if you haven’t changed the use of $img further down the page to use the $_GET array member, you could just add this line:

$img = $_GET['img'];   // this is the new line
$id1 = basename($img, '.gif');  // and this is your old first line, carry on from here

but I doubt that would help, as all the other data (title, description) would have been populated after you changed the start of the script as per post 12. As you said that hadn’t worked, I presumed the title and so on was still blank at that point.

1 Like

This is way cool So the dump gives this result in the popup window:
array(1) { [“img”]=> string(19) “images/BR-02-05.jpg” }

And adding the line above fixes it!!! Wow. THANK YOU! This all has to do with the change in the way php handles javascript content?

PHP has no idea that the information has come from JavaScript. It must be that some old version would automatically parse that array into discrete variables. I’ve had another search as I have an idea that it’s been mentioned on here, but I can’t easily find it.

Glad it’s working now, anyway.