Forum Moderators: coopster

Message Too Old, No Replies

PHP & Javascript - How to create some dynamic PHP pages for this site?

making my navigation dynamic thru PHP

         

loopylee130

9:25 pm on Oct 28, 2006 (gmt 0)

10+ Year Member



Hi, I need some expert help!?
I am trying to incorporate php into an example site that i am messing about with at the moment

Basically it all works fine as static html files, but i would like to replace the index.html file with an index.php file and then have ALL the linking pages dynamically generated on the fly.
I think what i am trying to say is that i need to append some variables and values to a URL (e.g. in my case, index.php?go=what) with Javascript and then use php (or javascript) to redirect the web browser to that URL.

At the moment the website relies on some Ajax (.js) files, a set of XML files which form the basis of the navigation content, and some CSS.

The index.html file has the following code:

------------------------------------------------------
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> - rest, relax and recuperate.</title>
<link href="css/layout.css" rel="stylesheet" type="text/css" />

<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<script type="text/javascript" src="js/photo.js"></script>
<script type="text/javascript" src="js/utils/AjaxUpdater.js"></script>
<script type="text/javascript" src="js/utils/HTTP.js"></script>
<script type="text/javascript" src="js/utils/Ajax.js"></script>
<script type="text/javascript" src="js/Content.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
</head>

<body onload="javascript:preloadImages(new Array('img/photos/1.jpg', 'img/photos/2.jpg', 'img/photos/3.jpg', 'img/photos/4.jpg', 'img/photos/5.jpg', 'img/photos/6.jpg', 'img/photos/7.jpg', 'img/photos/food.png')); correctPNG();">

<div id="main">
<div id="header">
<a href="./" id="logo"><img src="img/logo.gif" border="0"/></a>
<div id="navigation">
<div id="navContainer">
<a href="index7958.html?go=what" class="navItem">What Is?</a>
<a href="indexba80.html?go=where" class="navItem">Where Is?</a>
<a href="indexa402.html?go=who" class="navItem">Who Is?</a>
<a href="index7607.html?go=prices" class="navItem">Prices</a>
<a href="index744c.html?go=faqs" class="navItem">FAQs</a>
<a href="indexc35d.html?go=contact" class="navItem">Contact</a>
<a href="index48bb.html?go=press" class="navItem">Press</a>
<a href="index547f.html?go=partners" class="navItem">Partners</a>
</div>
</div>
</div>
<div id="contentContainer">
<div id="gourmet"><img src="img/photos/food.png" border="0"/></div>
<div id="content2"></div>
<div id="content">
<script type="text/javascript">
var indexMax = "7";
var index = 1;
newPhoto();
</script>
</div></div>
<div id="footer">
<div id="link"><a href="index7607.html?go=products#GoGourmet"><img src="img/gogourmet.gif" border="0"/></a></div>
<div id="link"><a href="index7607.html?go=products#GoPicnic"><img src="img/gopicnic.gif" border="0"/></a></div>
<div id="link"><a href="index7607.html?go=products#GoSnack"><img src="img/gosnack.gif" border="0"/></a></div>
<div id="link">
<br/><a href="javascript:NewWindow('updates.html', 'FreeUpdates', '350', '200', 'yes');"><b>Stay Current</b><br/>On 's Latest<br/>Developments</a>
</div>
</div>
</div>
<div id="copyright">, 123 MadeupStreet, MadeupTown, MadeupCity, MadeupCountry, MadeupPostcode
<br/>Copyright © 2006 , is a registered trademark of . All Rights Reserved.
</div>

</body>

</html>
----------------------------------------------------------

and a corresponding link page has this code:

----------------------------------------------------------
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title> - rest, relax and recuperate.</title>
<link href="css/layout.css" rel="stylesheet" type="text/css" />

<script language="JavaScript">
<!--

function SymError()
{
return true;
}

window.onerror = SymError;

var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
return (new Object());
}

window.open = SymWinOpen;

//-->
</script>

<script type="text/javascript" src="js/photo.js"></script>
<script type="text/javascript" src="js/utils/AjaxUpdater.js"></script>
<script type="text/javascript" src="js/utils/HTTP.js"></script>
<script type="text/javascript" src="js/utils/Ajax.js"></script>
<script type="text/javascript" src="js/Content.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
<script type="text/javascript">
function initialize()
{
AjaxUpdater.Update("GET", "services/press.xml", Content.display);
}
</script></head>

<body onload="javascript:preloadImages(new Array('img/photos/1.jpg','img/photos/2.jpg', 'img/photos/3.jpg', 'img/photos/4.jpg', 'img/photos/5.jpg', 'img/photos/6.jpg', 'img/photos/7.jpg', 'img/photos/food.png')); initialize(); correctPNG();">

