+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: How does facebook do this?

  1. #1
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    How does facebook do this?

    It first started with this: http://forums.x10hosting.com/program...cebook-do.html

    Misson was able to show me how to do it using isset(), but making a new if statement for each 'parameter' was very tiring and confusing. But misson also mentioned using array_keys()

    I tried this out:
    PHP Code:
    print_r(array_keys($_REQUEST)); 
    and got this
    Code:
    Array (     [0] => compose [1] => account_php?compose     [2] => start )
    so I tried calling upon, $_REQUEST[0], but that did nothing.

    So does anyone have a solution that I can use that I would not need to make a new if statement for each parameter?

  2. #2
    Gouri's Avatar
    Gouri is offline Community Paragon Gouri has a brilliant futureGouri has a brilliant futureGouri has a brilliant future
    Join Date
    Oct 2007
    Location
    India
    Posts
    4,502

    Re: How does facebook do this?

    I think you have to use $_GET(REQUEST_URI)

    and use explode to get string by string.

    As registered globals are off.
    Last edited by Gouri; 12-09-2009 at 03:36 PM.
    If you feel my post is useful then click to give Reputation (bottom left corner of this post)

    X10 Hosting | News and Announcements | Premium Hosting | VPS Hosting | Prime Membership

    Tech Community | Gouri

  3. #3
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: How does facebook do this?

    Exactly what do you want to do?

  4. #4
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How does facebook do this?

    http://www.facebook.com/inbox/?compose&ref=mb
    how does FB pass "compose" in php?
    because the variable compose is not set to anything.

    misson showed me how to do it using isset(), but that would mean I would have to create a new if statement for each one I want to pass. I want a way so that I can just find out what its looking for and include the necessary files for it.

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: How does facebook do this?

    PHP Code:
       # legal options
    $permitted = array( 'compose' 'destroy''giggle''whistle' );
       
    # all options sent
    $submitted array_keys$_GET ) ;
       
    # legal options sent
    $ok_submitted array_intersect$permitted $submitted ) ;

    foreach( 
    $ok_submitted as $option ){

      
    // Do something with $option


  6. #6
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How does facebook do this?

    Quote Originally Posted by descalzo View Post
    PHP Code:
       # legal options
    $permitted = array( 'compose' 'destroy''giggle''whistle' );
       
    # all options sent
    $submitted array_keys$_GET ) ;
       
    # legal options sent
    $ok_submitted array_intersect$permitted $submitted ) ;

    foreach( 
    $ok_submitted as $option ){

      
    // Do something with $option

    thank you!

    another thing popped up. what happens if some sob comes and tries to use:
    site.php?calendar&staff

    I need a fail-safe so that it only executes the first command. but as far as i know foreach does not have a way to stop it, unlike while().

  7. #7
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: How does facebook do this?

    Quote Originally Posted by diabolo View Post
    thank you!

    another thing popped up. what happens if some sob comes and tries to use:
    site.php?calendar&staff

    I need a fail-safe so that it only executes the first command. but as far as i know foreach does not have a way to stop it, unlike while().
    If you want just one option executed:

    PHP Code:
       # legal options
    $permitted = array( 'compose' 'destroy''giggle''whistle' );
       
    # all options sent
    $submitted array_keys$_GET ) ;
       
    # legal options sent
    $ok_submitted array_intersect$permitted $submitted ) ;
     
    ## INSERT A TEST TO MAKE SURE AT LEAST ONE OPTION
     
    foreach( $ok_submitted as $option ){
     
      
    // Do something with $option
     
      
    break ;  # STOP AFTER ONE

    Does not guarantee which will be executed.

    If you list the options in order you want to perform, then something like


    PHP Code:
       # legal options
    $permitted = array( 'compose' 'destroy''giggle''whistle' );
       
    # all options sent
    $submitted array_keys$_GET ) ;
       
    # legal options sent
     
    $found_option false ;
     
    foreach( 
    $permitted as $option ){
     
        if( 
    in_array(  $option $submitted ) ){
            
    # DO SOMETHING WITH $option
            
    $found_option true ;
            break;
        }
     

     
    # HANDLE CASE WHERE $found_option is false 

  8. #8
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How does facebook do this?

    thank again

    PHP Code:
    # legal options
    $permitted = array( 'compose' 'destroy''giggle''whistle' );
       
    # all options sent
    $submitted array_keys$_GET ) ;
       
    # legal options sent
    $ok_submitted array_intersect$permitted $submitted ) ;
     
    $numOptionSel count($ok_submitted);
    if(
    $numOptionSel == 1) {
       foreach(
    $ok_submitted as $option) {
       echo 
    $option;
       }
       echo 
    'working...';
    } else {
       echo 
    'Stop messing around with my script!';

    I just need to add some more fail-safes and errors, but thank you for your help
    +REP

  9. #9
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: How does facebook do this?

    Also, provide a default option that is displayed when no option is specified.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

  10. #10
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How does facebook do this?

    Quote Originally Posted by xav0989 View Post
    Also, provide a default option that is displayed when no option is specified.
    good point.
    this is what I got
    PHP Code:
    # legal options 
    $permitted = array( 'compose' 'destroy''giggle''whistle' ); 
       
    # all options sent 
    $submitted array_keys$_GET ) ; 
       
    # legal options sent 
    $ok_submitted array_intersect$permitted $submitted ) ; 
      
    $numOptionSel count($ok_submitted); 
    if(
    $numOptionSel == 1) { 
       foreach(
    $ok_submitted as $option) { 
       echo 
    $option
       } 
       echo 
    'working...'
    } elseif(
    $numOptionSel == 0) {
       
    # if $submitted is not in $permitted
       
    echo 'Invalid Error Performed.';
    } else { 
       echo 
    'Stop messing around with my script!'

    how would I add a if statement for no parameter being passed?
    right now, "} elseif($numOptionSel == 0) {" is picking it up

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 27
    Last Post: 01-17-2010, 06:00 PM
  2. Xbox 360 - Facebook, Twitter, Last.Fm, Zune Movies
    By Zenax in forum Gamer's Lounge
    Replies: 10
    Last Post: 11-22-2009, 08:50 PM
  3. Anyone here uses Facebook?
    By TPI007 in forum Off Topic
    Replies: 5
    Last Post: 02-22-2009, 06:21 PM
  4. Review my Facebook Connectable Gaming Community
    By TPI007 in forum Review My Site
    Replies: 0
    Last Post: 02-22-2009, 05:17 PM
  5. Your Facebook
    By Brandon in forum Off Topic
    Replies: 4
    Last Post: 11-28-2007, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers