View Full Version : Iframe help: Can not find solution ANYWHERE :(

09-22-2007, 04:58 PM
I've seen this question asked on several forums yet the answer has never been provided with clarity...

In short, I have a home page, and different page with an iframe. I need links on my homepage to open the page with the iframe on it, and i need each link to open a unique(different) site in that iframe...

Specifically, I have two pages, index.htm and nba_main.htm... nba_main.htm has an iframe on it... index.htm has a menu with about 10 links ALL pointing to nba_main.htm, but I need those links to display a different page each time in the Iframe... So 10 links on index.htm going to nba_main.htm, but I need the links to be different in that they will open different pages within the iframe on nba_main.htm...

Example I

1. Someone visits index.htm and clicks on the "matchups and scores" button.
2. nba_main.htm comes up in the same browser with "matchups.htm" within the iframe window

Example II

1. Someone visits index.htm and clicks on the "live odds" button.
2. nba_main.htm comes up in the same broswer with "latestodds.htm" within the iframe window

I've been trying to tackle this all week and I would DEEPLY appreciate any help with this!

09-22-2007, 08:54 PM
I am beginning to think that this is not even possible... Please if anyone can help me out or if you'd like a better-explained description of what I am trying to do let me know... This is really holding up my site design :(

09-22-2007, 09:04 PM
You can do this with PHP (maybe javascript too, but I'd recommend PHP for several reasons-- easier, and it wouldn't require the user have Javascript enabled).

Note that to use PHP, you must have the extension of the page be .php, not .htm (unless you change your server configuration), as well as having PHP installed/enabled on the server.

Use a get variable to pass the link:
<a href="nba_main.php?iframe=http://othersite.com">

On nba_main.php:

<iframe src="<?php echo $_GET['iframe']; ?>" ....>

Now, you may also want to do a bit more to check that it is in fact a link you want to use like that, not just something the user entered randomly.

$iframe = @$_GET['iframe'];
$okurls = array(
if (!in_array($iframe,$okurls)) { $iframe = 'http://default.com'; }
Then just use <?php echo $iframe; ?> for the iframe's src.

09-22-2007, 09:38 PM
Ok, so on index.php I have a menu with a link, the link is <a href="nba_main.php?iframe=http://affstats.betus.com/NBA/matchups.aspx?ats=10468&mid=797">

On nba_main.php, I have an iframe, the spot where I want the iframe to show has this code: <iframe name="iframe" src="<?php echo $_GET['iframe']; ?>" height="800" width="500"></iframe>

And it is not working... I am not very php-inclined so I may be running into an obvious mistake... Shouldn't I have a php include in there somewhere or am I running into a different problem?

Thank you very much for your help...

09-22-2007, 10:23 PM
include() is just one function used in PHP. Not related in this case.

Link to your page. What's the problem? what IS the src of the page displayed as?

09-22-2007, 10:38 PM
On the main page, scroll over nba and a menu will drop down... On the drop down, when you click matchups it should take you to nba_main.php with the matchups page loaded in the iframe...

this is going to be the main page: www.ultimatesportsbets.com/scrap.php

this is nba_main.php:

Thanks again...

BTW... Disregard all of the other links as I am only using the nba:matchups link for testing purposes...

09-22-2007, 10:47 PM
Ok, I get it.

The issue is that the URL isn't being used fully.

The url you're using for the iframe has get variables of its own, so that confuses the browser:
http://1.com?iframe=http://2.com?a=b, etc.

So, you'll want to encode the link for a url.

Easiest way is with PHP:
<a href="<?php echo urlencode('http://whatever.com?variable=value&etc.'); ?>">

That will change symbols and spaces to their correct codes, ie %20 for space.

You could also use a different code, like

then use an array like:
array('a'=>'http://a.com'), and $that['a'] will give you 'http://a.com'.
So you don't need to send the full URL, just the reference for that link. Takes a bit more setup, but easier to remember/use the URLs.

09-22-2007, 10:53 PM
So my link should be looking something like this?
<a href="<?php echo urlencode('http://www.ultimatesportsbets.com/nba_main.php?iframe=http://affstats.betus.com/NBA/matchups.aspx?ats=10468&mid=797'); ?>">

I apologize for my ignorance with using php :\

09-22-2007, 11:13 PM
Yep. Looks right.
Or you could manually change the link to a url supported format, but that would be hard unless you happen to have it memorized.

09-23-2007, 12:21 AM
I tried it and it gives me a 404 error :( I am completely out of luck with trying to get this done... :-\

The error can be seen by visiting the above links again or... http://www.ultimatesportsbets.com/scrap.php

09-23-2007, 12:30 AM
Use the other option I suggested, then.
?id=#, like ?id=0, or ?id=5.
Then just use:
$urls = array(
$id = @$_POST['id'];
$url = isset($urls[$id])?$urls[$id]:$urls[0];
echo $url; //later when you need it
Note that this will use the first one as the default, ie, index 0. The id will choose anything from 0 up, if it has a value. If not, uses the default.