<div id="main">
<div id="header">
<a href="./" id="logo"><img src="img/logo.gif" border="0"/></a>
<div id="navigation">
<div id="navContainer">
<a href="index7958.html?go=what" class="navItem">What Is?</a>
<a href="indexba80.html?go=where" class="navItem">Where Is?</a>
<a href="indexa402.html?go=who" class="navItem">Who Is?</a>
<a href="index7607.html?go=prices" class="navItem">Prices</a>
<a href="index744c.html?go=faqs" class="navItem">FAQs</a>
<a href="indexc35d.html?go=contact" class="navItem">Contact</a>
<a href="index48bb.html?go=press" class="navItem">Press</a>
<a href="index547f.html?go=partners" class="navItem">Partners</a>
</div>
</div>
</div>
<div id="contentContainer">
<div id="gourmet"><img src="img/photos/food.png" border="0"/></div>
<div id="copyContainer"><div id="copy"></div></div><div id="content"><img src="img/bg.jpg"/></div></div>
<div id="footer">
<div id="link"><a href="index7607.html?go=products#GoGourmet"><img src="img/gogourmet.gif" border="0"/></a></div>
<div id="link"><a href="index7607.html?go=products#GoPicnic"><img src="img/gopicnic.gif" border="0"/></a></div>
<div id="link"><a href="index7607.html?go=products#GoSnack"><img src="img/gosnack.gif" border="0"/></a></div>
<div id="link">
<br/><a href="javascript:NewWindow('updates.html', 'FreeUpdates', '350', '200', 'yes');"><b>Stay Current</b><br/>On GoPicnic's Latest<br/>Developments</a>
</div>
</div>
</div>
<div id="copyright">, 123 MadeupStreet, MadeupTown, MadeupCity, MadeupCountry, MadeupPostcode
<br/>Copyright © 2006 , is a registered trademark of . All Rights Reserved.
</div>

</body>
</html>
----------------------------------------------------------

So basically I would like the navigation after implementing php to show:

<div id="main">
<div id="header">
<a href="./" id="logo"><img src="img/logo.gif" border="0"/></a>
<div id="navigation">
<div id="navContainer">
<a href="?go=what" class="navItem">What Is?</a>
<a href="?go=where" class="navItem">Where Is?</a>
<a href="?go=who" class="navItem">Who Is?</a>
<a href="?go=prices" class="navItem">Prices</a>
<a href="?go=faqs" class="navItem">FAQs</a>
<a href="?go=contact" class="navItem">Contact</a>
<a href="?go=press" class="navItem">Press</a>
<a href="?go=partners" class="navItem">Partners</a>
</div>
</div>
</div>

and for the links to go to their specific index.php?go=woteva pages

Any help would be greatly appreciated

Many thanks, Lee
:)

[edited by: jatar_k at 10:10 pm (utc) on Oct. 28, 2006]
[edit reason] no urls thanks [/edit]

loopylee130

12:13 am on Oct 29, 2006 (gmt 0)

10+ Year Member



the site in question is: <snip>

[edited by: dreamcatcher at 8:19 am (utc) on Oct. 29, 2006]
[edit reason] No URLs, thanks. [/edit]

mcibor

5:15 pm on Oct 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is file index.html

<?php
$arr_redirect = array(
"what" => "7958",
"where" => "ba80",
"who" => "a402",
"prices" => "7607",
"faqs" => "744c",
"contact" => "c35d",
"press" => "48bb",
"partners" => "547f",
"products" => "7607"
)

$redirect = "";
if(isset($_GET['go']) $redirect = $arr_redirect[$_GET['go']];

if($redirect)
{
$redirect = "index$redirect.html?go=".$_GET['go'];
header("Location: $redirect");//redirect to desired location
exit;
}//if it's the main index.html or wrong link then don't redirect, but show index.html
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
...

This should work, either with index.php or index.html - with latter you need to enable html files to be parsed with php.

Regards
Michal

PS. Next time try to avoid unnecessary chunks of text, we don't need you whole source code to provide solution.

loopylee130

9:16 am on Oct 30, 2006 (gmt 0)

10+ Year Member



When i add this code i get:

Parse error: parse error, unexpected T_VARIABLE in ..... on line 14

Any further suggestions?

Regards

loopylee130

10:00 am on Oct 30, 2006 (gmt 0)

10+ Year Member



Worked out the problem with code - a missing bracket on line 15:
if(isset($_GET['go'])) $redirect = $arr_redirect[$_GET['go']];

However now when i load the page and then click on one of the hyperlinks i get the following:

Warning: Cannot modify header information - headers already sent by (output started at /usr/local/home/httpd/vhtdocs/somesite.co.uk/GOPICNIC/index.php:1) in /usr/local/home/httpd/vhtdocs/somesite.co.uk/GOPICNIC/index.php on line 20

The culprit code on line 20 being:
header("Location: $redirect");//redirect to desired location

What does this mean please?

Many thanks

[edited by: dreamcatcher at 12:05 pm (utc) on Oct. 30, 2006]
[edit reason] Generalized urls. [/edit]

loopylee130

10:11 am on Oct 30, 2006 (gmt 0)

10+ Year Member



OK...This all works now!
YAY :)

Many thanks to the person who posted the code. I had to tweak it a bit (ie. add a curly bracket and a semicolon and then take away a space at the beginning of the php code on line 1) but now it all works hunky dory!

I am forever in your debt!

Thanks again :) :)

mcibor

10:25 pm on Oct 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No problem.

Take care and have fun with php!

Sorry for the bracket - I just wrote without testing that first.

Function header() sends a header to the browser.
header("Location: [domain.com...]
will redirect you to [domain.com...]

I'm glad that you worked it out on your own. Usually if you post such large text nobody takes his/her time to read through.

Regards
Michal