jp612 Posted January 5, 2011 Report Share Posted January 5, 2011 For some strange reason one of my php if statements isnt working for opera. Which is odd since the browser has nothing to do with the php right? this is my index.php: <?php session_start(); ?> <!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> <title> <?php if($_GET['page'] == "design") { echo "Website Design Services - Affordable Website Design | Debes Design"; }else if($_GET['page'] == "graphic") { echo "Graphic Design Services - Affordable Graphic Website Design | Debes Design"; }else if($_GET['page'] == "contact") { echo "Contact Us - Place An Enquiry About A Website | Debes Design"; }else if($_GET['page'] == "about") { echo "About Us"; }else{ echo "Web Design Services - Effective And Affordable Websites | Debes Design"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="We provide affordable web and graphic design solutions for our customers - Debes Design" /> <meta name="keywords" content="Debes Design,website,business,webpage,design,services,graphic,CMS,content management system,affordable,effective" /> <link href="css/style.css" rel="stylesheet" type="text/css" /> <?php $include_home = "include(\"includes/home.php\")"; if($include_home) echo "<link href=\"css/home.css\" rel=\"stylesheet\" type=\"text/css\" />"; ?> <!--[if lt IE 8]> <link rel="stylesheet" type="text/css" href="css/ie7.css" /> <![endif]--> </head> <body> <div id="page-wrapper"> <div id="header-wrapper"> <div id="header"> <div id="logo"> <a href="index.php?page=home"><img src="images/debes-logo.png" width="210" height="88" alt="Debes Web Design Logo"/></a> </div> <div id="navbar"> <ul> <li> <a href='index.php?page=home'>Home</a> </li> <li> <a href='index.php?page=design'>Web Design</a> </li> <li> <a href='index.php?page=graphic'>Graphic Design</a> </li> <li> <a href='index.php?page=contact'>Contact</a> </li> <!-- <li> <a href='index.php?page=about'>About</a> </li> --> </ul> </div> </div> </div> <div id="content-push"> <?php if($_GET['page'] == "design") { include("includes/design.html"); }else if($_GET['page'] == "graphic") { include("includes/graphic.html"); }else if($_GET['page'] == "contact") { include("includes/contact.php"); }else if($_GET['page'] == "about") { include("includes/about.html"); }else if($_GET['page'] == "redirect") { include("includes/re-direct.php"); }else{ include("includes/home.php"); } ?> </div> <div id="push"></div> </div> <div id="footer"> <div id="footer-content"> <a href="https://www.paypal.com/verified/pal=info@debesdesign.com"><img id="paypal" src="images/icons/Paypal-Verified-CC.png" alt="Paypal Verified" /></a> <p>© debesdesign.com 2010</p> </div> </div> </body> </html> What i have is a css file that i only want attached when my home.php or default index.php include is included. So I created a php statement in my index.php: <?php $include_home = "include(\"includes/home.php\")"; if($include_home) echo "<link href=\"css/home.css\" rel=\"stylesheet\" type=\"text/css\" />"; ?> It does the trick in firefox and chrome and IE (I think) but not in Opera. In Opera the home.css is always attached which creates difficulties. Should i be doing this another way? Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 5, 2011 Report Share Posted January 5, 2011 Basically, you are setting $include_home to a string, and then testing if it is true. According to your code above, it should always return true, since it always holds a value. I would think that the CSS file would be included every time, in all browsers, but I really can't test this easily and you haven't provided a live link. I would approach this slightly differently, by checking for the page variable in the url: <?php if(isset($_GET['page']) == FALSE || $_GET['page'] == 'home') echo "<link href=\"css/home.css\" rel=\"stylesheet\" type=\"text/css\" />"; ?> One other idea to consider is perhaps adding a class to the <body> tag based on the page (this snippet replaces the <body> tag): <?php if(isset($_GET['page']) { echo '<body class="page-' . htmlentities($_GET['page'], ENT_QUOTES) . '">'; // I use htmlentities to clean the input, just in case }else{ echo '<body class="home">'; } ?> Then you shouldn't need a separate CSS file just for the home page - you can use one CSS file and specify your CSS changes since there is a "home" class on the body tag. Quote Link to comment Share on other sites More sharing options...
jp612 Posted January 5, 2011 Author Report Share Posted January 5, 2011 (edited) Oh i see. So my command didn't really do anything accept always echo the command. Oh well I put in this: <?php if(isset($_GET['page']) == FALSE || $_GET['page'] == 'home') echo "<link href=\"css/home.css\" rel=\"stylesheet\" type=\"text/css\" />"; ?> which basically says: if the $_GET['page'] function isn't being executed OR if it is and its getting the page 'home'. Then echo my css link? It works, great! Edited January 5, 2011 by jp612 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted January 5, 2011 Report Share Posted January 5, 2011 which basically says: if the $_GET['page'] function isn't being executed OR if it is and its getting the page 'home'. Then echo my css link? Correct. More specifically, if the $page variable isn't set in the URL, or the $page variable equals "home", then echo the CSS link. Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.