Dynamic part of PHP include URL not functioning properly

Hello Experts!

I have defined a php include in my (MySQL) database as follows:
<?php include ('includes/travel_pic_thumbnails.php?poi_id=163'); ?>
...which i'm trying to use on my main site (www.globexposure.net/index.php) to display photos in a Google Maps Infowindow in conjunction with the Javascript thumbnail viewer, Highslide.
This can be seen by clicking on the Norwich (SE England) pushpin marker > arrow marker > home icon (hardcoded images) vs airplane icon (dynamic pictures loaded by php include).

The php script isn't being included however, so i have seperated the Google API code from the Highslide code to make this problem a little easier to follow. The current test site, www.globexposure.net/example-mini-gallery.php, displays a single image (as it should).
When this image is clicked, Highslide loads it and displays a controlbar for cycling through multiple images. The problem is the other images aren't being loaded by the php include, so it's not possible to cycle through them!

Initially i thought the php include itself was working well and the Highslide javascript was at fault, when in fact the Highslide forum has helped to establish that it's the other way round:
http://highslide.com/forum/viewtopic.php?t=2600&postdays=0&postorder=asc&start=0

The Highslide developer who has been helping me has got as far as diagnosing the problem as:
"Got to the cause, it's the dynamic part of the include url which seems to be the issue"
and...
"Can you try to find a different method of outputting the image links, I'm not happy with travel_pic_thumbnails script. There's a delay before images appear (the page loads first followed by the images). So I think what is happening is the include is working but it's pulling in a blank page."

This is as far as we have got - so i was hoping one you could help better explain and hopefully resolve this problem?


Many thanks for any help you can give me
DaniishAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ahoffmannCommented:
> I have defined a php include in my (MySQL) database as follows:
does this mean that you generate the PHP code dynamically per request from that db?
0
DaniishAuthor Commented:
Yes i think so.

Though i have to hardcode that php include into each database record where i would like to display multiple images, because the rest of the site is written in client-side javascript, this was the only way i could think of doing it. So in this respect it's not too dynamic.
0
DaniishAuthor Commented:
MX3Design from the Highslide forum has managed to get the development site working:
www.globexposure.net/example-mini-gallery.php

BUT - he has had to drop the dynamic include. Instead his workaround is to place an index file in each photo sub-directory of /travel_pics/ - (see code snippet).

Obviously, if you can see a way that i can maintain the dynamic include that would be very much appreciated.

<?php
if ($handle = opendir('your/full/relative/path/to/includes/travel_pics/163')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && $file != "index.php") {
            echo "<a href=\"includes/travel_pics/163/$file\" onclick=\"return hs.expand(this, { thumbnailId: 'thumb1' })\" class=\"highslide\"><img src=\"includes/travel_pics/163/$file\" alt=\"\" /></a><br />";
        }
    }
    closedir($handle);
}
?>

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ahoffmannCommented:
just to be sure that I understand what you do:
  the request from the browser goes to a php page/script which queries a database which returns php code, and you want to execute that php code in your script and return the result to the browser

Is this correct?
0
DaniishAuthor Commented:
So just to clarify, the dynamic php include (see attached), which is called as follows:
<?php include ("./includes/travel_pic_thumbnails.php?poi_id=163"); ?>

has been dropped in favour of a simpler, albeit more laborious solution of using the following include:
<?php include ('includes/travel_pics/163/index.php'); ?>

...which requires the index file, as detailed in my last post, to be manually placed in each photo directory.
travel-pic-thumbnails.php.txt
0
DaniishAuthor Commented:
Yes that's right ahoffmann.
0
ahoffmannCommented:
Then you have to find a web/application server which "post processes" the result of your first php script again before it's passed to the browser.
IIRC there does not exist such a web server.

I guess you need to rethink about your architecture.
IMHO it's a bad idea to rerieve (php or any other) code from the database to be processed.

If you realy insist on your current solution --which I don't recommend-- then you have to change the code stored in the database to be plain php code (without the enclosing <?php ?> tags), and use php's eval() to execute it from within your script.
If you do that, ensure 101% (better 150%) that the code in the database is written by you, as it is very dangerous to evaluate dynamic code. You have been warned.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DaniishAuthor Commented:
Assuming that i currently include the following in my database record:

<?php include ("./includes/travel_pic_thumbnails.php?poi_id=163"); ?>

how would this be coded for using eval() ?
The example code provided on php.net (see attached snippet) is still enclosed by <?php ?> tags
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";
?>

Open in new window

0
ahoffmannCommented:
> Assuming that i currently include the following in my database record:
the database record should look like:

   include ("./includes/travel_pic_thumbnails.php?poi_id=163");

then you get this table cell and in a variable, let's say $str, then do

  eval($str);

BTW, what should the
   ?poi_id=163
do in this path? Remember that this include is a filesystem path and not a URL!
0
DaniishAuthor Commented:
So for example, a record in my database with the php include currently looks like this:

<div><a id="thumb1" href="/includes/travel_pics/163/Toby Texas Chainsaw Massacre.jpg" class="highslide" onclick="return hs.expand(this)">
<img style="float: left; margin: 0px 10px 8px 0px;" src="/includes/travel_pics/163/Toby Texas Chainsaw Massacre.jpg" width="100" height="100" alt="Highslide JS" title="Click to enlarge"/></a>
My family moved here, from College Road, when I was aged 12, after I spotted the house was for sale when we visited another further down the Close. We couldn't believe our luck when it was in our budget and this is where my folks have been based since 1992...and I dare say for a fair few years to come.
</div>
<div class="hidden-container">
<?php include ('includes/travel_pic_thumbnails.php?poi_id=163'); ?>
</div>

so how would this be encoded into a variable called $str ?

The ?poi_id=163 is passing the record 'id' in the url which is used by the travel_pic_thumbnails.php script to retrieve the relevant photos from a subfolder of /travel_pics/ that is named accordingly.

Will that still work?
0
ahoffmannCommented:
dooh, as I said, you better redesign your architecture

For your example above, you need to parse what you get from the database and extract the parts being php code (those you enclosed in php tags), then eval that code and insert it again in your data.
Ugly, very ugly code ...

>  .. ?poi_id=163 is passing the record 'id' in the url
as I said: you don't have an URL here, it's a filesystem path.

Please read my suggestions carefully.
0
DaniishAuthor Commented:
OK sorry i see where your coming from now.

Personally, i would much prefer to keep my code seperate from my content and therefore not use a php include in the database, but i'm really not cluded up enough on php to know what alternative structure i could use.

In essence i need to display a single image with text pulled from mysql and when this image is clicked it uses the Javascript thumbnail viewer, Highslide, to open the image. - this i have working!

Highslide has a controlbar, which allows me to cycle through multiple images and i want it to do this for all the images that are in the same folder as the above image. The problem is the client-side Javascript can't read whats on the server, so i was trying to use php to dynamically pass the folder name that is based on the record primary key ('poi_id') back to the Highslide Javascript:
/includes/travel_pics/$poi_id/

I realise this is rather convoluted method but it's all that i could think of. Is there an obvious alternative architecture that i should consider?

Thanks again
0
DaniishAuthor Commented:
Thank you for diagnosing the issue in my code. I will ask a new question to establish how it would be better to structure my code - please respond if you have any ideas.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.