Forum Moderators: open

Message Too Old, No Replies

Opening a window in the same browser

html index with php calling script

         

Lady_Lea

7:06 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



Hi there - I am experimenting with php - calling bits of script, because my navigation menu keeps changing, and I have to change every page every time it does with normal html (at least thats my understanding)

So far - this is what I have - and I don't know what it is called.

this is on my main html page - hopefully calling the .php page I have loaded

<iframe marginwidth="0" marginheight="0" width="468" height="30" scrolling="no" frameborder=0 src="http://www.example.com/navbar.php">
</iframe>

Now when I click on any of the links on the nav bar - they open in the frame - and not in the browser. I am assuming this is because of the code <iframe>

What code do I need to put instead please to call the page links in the nav bar in the browser?

Can anyone help please

Thankyou in advance.
Lea

[edited by: tedster at 9:40 pm (utc) on Mar. 11, 2004]
[edit reason] use example.com [/edit]

PatomaS

7:29 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



Hello

:)

Well the solution is very easy so don't worry

just add target="_top" to the links

:)

Bye

Lady_Lea

7:50 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



oh my goodness - that is almost as bad as calling telewest for a sound problem to be told to go to the box and push the cable in (that happened yesterday!)

Thankyou so much.

Lea x

encyclo

7:55 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



this is on my main html page - hopefully calling the .php page I have loaded

<iframe marginwidth="0" marginheight="0" width="468" height="30" scrolling="no" frameborder=0 src="http://www.example.com/navbar.php">
</iframe>

I think you're going about this the wrong way - you should really be including your menu directly into each page so it becomes an integral part of it, rather than using an iframe.

Try:

<?php include($_SERVER["DOCUMENT_ROOT"]."/path/to/menu.inc.php");?>

In your file menu.inc.php you put the fragment of markup and/or php code you want on each page. Your pages will have to have the extension .php or, if they have the extension html, you need to have .html files parsed for php defined in your .htaccess file.

[edited by: tedster at 9:39 pm (utc) on Mar. 11, 2004]
[edit reason] use example.com [/edit]

Lady_Lea

8:24 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



does the menu.inc.php have to be in php?

as I dont write php - only html

I was only doing it this way so that I could change the nav bar without updating the pages.

grahamstewart

8:33 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



does the menu.inc.php have to be in php?

Nope, you could equally put..

<?php include($_SERVER["DOCUMENT_ROOT"]."/path/to/menu.html");?>

or even

<?php include($_SERVER["DOCUMENT_ROOT"]."/path/to/menu.txt");?>

Lady_Lea

8:45 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



maybe I am missing something

what is the difference in what it does to the site

What I was doing, I am assuming, put the menu in the place I want it and meant I can change it accross all the pages.

What you are suggesting appears to do the same - but you mention includes? Is this for spidering or something?

lol - you would not think I had 60 sites! But mostly I write in raw html.

Thankyou

Lady_Lea

8:52 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



ok - the /path/to/ bit is that supposed to be something of mine? I cant get this working.

lol - Lea

Lady_Lea

9:00 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



using my origional plan - its not working with the target="_top"

because its still opening in the nav frame - rather than opening in the page browser
see <Sorry, no personal URLs. See TOS [webmasterworld.com]> to see what i mean - top nav bar.

Lea

[edited by: tedster at 9:41 pm (utc) on Mar. 11, 2004]

grahamstewart

9:31 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The /path/to/ is supposed to be the path to your navbar.html or whatever. (e.g. it might be /common/navbar.html)

Heres a slighty expanded example...

You want the same navbar on every page. In fact, the top html of your pages is probably the same on all pages. So you could stick this all in one file something like this...

/common/header.inc:


<html>
<head>
..usual stuff...
</head>
<body>
<div id="navbar">
..navbar links
</div>

..then your other files would include this file by doing this..


<?php include($_SERVER["DOCUMENT_ROOT"]."/common/header.inc");?>

..rest of the page..

</body>
</html>

See?

It's just using a tiny bit of php to include another file on all your pages. Now if you need to change the navbar you only need to change the header.inc file and every page will change.

Note: your pages should end in

php
so that the server knows to process any php contained in them (e.g. they should be named
index.php
rather than
index.html
)

Hope that helps.

rogerdp

10:04 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



It gets even easier, all you need is Server Side Includes (SSI).

Make a file, such as _nav-main.html.

Wherever you want the contents of that file, use
<!--#include virtual="_nav-main.html"-->

You can include a relative path, so if _nav-main is in the parent directory of where the current file is, you can use
<!--#include virtual="../_nav-main.html"-->

All you need is to rename your pages to *.shtml, if your server is setup correctly.

Also, I highly recommend that you use multi-views so file extensions are an internal detail instead of exposing your innards. Makes maintainence easier too.

Lady_Lea

10:17 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



oh my goodness

I think I landed on the wrong planet.

Thankyou for all of that. Will have a play around with it all again and see what needs the least amount of work - you see that site is over 100 pages, and I was just going to change them gradually - I dont think that changing them to a .php is an option because of the amount of links from other sites I have already. - tho I suppose I can set up a forwarding url - ahhhh - my head hurts.

Thankyou again, sleeping now.

Lea

encyclo

11:40 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I dont think that changing them to a .php is an option because of the amount of links from other sites I have already.

Quite right - never change the file name unless absolutely forced to. However, you probably won't need to! Try adding this to a plain text file called .htaccess in your document root:

AddType application/x-httpd-php .html

Change .html to .htm if that's the extension you're currently using. An important note - check to see whether an .htaccess file exists already before uploading a new one. If one exists, just add the above line to the other entries which exist already.

rogerdp

1:20 am on Mar 12, 2004 (gmt 0)

10+ Year Member



Lady_Lea.. that is exactly why you should use content negotiation. :P Look into using multi-views on apache. It's as simple as adding this to your .htaccess file:

Options +MultiViews