Jump to content

PHP Template error on production server but works on localhost?


rahish

Recommended Posts

Hi I am trying to build a php template from the following tutorial  http://www.alistapart.com/articles/phpcms

 

All I want to do is send a variable to another page, something I have done countless times before. It works fine on my local server but I cannot get it to work on my web account. It may have something to do with the way & needs to be encoded but I have corrected that and the page validates as XHTML strict but the file still won't work.

 

Can anyone work out what I am doing wrong?

 

template.php has menu.php as a require and the content loads dynamically when you select a menu item from menu.php the variables are in the url on the menu link.

 

here is template.php

<?php
setcookie ("styleCookie", $style, time()+40000000);
?>

<?php

if ($style == "") {
$style="default";
}
if ($page == "") {
$page="home";
}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="en-us" />

    <title>New CMS Template - Alistapart Tutorial - Managing your content with PHP</title>
    
<?php echo "<style type=\"text/css\" 
media=\"all\">@import 
\"$style.css\";> </style>"; ?>    
    

<?php echo 
"<link rel=\"alternate style sheet\" 
type=\"text/css\" 
href=\"default.css\" title=\"Default\" />"; ?>
</head>

<body>

<?php $_GET['$style'];

	$_GET['$page'];?>

<?php echo "$style";?>
<?php echo "$page";?>
<div class="body">
<?php //@require_once ("header.php");?>

<div class="menu">
<?php @ require_once ("menu.php"); ?>
</div>

<?php @ require_once ("$page.html"); ?>

</div>



</body>
</html>

 

and here is menu.php

 

<?php
$home="Home";
$info="Information";
$contact="Contact Details";
$links="Links";

$default="default";
$blue ="blue";

?>
<ul>
<li><?php echo "<a href=\"template.php?page=home&style=$default\">$home</a>"; 
?></li>
<li><?php echo "<a href=\"template.php?page=info&style=$blue\">$info</a>"; 
?></li>
<li><?php echo "$contact";?></li>
<li><?php echo "$links";?></li>
</ul>

 

the css files just have a background colour defined and the home and info pages are home.html and info.html

 

The link to the template.php which has the error is herehttp://www.undesign.co.uk/computer_club/dynamic_web/PHP/alistapart_tutorials/managing_content_php/template.php?page=home&style=default

Link to comment
Share on other sites

Thanks,

I am not getting an error at all, its just that when you try clicking on info in the list menu, it should send the variables to be picked up by template.php to load a different html file and change the style sheet. As I say this seems to work fine on localhost under xampp but on my web server on the link below it doesn't work. The variable in on the info link should send

 

?page=info&style=blue

 

to template.php

 

I echoed variables $style and $page to template.php and it still shows default and home.

 

The page has a cookie applied also, could it be that it is not updating the information

 

 

 

If you click on the link

 

http://www.undesign.co.uk/computer_club/dynamic_web/PHP/alistapart_tutorials/managing_content_php/template.php?page=home&style=default

 

 

You will see what I mean

 

 

 

 

Link to comment
Share on other sites


change to below code

may be in the server the global variables may be off

if global variables are off you cannt get the get or post variables directly you hv to get it through

$_GET[variable] or $_POST[variable]

 

<?php
setcookie ("styleCookie", $style, time()+40000000);
?>

<?php

if ($_GET[style] == "") {
$style="default";
}
if ($_GET

 == "") {
$page="home";
}

?>

Link to comment
Share on other sites

Thanks

 

Now I am getting

 

Warning: Cannot modify header information - headers already sent by (output started at ******template.php:2) in ******template.php on line 3

 

There is a header redirect in an index.php file, I am wondering if this code should be in template.php

 

<?php



if ($styleCookie == "") {
$style="default";
}
else {
$style=$styleCookie;
}

Header ("Location: template.php?page=home&style=$style");

?>

 

Link to comment
Share on other sites

add  ob_start(); in line one of index.php

 

and i dont know why you are using header redirect in index.php

 

<?php
ob_start();


if ($styleCookie == "") {
$style="default";
}
else {
$style=$styleCookie;
}

Header ("Location: template.php?page=home&style=$style");

?>

Link to comment
Share on other sites

Thanks

 

Because the tutorial says so, I am starting to think this tutorial was a bad idea.

 

The code in index.php just redirects to template php with headers but also sets the css to default if no other variables are passed via the browser.

 

Why does it come up with header errors when you go directly to template.php there is no header info in this page in the first place?

 

 

Link to comment
Share on other sites


Thanks for that,

 

That removed the header error. It still didn't work but I noticed the reason why.

 

Although as was suggested earlier in this post that

 

<?php

if ($_GET[style] == "") {
$style="default";
}
if ($_GET

 == "") {
$page="home";
}

?>

 

was needed

 

It also needs

 

<?php $style = $_GET['style'];

	$page= $_GET['page'];

	?>

 

Now it works, thanks a lot.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.