Shijil T Shijil T - 1 year ago 124
PHP Question

Disable a php code only in homepage

I want to add a php code in my CMS site's header, but dont want to run it in homepage. Because it causes errors!!

already tried this code, but it somehow still runs the code and shows error

$homepage = "/";
$currentpage = $_SERVER['REQUEST_URI'];
if($homepage==$currentpage) {

It is not an error, if the php code run in the home page header , it will call for a database query, which the home page is not assigned to work for. I am trying to add an additional feature.

Error page

this is the code


$item = the_item();
$imgsd = 'store_avatar( ( !empty( $item->image2 ) ? $item->image2 : store_avatar( $item->store_img ) ) )';


Answer Source

Try something more like this (might work):

    $homepage = array("/","/index.html","/index.php");
    $currentpage = strtolower($_SERVER['REQUEST_URI']);
    if(!in_array($currentpage, $homepage)) {    
        //Code goes here

P.S. : Try to ALWAYS indent your code especially when you post on the internet.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download