How does www.mysite.com/index.php?affid=48553 work?

Discussion in 'PHP' started by circuitnotes, Dec 10, 2008.

  1. #1
    Im trying to build a website in which there are different landing pages depending on the ?affid=XXXX (i dont know whats that called). For example i want www.funstuff.com/index.php?page=fartjokes go to the "fart jokes" landing page, and the www.funstuff.com/index.php?page=nipplerings go to the "nipple rings" page. Can someone please tell me where to start, Thanks!

    And how will this affect my SEO? Does google see this as bad?
    Thanks!
     
    circuitnotes, Dec 10, 2008 IP
  2. !Unreal

    !Unreal Well-Known Member

    Messages:
    1,671
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    165
    #2
    !Unreal, Dec 10, 2008 IP
  3. kb0000

    kb0000 Peon

    Messages:
    6
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have posted this code on my site some time ago. Below is the link and u can check it out.
    Hope it helps.
    http://scripts.webpany.com/index1.php?page=ctg/tutorials/basics/index&%20tutorialcod=1
     
    kb0000, Dec 10, 2008 IP
  4. circuitnotes

    circuitnotes Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So lets see if i got this....
    If this is the link
    mysite.com/index.php?page=about
    then the php script will actually include the about.php file inside the index.php page?
     
    circuitnotes, Dec 10, 2008 IP
  5. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You do this using $_GET most often. It can be done with $_REQUEST too, but avoid using that. Basically, you would check if $_GET['affid'] was set and if so process the data.

    if(isset($_GET['affid'])){
    $affid = intval($_GET['affid']);
    // Do whatever now
    }

    Most often when I check for $_GET, I use a switch statement...

    switch($affid){
    case '1':
    // Do something if the affid was 1
    break;
    }

    Or along those lines. If you want to include certain pages based upon this, then you will want to perform extra checks. If a user supplies ../../some_folder, for example, you may be opening a file from deep within the server that you really don't want them to see. You can use strpos to check for ../ in the string, or strtr or str_replace to strip those characters out automatically before processing or including any pages.

    You will also want to take special care before using it in a query, but if its set as intval ( if you expect only integers ) then you shouldn't have to worry. Run mysql_real_escape_string against anything that isn't and you should also run addcslashes to strip out % sign as well ( and depending upon your app, the underscore too ).
     
    xxKillswitch, Dec 10, 2008 IP
  6. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Yeah, you can use it to include other pages on your site. They all do run through one page so it assists in some matters such as only having one page to edit for a template.

    For example: (untested)
    <?php
    
    $pages = array('home', 'about', 'faq', 'contact');
    $page = preg_replace('/[^a-z0-9]/i', '', $_GET['page']);
    
    if ( in_array($page, $pages) )
    {
      include('pages/'.$page.'.php');
    }
    else
    {
      include('pages/index.php');
    }
    
    ?>
    PHP:
     
    chopsticks, Dec 11, 2008 IP
  7. circuitnotes

    circuitnotes Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you all, that's great help!
    I have another question about this... I own a website that has a simple form on the index page, if a visitor fill out the form the information goes out to all 50 of my clients, however i also want the option for my clients to display a link on their personal website that will direct their visitor to my form but the form information will solely go back to that ONE client.
    Would the URL variable be a good option to start on this?
     
    circuitnotes, Dec 11, 2008 IP
  8. brownskinman

    brownskinman Peon

    Messages:
    18
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    IMHO, this is a bad practice. Use at your own risk.

     
    brownskinman, Dec 11, 2008 IP
  9. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ah there's nothing wrong with using such a technique, escpecially if your site isn't that dynamic. You just gotta be sure you've checked and processed the data supplied very well, or it can lead to some nasty stuff happening. I've visited sites that use similar methods, but didn't check as well and just by entering index.php/page=../index I've reloaded their index over and over and over. Sometimes you can also recurse into directories outside of the server root and display things you really don't want displayed ( such as password files, etc ).

    @curcuit, I don't think I quite understand what you are trying to do? Can you describe it alittle more in detail?
     
    xxKillswitch, Dec 11, 2008 IP
  10. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #10
    Reasons?

    The best way IMO would really be to use some sort of central entry point to use an Model View Controller. Parse the requested URL to get the module, controller and specified action. That would be the most desireable way, but using something as I posted is suited to smaller applications and works fine.

    There isn't really any security issues with what I posted as data is filtered twice, so nothing that shouldn't be included can be included.

    If you can show a better practise, please do so, I want to see.
     
    chopsticks, Dec 11, 2008 IP