rahish Posted March 26, 2008 Share Posted March 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/ Share on other sites More sharing options...
Cep Posted March 26, 2008 Share Posted March 26, 2008 What is the error your getting? Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501074 Share on other sites More sharing options...
rahish Posted March 26, 2008 Author Share Posted March 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501100 Share on other sites More sharing options...
ansarka Posted March 26, 2008 Share Posted March 26, 2008 plz check this line <body> <?php $_GET['$style']; $_GET['$page'];?> this should be like <body> <?php $_GET['style']; $_GET['page'];?> Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501107 Share on other sites More sharing options...
rahish Posted March 26, 2008 Author Share Posted March 26, 2008 Thanks, I have done that but it didn't change anything. Is it that if ($style == "") { $style="default"; } if ($page == "") { $page="home"; } is overriding the $_GET part? Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501122 Share on other sites More sharing options...
ansarka Posted March 26, 2008 Share Posted March 26, 2008 Previous Page Next Page 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"; } ?> Previous Page Next Page Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501125 Share on other sites More sharing options...
rahish Posted March 26, 2008 Author Share Posted March 26, 2008 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501159 Share on other sites More sharing options...
ansarka Posted March 26, 2008 Share Posted March 26, 2008 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501165 Share on other sites More sharing options...
rahish Posted March 26, 2008 Author Share Posted March 26, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501173 Share on other sites More sharing options...
rahish Posted March 26, 2008 Author Share Posted March 26, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501353 Share on other sites More sharing options...
BlueSkyIS Posted March 26, 2008 Share Posted March 26, 2008 latest code for index.php? Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501367 Share on other sites More sharing options...
rahish Posted March 26, 2008 Author Share Posted March 26, 2008 Sorry, yes here it is <?php ob_start(); if ($styleCookie == "") { $style="default"; } else { $style=$styleCookie; } Header ("Location: template.php?page=home&style=$style"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501496 Share on other sites More sharing options...
rahish Posted March 27, 2008 Author Share Posted March 27, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-501998 Share on other sites More sharing options...
ansarka Posted March 27, 2008 Share Posted March 27, 2008 in template.php add ob_start(); in line number one <?php ob_start(); setcookie ("styleCookie", $style, time()+40000000); ?> ;) ;) Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-502030 Share on other sites More sharing options...
rahish Posted March 27, 2008 Author Share Posted March 27, 2008 Previous Page Next Page 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. Previous Page Next Page Quote Link to comment https://forums.phpfreaks.com/topic/97939-php-template-error-on-production-server-but-works-on-localhost/#findComment-502600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.