Dynamic URLs

Discussion in 'PHP' started by W3C, Dec 27, 2006.

  1. W3C

    W3C New Member

    Joined:
    Nov 24, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    I have been trying to get pages that the address are:

    example.com/forum/forum.php?t=3

    I have been looking at tutorials and I have found stuff, but I don't quite get how it works and where to put the code that executes to make dynamic URLs.

    Help or other tutorials would be great.
    Thanks in advance,
    W3C
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Your forum.php script which is a PHP script should take into consideration the parameter passed (t=3) and should display the results based on the condition specified.
     
  3. W3C

    W3C New Member

    Joined:
    Nov 24, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Sorry I put a wrong example. Here is a better one:

    example.com/index.php?page=browse

    How would this code look to have an outcome of this address? Would it be just the '<a>' tag with the attibute of 'href="index.php?page=browse"', or how would you get a link to do that?
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I am not able to get what you are asking. The parameter name and value will not make much of a difference provided it has been handled in the script. In the second example the script is index.php.
     
  5. W3C

    W3C New Member

    Joined:
    Nov 24, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    What I want to know is how to get a link like a browse file and when clicked on have the address be:

    example.com/index.php?page=browse

    Example:
    A site has home, browse, community, and contact us links. I want to know when the links are clicked on the address is:
    browse = example.com/index.php?page=browse
    community = example.com/index.php?page=community
    contact us = example.com/index.php?page=contact_us

    Is there a special code to execute that?
     
  6. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Are you suggesting that you want to include the files according to the parameter that is passed?? If that is what you want to do, that's very much possible to do.
     
  7. W3C

    W3C New Member

    Joined:
    Nov 24, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Yes that is what I want. Do you have a code that I may use?
     
  8. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    That's is very simple, all you would need to do is to use a switch statement.
    Here is a sample code,

    PHP:
    $page $_GET['page'];

    switch(
    $page)
    {
        case 
    'browse':
            include(
    'browse.php');
            break;
        case 
    'contact_us':
            include(
    'contact_us.php');
            break;
    }
     
  9. W3C

    W3C New Member

    Joined:
    Nov 24, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for the code.
    But what I don't really quite get is where to insert the code and how it works with links.
     
  10. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Insert the code in index.php, the logic is that according to the page parameter's value appropriate file is included and it's contents are executed, which as a result will change the output according to the parameter passed.
     
  11. W3C

    W3C New Member

    Joined:
    Nov 24, 2006
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    Oh okay I get it now. Thank you for all you help guys. And thanks for the code.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice