Page 1 of 4 123 ... LastLast
Results 1 to 10 of 37

Thread: URLS like: index.php?page=page1 ???

  1. #1
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default URLS like: index.php?page=page1 ???

    I have links on my page, but instead of linking to pages like:
    Code:
    <a href="guestbook.php">Guestbook</a>
    I would like to have

    Code:
    <a href="?page=1">Guestbook</a>
    How can I do this?
    - Mike

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mburt
    ... instead of linking to pages like:
    Code:
    <a href="guestbook.php">Guestbook</a>
    I would like to have

    Code:
    <a href="?page=1">Guestbook</a>
    How can I do this?
    Uh, why would you want to do that? URLs should be transcribable and easy to remember. Ideally, the query string should be used only to modify details about a particular document, not choose the document itself.

    Jakob Nielsen has a few guidelines regarding URIs and their importance as a UI feature, sentiments that are echoed elsewhere.

    What exactly makes you think this will be a good idea, either for visitors or yourself?

    Mike

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    It leaves off the extension, possibly making it easier to navigate.
    - Mike

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    So how could I do this?
    - Mike

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So then why don't you aim for URIs like:

    &#160;&#160;http://www.example.com/guestbook

    Still no "extension", but no unnecessary query string silliness.

    I've discussed how to implement extension-less URIs in the past - you even participated in one thread.

    Mike

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I've read that post, I couldn't understand it.
    Code:
    So then why don't you aim for URIs like:
    
      http://www.example.com/guestbook
    I would... but I don't know how. What's a URI?
    - Mike

  7. #7
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If I understood well, you want to use links that have that "?" in the end, like "<a href="login.php?user=username">Login</a>". Well, here's an example:

    index.html
    Code:
    <?
    $user = $_POST[user];
    if(user != NULL)
    {
    header("Location: members.php?user=$user");
    }
    ?>
    ....
    <body>
    <form action="<? echo $_SERVER['PHP_SELF'];?>" method="post">
    Username: <input type="text" name="user">
    <br><br><input type="submit" value="Login">
    </form>
    </body>
    members.php
    Code:
    <?
    $user = $_GET[user];  // you MUST use the "get" method
    if($user == "costas")  // then verify it
    echo "Welcome oh COSTAS!!";
    else
    echo "You are an unauthorized User!";
    ?>
    This is a very simple example, but I hope you understand how it works. If you want a bit bigger and more complex example, I could give you one I've made!!

    Hope I helped!!!

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The easiest way to do this is to construct a query-string mechanism as you describe here, then use mod_rewrite or equivalent to map /guestbook to /?page=1.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Okay.. I think I get it now. Thanks Mwinter, Twey, and costas. PHP is awesome...
    - Mike

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You could, if you're just looking for a nice feel to the url, use page.php?guestbook

    Then split the string of the url to work.
    PHP Code:
    list($addr,$page) = explode($_SERVER['REQUEST_URI'],"?",2);
    //set the two variables equal to the parts of: URI split at ?, limited to 2 chunks.
    echo $page;
    //that's "guestbook", etc. 
    This isn't necessarily a great idea, but it might help. If you want simplicity and a single php page as the basis for navigation, could work well.

    Note, though, that a major problem is that you can't use GET variables after this. If you wanted to specify something else with the URI, then the & would have to be there, and it would get messy, as that would be in the $page string as well.
    You could do some fancy coding, but it would just be a pain.
    In that case, you should definitely use ?page=.... instead. It would also make it clearer when making the URLs.
    One ?.... value is easy, but after that, using the normal syntax is much clearer.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •