SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Load PHP includes depending on url

    Hi

    I'm trying to load php includes if on a certain url. This is the code I'm trying to use, but I'm not sure what I'm doing wrong.


    PHP Code:
    <?php
            
    if ($_GET['url'] == "/cart/") {
            include (
    "includes/cart.inc.php");
            } else {
            include (
    "includes/checkout.inc.php");
            }
            
    ?>

    Would really appreciate some help.
    Thanks

  2. #2
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by leanda View Post
    Hi

    I'm trying to load php includes if on a certain url. This is the code I'm trying to use, but I'm not sure what I'm doing wrong.


    PHP Code:
    <?php
            
    if ($_GET['url'] == "/cart/") {
            include (
    "includes/cart.inc.php");
            } else {
            include (
    "includes/checkout.inc.php");
            }
            
    ?>

    Would really appreciate some help.
    Thanks

    AN example of the url could help us

    But I think you used too much slashes:



    PHP Code:
    <?php
        
    if ($_GET['url'] == "cart") {
        require_once 
    "includes/cart.inc.php";
        } else {
        require_once 
    "includes/checkout.inc.php";
        }
    ?>

    since you don't do any checks to see if the files exist, I would recomend using require over include. and to make sure the parser doesn't read the same file twice, I used require_once
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  3. #3
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but I'm afraid that didn't work. New to the forum so I can't post urls yet.

    The second half of the code is working, but not the first part.

    Just can't get my head around it, I'm new to PHP :-(

    Thanks for the help.

  4. #4
    messing with my mind fristi's Avatar
    Join Date
    Feb 2009
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by leanda View Post
    Thanks, but I'm afraid that didn't work. New to the forum so I can't post urls yet.

    The second half of the code is working, but not the first part.

    Just can't get my head around it, I'm new to PHP :-(

    Thanks for the help.
    We really need some more information. Can't you find a way to post an url? even part of it?
    To PHP or to Perl, that is the question!
    (Bucket - simpletest) User

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post the bit from ?url= onwards

  6. #6
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    When you say a different url, you mean the entire url

    http://www.yoursite.com/abc/xyz

    Rather than a get variable called 'url'

    http://www.yoursite.com/abc.php?url=xyz?

    I think you need to be doing some stuff with the $_SERVER array

    Run this, and then you'll be able to see some of the values you can check against.

    PHP Code:
    print_r($_SERVER
    I imagine you might want to be doing this
    PHP Code:
     if ($_SERVER['REQUEST_URI'] == "/cart/") { 
            include (
    "includes/cart.inc.php"); 
            } else { 
            include (
    "includes/checkout.inc.php"); 
            } 


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •