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
https://forums.phpfreaks.com/topic/182710-help-with-if-page-equals/
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');

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

this is the site i am working on: www.exactmining.com.au/new

 

cant get this... either doesnt show either, or just shows home.php

 

attached is the four files i am using.

 

all that is in middle.php is an image, any help would be so great.

 

[attachment deleted by admin]

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;
    }
?>

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.