php Url redirection to iframe

sapo

Power Member
Joined
Feb 25, 2008
Messages
510
Reaction score
286
Im trying to keep this in my header and just redirect the target iframe below.

like this php redirection will be in the horizantly navigation that it the main page and the body is a iframe.

Code:
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];

if(preg_match('/microsoft|window/i', $user_agent)) {
	header('Location: http://www.yahoo.com');
} elseif(preg_match('/mac|os x/i', $user_agent)) {
	header('Location: http://www.google.com');
} else {
	header('Location: http://www.bing.com');
}

?>

<iframe name="donkey" src="http://donkey.com" </frame>

how do i change the redirection to traget the iframe?
 
i cant post links since im new here but if you PM me i've got a url to explain it and provide working code.
 
haha... that code looks familiar. :D

I'm not quite sure what you want to do from your description - you have an iframe on your page, and you want to show different content in the iframe depending on the OS?
 
its old school html. like having a top nav bar that is loaded from say index.php and the lower portion of the site is an iframe. using the nav bar u want to change the pages of the iframe, not the entire page.
 
its old school html. like having a top nav bar that is loaded from say index.php and the lower portion of the site is an iframe. using the nav bar u want to change the pages of the iframe, not the entire page.

That style of navigation would generally be a regular frameset, not an iframe.

I'm still not quite clear what the OP is trying to achieve, because the current code would be redirecting all traffic to a search engine before the iframe is displayed.
 
[shrugs] i was jus tryin to point him to a iframehtml page that explains this option, along with some alternatives lo

hopefully he just changed the urls to diff ones to keep his pages to himself, cause i have no clue why one would want to route to diff search engines.
 
LOL yeah that code is familiar, jacked it from the other thread sort of.

but yeah this is what I want.

=====================
top nav bar
<php code that redirects but instead of redirecting the whole page to somehwere just redirect the iframe below

=============================
============================
< iframe name ="target iframe /iframe >

====================================================

hope that explains it, It rough
 
LOL yeah that code is familiar, jacked it from the other thread sort of.

but yeah this is what I want.

=====================
top nav bar
<php code that redirects but instead of redirecting the whole page to somehwere just redirect the iframe below

=============================
============================
< iframe name ="target iframe /iframe >

====================================================

hope that explains it, It rough

Oh, if i get what you are saying, than thats cake:)

Code:
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];

if(preg_match('/microsoft|window/i', $user_agent)) {
	$site= "http://www.yahoo.com";
} elseif(preg_match('/mac|os x/i', $user_agent)) {
	$site="http://www.google.com";
} else {
	$site= "http://www.bing.com";
}

?>

<iframe name="donkey" src="<?php echo $site; ?>" </frame>

Hope it helps
 
Sorry, didn't see the "name" thing where the iframe's name has to change. Im not sure why that would matter, but here is the code for that:

Code:
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];

if(preg_match('/microsoft|window/i', $user_agent)) {
	$site= "http://www.yahoo.com";
$name="yahoo";
} elseif(preg_match('/mac|os x/i', $user_agent)) {
	$site="http://www.google.com";
$name="google";
} else {
	$site= "http://www.bing.com";
$name="bing";
}

?>

<iframe name="<?php echo $name; ?>" src="<?php echo $site; ?>" </frame>
 
So you want to display different content in the iframe below depending on what link they click in the top navbar?

Here's your main page that contains the iframe:
Code:
<html>
<head>
<title>Main page</title>
<script>
function loadIframe(iframeName, url) {
    if ( window.frames[iframeName] ) {
        window.frames[iframeName].location = url;   
        return false;
    }
    return true;
}
</script>
</head>
<body>
<a href="iframepage.php?id=1" onclick="return loadIframe('myiframe', this.href)">Page 1</a> | 
<a href="iframepage.php?id=2" onclick="return loadIframe('myiframe', this.href)">Page 2</a> | 
<a href="iframepage.php?id=default" onclick="return loadIframe('myiframe', this.href)">Default</a>
<br>
<br>
<iframe src="iframepage.php?id=default" name="myiframe" id="myiframe" width="800" height="800"></iframe>
</body>
</html>

Here's your iframe page that loads a different url, depending on the top nav bar link that was clicked:

Code:
<?php

if($id = $_GET['id']) {
	// great
} else {
	$id = 'default';
}

switch($id) {
	case '1':
		//echo "It's 1";
		header("Location: http://www.wormgush.com/", true, 301);
		break;
	case '2':
		//echo "It's 2";
		header("Location: http://www.eelsoup.net/", true, 301);
		break;
	default:
		//echo "Default";
		header("Location: http://www.nutabuse.com/", true, 301);
		break;
}

