Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts

    What am I looking for ??

    If a PHP site uses a URI like www.example.com/?target, how is that done?

    Back when I started looking into OO PHP, I came across a good video tute series on this specifically, but now that I'm actually looking for it, I'm not finding it.

    Can someone please feed me some keywords or links ?

    ~ Mo

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts

  • #3
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Thanks.
    I think I need to clarify
    (I'm already comfortable with GET)

    The target (if memory serves correctly) was the name of a class, and that was how the website is browsed.
    Instead of having seperate page for the "contact" and "about us" info, it would be
    www.example.com/?contact
    and
    www.example.com/?aboutUs
    respectively.

    ~ Mo

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    This is called passing a variable via $_GET method.

    What happens is that the link may go to index.php?page=aboutus

    Inside the index.php there is an if statement that say that if $_GET['page']==aboutus then show about us content.

    That's the very watered down version.

  • #5
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Oh, your kidding !!
    That's so nice and simple.
    I thought it was something more involved

    Thanks.

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I believe this is what you are looking for.

    PHP Code:
    if (isset($_GET["do"])) {
        
    $do explode(":",$_GET["do"]);

        switch(
    $do[0])
        {
            case 
    'main':
                
    main();
            break;

     }

    Makes this: www.example.com/page.php?do=main
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #7
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    422
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Thanks.

    And, what if I didn't want to display the page name (like found at www.awesomephp.com)?

  • #8
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by mOrloff View Post
    Thanks.

    And, what if I didn't want to display the page name (like found at www.awesomephp.com)?
    That page displays the page name, I prefer to make the GET url descriptive - and bookmarkable, like:

    • index.php?page=about_us
    • index.php?page=products
    • index.php?page=contact_us
    • index.php?forum=4&topic=45789


    Not urls with single letters, like:

    • index.php?p=products
    • index.php?a=56889




    --------------
    Leonard Whistler

  • #9
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    To be honest it's much nicer to have clean URI's using some simple htaccess rewrite rules and some clever coding to load pages up. Something like
    www.example.com/page/about
    looks much nicer than
    www.example.com/?page=about
    in my opinion
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by JAY6390 View Post
    To be honest it's much nicer to have clean URI's using some simple htaccess rewrite rules and some clever coding to load pages up. Something like
    www.example.com/page/about
    looks much nicer than
    www.example.com/?page=about
    in my opinion
    You could also achieve the same outside of using rewrite by using an error handler which loads the requested page content.

    Edit: Why are there always so many methods of achieving the same end?


  •  

    Posting Permissions

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