Getting a user to enter part of a URL, then directing them to the full URL ... ?

Discussion in 'PHP' started by netro1, Jul 28, 2010.

  1. #1
    I am fairly new to PHP so this might not make sense to some people, but here it goes....

    I am wanting to make a script where a user enters their username of a website, which will then display their profile - e.g. www.website.com/username

    Let me use Facebook as an example, this is what I want to do:

    Please enter your Facebook profile name:
    
    [entry box]bob2010[/entry box] [SUBMIT BUTTON]
    Code (markup):
    Upon the user entering their facebook profile username, I want the page to bring up http://www.facebook.com/bob99 - maybe in an iframe or something, so that they remain on my website.

    This isn't precisely what I want to do, but this is easier to explain - and hopefully any answers you have for me will help!

    What I actually want to do is link to http://www.website.com/[user name entered by visitor]/the-rest-of-the-url

    Thanks
     
    netro1, Jul 28, 2010 IP
  2. Zeh.

    Zeh. Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    With:
    <form action="script.php" method="post"><input type="text" name="username" /><input type="submit" /></form>
    HTML:
    And:
    <?php
    if(isset($_POST['username'])) {
        $url = 'http://www.website.com/' . urlencode($_POST['username']) . '/the-rest-of-the-url';
        header('Location: ' . $url); // This redirects
    }
    ?>
    PHP:
    Maybe?

    Regards.
     
    Zeh., Jul 28, 2010 IP
  3. netro1

    netro1 Peon

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks - this is kind of what I mean :)

    However, I want the script to display information on the page, independent of the other site.

    So, sticking with our facebook example, instead of just redirecting to the profile page of the user name submitted, how can I get the script to scan the profile page for other user profiles, and display it in a table?

    For example, say on facebook, I want to gather the profiles of everyone who has written on my wall, how can my script scan the http://www.facebook.com/bob99 profile page, and display all the other users who has written on his wall in a list?

    The common URL would be:

    http://www.facebook.com/profile.php?id=99999999 - for example
     
    netro1, Jul 28, 2010 IP
  4. Zeh.

    Zeh. Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's much more advanced.

    You need to use file_get_contents() or cURL to get the source of the page and grab the data using regex.
     
    Zeh., Jul 28, 2010 IP
  5. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #5
    I think you would definately want to use an iframe for this. Don't think that getting the contents of the page will do you any good since it would cause problems any time there is a local reference.

    Iframe's are fairly simple to use too:
    http://www.w3schools.com/tags/tag_iframe.asp
     
    Thorlax402, Jul 29, 2010 IP