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 12 of 12
  1. #1
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    confused with *.php?=*

    Hi there,

    I'm a bit confused, on how to create a webpage that uses the 'index.php?=somethinghere' thing?

    What's it called? And how do you use it?
    <? print("Hello World") ?>

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    They're called GET variables.

    PHP provides you with an array called $_GET (it's a superglobal, meaning it's available everywhere and automatically).

    So if you have the URL index.php?value=test.

    Then this:

    PHP Code:
    echo $_GET['value']; 
    Would echo: test

  • #3
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You.

    And how do websites work with let's say

    ...com/index.php?p=home
    ...com/index.php?p=about
    ...com/index.php?p=contact

    etc?

    that is, how do you make a redirection to a certain url depending on the $GET Variable?
    <? print("Hello World") ?>

  • #4
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Those types of sites are usually pulling the information from a database, not redirecting. The index page checks what the value of p is, then retrieves the relevant information from the database. It would be possible to construct a site using this type of URL structure without having a database, but it would be pointless.

    A very simple example:

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

    // (Connect to database)

    mysql_query ("SELECT * FROM table WHERE page = '$page'") or die (mysql_error()); 

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Pennimus View Post
    TIt would be possible to construct a site using this type of URL structure
    .. don't forget its also possible that urls of that structure could be navigating a templating system such as SMARTY of a custome built template system... it can include files and set directorys/themes in the same way it can call information from a database

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,539
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    CodilX ...

    ... and there is also something called "PHP Includes". Includes are often
    used to pull information from other pages, other sites, text files, etc.

    Maybe an example would be easiest to describe ...

    For example, in the site below, there are many text files that the client can
    edit using a really basic text editor. The website is one PHP script (page.php) that
    uses page codes to determine which text file to display (as content). Move
    mouse over links to see what the URL looks like.

    http://www.palosantodesigns.com/

    So, when the PHP script sees p=2 (for example), it knows which text file
    to grab and uses that text file as the content. The navigation (which is
    also a PHP script include), adjust according to that variable also.

    This type of site allows for dozens of pages without static pages. The site owner
    who knows very little about HTML, can go in and edit text files (the content), making
    simple changes, additions, corrections. This requires no fancy databases (no MySQL).
    It's a rather simple, no frills content management, dynamic site.

    EDIT:
    There have been discussions about SEO using PHP variables in URLs ...
    I've never really had a problem with this. Even a search with part of the name,
    which ends up with over one million results ... falls in the first 5 hits:
    http://www.google.com/search?hl=en&s...ns&btnG=Search
    Last edited by mlseim; 05-31-2007 at 02:48 PM.

  • #7
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Re: above posts - you're right of course, although it could be argued that those are essentially primitive forms of databasing. I should have mentioned that using MySQL is just one possible form of storing data for retrieval by a dynamic page.

  • #8
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Maybe, using includes someting like:

    PHP Code:

    <?php
         $page 
    $_GET['p'];
              
              if(
    $page == NULL) {
                        include(
    'home.php');
              } elseif(
    $page == 'contact') {
                       include(
    'contact.php');
             }
    ?>

  • #9
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    It would make more sense (and be more extendable) if you did this:

    PHP Code:
    <?php
    $page 
    $_GET['p'];
    if(
    $page == NULL)
     {
      include(
    'home.php');
     }
    else
     {
      if(
    file_exists("$page.php"))
       {
        include(
    "$page.php");
       }
      else
       {
        include(
    "notfound.php");
       }
     }
    ?>
    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #10
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP Code:
      if(file_exists("$page.php"))
       {
        include(
    "$page.php");
       } 
    If the host has external URLs allowed for fopen then this is a security hole. You need to include some sort of path. Either relative or absolute.

    PHP Code:
    if(file_exists('./' $page '.php')) {
        include(
    './' $page '.php');


  • #11
    New Coder
    Join Date
    Jun 2006
    Location
    eth0
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you sooo much! that's what I was looking for. thank you all
    <? print("Hello World") ?>

  • #12
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Quote Originally Posted by aedrin
    If the host has external URLs allowed for fopen then this is a security hole. You need to include some sort of path. Either relative or absolute.
    ahh. Thanks

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

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