Jump to content

help with if page equals


Exact

Recommended Posts

Ok guys, i am only good with the basics, sorry if i come off stupid :)

 

I want to write on this file if page is equal to home.php show middle.php, if it equals any other page do not show middle.php

 

this is the body where i want to write it:

  <tr>

    <td><?php include("middle.php"); ?></td>

  </tr>

  <tr>

    <td><?php include("bottom.php"); ?></td>

  </tr>

bottom.php is where the default page loads. so in lamens terms i want to say show middle.php on the home page and dont show it anywhere else

 

 

ANY help would be soooo appreciated!! :)

Link to comment
Share on other sites

This might be helpful

<?php
    function page($name){
        $uri = basename($_SERVER['REQUEST_URI']);
        if(strpos($uri, '?') !== false)
            $uri = reset(explode('?', $uri));
        return $page == $uri ? true : false;
    }
?>

 

And then to use it just do

 

if(page('home.php'))

    include('middle.php');

Link to comment
Share on other sites

this is much easier

if($_SERVER[sCRIPT_NAME] == "/home.php){include (middle.php);}

or

 

if($_SERVER[sCRIPT_NAME] == "/anydirectory/home.php){include (middle.php);}

if you were on yoursite.com/home.php echoing that server variable script name outputs: /home.php

and if theres a string on the end.. like

site.com/home.php?blah=blah3983&a=1

it will still output : /home.php

Link to comment
Share on other sites

Sorry, the reason my function didn't work was because I unknowingly changed a variable-name in the middle of a function...

 

Try this function, instead, I should work:

<?php
    function page($name){
        $uri = basename($_SERVER['REQUEST_URI']);
        if(strpos($uri, '?') !== false)
            $uri = reset(explode('?', $uri));
        return $name == $uri ? true : false;
    }
?>

Link to comment
Share on other sites

  • 2 weeks later...
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.