View Full Version : php layout help!
nekng
04-24-2006, 03:19 AM
Can someone help make an index page (backstageneopets.com/index.php) that has an iframe and if a user goes to index.php?frame=23 then the page will load 23.html(same floder as the index) in the iframe? I would also like the index page to have the layout found at http://www.backstageneopets.com/pass_save/layout/ (username: Username pass: apple35 , CaSe SeNtIvE) Lastly I don't know any php so if you could write things in a way that I could understand it, I would be very appreciative.
Thanks so much!
Simply:
<iframe
src="<?php echo($_GET['frame']); ?>" name="main" frameborder="0" height="999"
width="438">
djr33
04-24-2006, 06:11 AM
Assuming you can place php in the right spot on a page, the layout doesn't matter.
Here's the answer:
What you're talking about is called "GET". index.php?var=value.
To get GET values (heh), just use "$_GET['varname']".
This is ALL you need to do for what you're talking about.
1. Find your iframe tag.
2. Place the following code in it:
<iframe src="http://path/<?php echo $_GET['frame']; ?>.html">
All that php does is "echoes" (outputs) whatever "?frame=this" is.
Change the path, .html, etc to your liking.
This will work with anything in the address bar.
However, the one catch is that if someone were to put "?frame=JSDFKL", then it would give an error... 404 in the frame.
You could have a code check if the page is valid. A bit more complex though.
Something like this:
<?php
$url = $_GET['frame'].".html";
if (file_exists($url)) { $link = $url; }
else { $link = "default.html"; }
?>
And put:<? echo $url; ?> where you want the url to go (inside the iframe tag, after src="...
EDIT: Darn you, Twey... beat me to it. :) Ha.
Same code, by the way, nekng. Use either... and use my second one if checking is important to you.
You could have a code check if the page is valid. A bit more complex though.There's no need. It doesn't pose a security risk, and if the user starts fiddling around with GET variables on the URI, s/he can expect to break things; there's no need to cater for that possibility.
nekng
04-24-2006, 01:46 PM
perfect, thankx!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.