[URL] If url contains ...... include("file.php");

Discussion in 'PHP' started by fi3h3r, Aug 9, 2010.

  1. #1
    WEll basically title says it all i need something that i can put on my menu bar but because it is global i want it so if the url has /admincp in it it include_once("menubar.php");


    COuld someone help please thanks :D
     
    fi3h3r, Aug 9, 2010 IP
  2. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #2
    try this:
    
    if (eregi("admincp",$_SERVER[REQUEST_URI]))
    include_once("menubar.php");
    else
    { 
    .....///ur code
    }
    
    PHP:
     
    arpit13, Aug 9, 2010 IP
  3. fi3h3r

    fi3h3r Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks :p
    m2s
     
    fi3h3r, Aug 9, 2010 IP
  4. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #4
    seems like i had some mistake u shud not have any else statement.
     
    arpit13, Aug 9, 2010 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    First, eregi() is a deprecated function and should not be used... ever again.

    Second, if I added the word "admincp" to the query string like this: example.com/index.php?admincp

    ... it would still include the file.
     
    nico_swd, Aug 9, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    <?php
    if (preg_match('~^/admincp$~', $_SERVER['REQUEST_URI'])) {
    include_once("menubar.php");
    }
    ?>
    PHP:
    That would be placed within /admincp/index.php
     
    danx10, Aug 9, 2010 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    
    if (strpos($_SERVER['REQUEST_URL'], '/admincp') === 0)
        include 'menubar.php';
    
    PHP:
    Although, to be honest, I'd do it differently. I'd define a constant within the admin area, and then check for that instead.

    
    if (defined('IN_ADMINCP'))
        include 'menubar.php';
    
    PHP:
     
    nico_swd, Aug 10, 2010 IP