?>

You can see that the main page contains a javascript function that loads a new version in the iframe.

The iframe page takes a $_GET argument and allows you to load a different url depending on which $_GET variable you append to the iframe url.
 
Sorry, I must have misinterpreted. Autmun's anwsner is more correct than mine.

But why are you using $_SERVER['HTTP_USER_AGENT'] ? That is used to get the browser of user, has nothing to do really with navigation.

My script is for a different iframe based on a different browser.

Also, the easiest way to make buttons that navigate iframes is just use javascript to change the src of the iframe.
 
thanks everyone for their response I dont have time to test right now but will test within the hours and reply. thanks. love bhw
 
I tested all the example but none worked. some about the url is too long, seems like it was just adding to itself

check this out.
Code:
http://bit.ly/uQWQPP

maybe that will explain what I looking for.

and the reason Im doing this is cause I am redirecting on referrer no operating system, so that why I need it to be on the top part and control the iframe. instead of the iframe just having the code cause then it will always be my own site being the referrer
 
I tested all the example but none worked. some about the url is too long, seems like it was just adding to itself

check this out.
Code:
http://bit.ly/uQWQPP

maybe that will explain what I looking for.

and the reason Im doing this is cause I am redirecting on referrer no operating system, so that why I need it to be on the top part and control the iframe. instead of the iframe just having the code cause then it will always be my own site being the referrer

:smashfrea You seem to change the thing you're looking for with each post.

Here is a script that changes the iframe based on the referer:

Code:
<?php
$referrer=$_SERVER['HTTP_REFERER'];

if ($referrer=="http://facebook.com")
$site="http://websiteA.com";
elseif ($referrer=="http://twitter.com")
$site="http://websiteB.com";
else
$site="http://websiteC.com";
?>

<iframe src="<?php echo $site; ?>"></iframe>
 
:smashfrea You seem to change the thing you're looking for with each post.

Here is a script that changes the iframe based on the referer:

Code:
<?php
$referrer=$_SERVER['HTTP_REFERER'];

if ($referrer=="http://facebook.com")
$site="http://websiteA.com";
elseif ($referrer=="http://twitter.com")
$site="http://websiteB.com";
else
$site="http://websiteC.com";
?>

<iframe src="<?php echo $site; ?>"></iframe>

lol thanks that worked, I figured the os code and referrer code were the same, so I just copied and paste that code rather then logging into my cpanel at the time and grabbing the real code. and I type how I talk lol, But thanks man greatly appeaciated..l
 
I tested all the example but none worked. some about the url is too long, seems like it was just adding to itself

check this out.
Code:
http://bit.ly/uQWQPP

maybe that will explain what I looking for.

and the reason Im doing this is cause I am redirecting on referrer no operating system, so that why I need it to be on the top part and control the iframe. instead of the iframe just having the code cause then it will always be my own site being the referrer

If you tried the code I posted then you must have made an error somewhere because I tested it and it worked fine.

Also it pays to be specific both when reporting error messages and when describing what you want to do. You just wasted a bunch of people's time because you didn't describe what you really wanted to do until your 4th post in the thread.
 
If you tried the code I posted then you must have made an error somewhere because I tested it and it worked fine.

Also it pays to be specific both when reporting error messages and when describing what you want to do. You just wasted a bunch of people's time because you didn't describe what you really wanted to do until your 4th post in the thread.

Im sorry man didnt mean to offend anyone, and I seen hello answered it way before. I just didnt look hard enough. My bad. I was exteremly swamped right now with pms etc etc. not an excuse. sorry.
 
revisiting this, I cant get the iframe to be a full page iframe, it just a lil 400 by 400 square.

Code:
<?php
$referrer=$_SERVER['HTTP_REFERER'];

if ($referrer=="http://facebook.com")
$site="http://yahoo.com";
elseif ($referrer=="http://twitter.com")
$site="http://google.com";
else
$site="http://bing.com";
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
html {overflow: auto;}
html, body, div, iframe {margin: 0px; padding: 0px; height: 100%; border: none;}
iframe {display: block; width: 100%; border: none; overflow-y: auto; overflow-x: hidden;}
</style>
</head>
<body>
<iframe id="tree" name="tree" src="<?php echo $site; ?>" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
</body>
</html>

thats what I am using, I need the iframe to be full page
 
<html>
<head><title>iframe 100%</title>
<style type="text/css"> body,html{width:100%;height:100%;margin:0;overflow:hidden}</style>
</head>
<body>
<iframe width="100%" height="100%" frameborder="0" src="cant/post/links/yet.html"></iframe>
</body>
</html>

I got this code from another post. It should work on all browsers.
 
Back
Top