PHP Alternative to Frames

Soldato
Joined
25 Oct 2006
Posts
5,395
Im trying to make a frame like environment on my website. I have the main nav bar using php include on each page to include it.

One one of the pages I also have a sidebar with links, I want this side bar to change the content beside it without opening a new web page, just like a frame.

How can I do this? Im not sure exactly what its called either in php..
 
Frames is a HTML concept (client side), and PHP is a server-side scripting language. I am not sure you'll ever get an 'alternative'?
 
If I understand correctly, you want the sidebar to be an include file. Then on each page you just say SideBar1.php is the include and on another page it would be SideBar2.php

or am I going another direction?
 
Not exactly, this drawing should explain more clearly:

designfr8.jpg
 
No he wants frames basicly, he doesn't want the whole page to reload when navigating. The talk of includes and what not is irrelevant.

And the answer the OP is looking for is: you need to use frames, or load content asynchronously using Ajax, which would require you implementing frames for redundancy anyway.
 
I dont know much about PHP etc but I have heard of different urls i.e. mysite.com/index.php?value=valuehere

Is there not a way I can use urls like that to change the content in the left hand side of the drawing above? (even if it did mean the whole page reloads)
 
ok think is what you're after

in my index.php page i have this

PHP:
$val = $_GET['id']; //get id from the url
if ( !isset($val) || $_GET['id']=="index" )
	{
	$val = "home";//defaults to homepage when no value is entered
	}

then have some html then i have this

PHP:
			///used as security to prevent use of .. : // . if an url is attempted to be entered
			$val = preg_replace('/\W/si', '', $val);
			include('./'.$val.'.php');
when index.php loads it gets the ID from the address bar for example a link like:

index.php?id=page4

this will then include page4.php into your page
 
Thanks, do I just put the pages to be included (e.g. page4.php) in the same directory as the index and it will work with no changes to your code above?

Also what part of PHP is this on tizag.com or w3schools as I would like to learn more about it.
 
It's unnecessary to use frames for this situation, the cost of generating the navbar / links on each page request will be pretty tiny, certainly not large enough to outweigh the cons of using frames (more difficult to bookmark, bad for search engines, etc).

Most web developers consider frames bad practice except in very rare circumstances, even as far back as a decade ago.
 
Well I dont mean to have frames exactly just something that emulates the functionality of frames. If marc_howarth replies I should be able to use that system if it works :)
 
you won't find this on tizag, because it's just a basic web development concept. you can pass variables to a php script in the query string (the bit after the question mark)

Code:
www.yourdomain.com/index.php?var1=foo&var2=bar

each time you want to add another key/value pair the format after the first is &variablename=variablevalue

you would then pass something like "about" to the query string under the variable page (p for short ;)) so it looks like this:

Code:
?p=about

then in your php code, do something like this:

Code:
$page = strip_tags($_GET['p']) . '.php';
require_once($page);

I hate this kind of development, though. I much prefer using some form of templating system.
 
No he wants frames basicly, he doesn't want the whole page to reload when navigating. The talk of includes and what not is irrelevant.

And the answer the OP is looking for is: you need to use frames, or load content asynchronously using Ajax, which would require you implementing frames for redundancy anyway.

Asynchronous Asynchronous Javascript and XML?!

Oh, you mean "use Javascript" :p
 
Asynchronous Asynchronous Javascript and XML?!

Oh, you mean "use Javascript" :p

Well unless you wanted to send all of the content for each page in one request, then you would have to use asynchronous requests to load each page. Also, he didn't mention 'asynchronous AJAX' anywhere in his post ;)
 
Well I dont mean to have frames exactly just something that emulates the functionality of frames. If marc_howarth replies I should be able to use that system if it works :)

I don't quite follow what you mean - why do you specifically require the center content to update independently of the page?

Unless your header / navigation has some horrendously heavy database query then there really is no advantage in not just loading the entire page, navigation and all.
 
OK I will probably do it just using pages then. Im interested in learning about this url value thing with the question marks. Does anyone know of a tutorial where I can learn more about it?
 
Asynchronous Asynchronous Javascript and XML?!

Oh, you mean "use Javascript" :p

Haha nice try but I didn't actually say it like that though! :p

Reminds me of the tagline attached to windows 2000 (i think):

"Built on NT technology" - So built on "New technology technology"? haha
 
Thanks, do I just put the pages to be included (e.g. page4.php) in the same directory as the index and it will work with no changes to your code above?
yea, the same directory and it should work fine, if you wanted to change the directory of the included pages it wouldn't be hard to edit the code to do this either

if you want to add me on msn i can help you if you get stuck :)
 
Back
Top Bottom