Login To My MySpace Account Via PHP Script?!

Discussion in 'PHP' started by bloggy, May 31, 2006.

  1. #1
    Hi there!

    I tried to write a script which can login to my myspace account via php using the snoopy php class for form submission. But the login fails ... I guess it has something to do with cookies which I can not accept via my php script. My script works with several other websites which don't require or use cookies for the login action ...

    Maybe somebody can give me a tip or tell me how I can login to my myspace account using a php script?!

    Thanks in advance
     
    bloggy, May 31, 2006 IP
  2. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #2
    disgust, May 31, 2006 IP
  3. blueoceanwave

    blueoceanwave Peon

    Messages:
    210
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you could probably get a rentacoder.com to do it for cheap
     
    blueoceanwave, May 31, 2006 IP
  4. yugu

    yugu Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have the script.
    Everyone interested send PMs.
     
    yugu, Jun 13, 2006 IP
  5. bloggy

    bloggy Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Have a very nice script now, too. Let me know if you need such a script. PM please. :)
     
    bloggy, Jun 13, 2006 IP
  6. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Forget the PM's...why not just post it?

    Bobby
     
    Chemo, Jun 14, 2006 IP
  7. bloggy

    bloggy Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here is a screenshot:

    [​IMG]
     
    bloggy, Jun 16, 2006 IP
  8. tobes

    tobes Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Here's what I just recently finished today. I run a train on MySpace and I needed a way for my riders to submit their "proofs" (bulletin URLs), have a PHP script check them, and automatically update a roster so that people on the train appear according to the number of times they've posted the train.
    Grabbing the page contents of bulletin URLs seemed easy, but actually requires an active login on MySpace's homepage in order to view them, so below is a portion of the code I use that deals specifically with logging into myspace and fetching the contents of a specified page. Anyone can obviously edit it as needed for their own purposes.

    Notes:
    I created a blank file, cookie.txt before I began using this script and CHMODed it to 777.

    
    <?php
    //PHP5
    //Purpose: Sign in to MySpace with specified account information.
    //Retreive page contents from a specified page that would otherwise
    //be unaccessible without a valid login first.
    
    
    $file = fopen("cookie.txt", "w+"); fclose($file);
    //Flush contents from cookie file before beginning.
    
    $url1 = "http://collect.myspace.com/index.cfm?fuseaction=login.process";
    //Set MySpace's main login form action.
    
    $url2 = "http://home.myspace.com/index.cfm?fuseaction=user";
    //MySpace page redirected to after login.
    
    $postvars = "email=user%40domain.ext&password=something";
    //Set your email and password for your MySpace account.
    
    $contentlength = strlen($postvars);
    //Determine length for content-length header info.
    
    $page = "http://...";
    //The page on MySpace you'd like to grab from once you're signed in.
    
    $agent=$_SERVER["HTTP_USER_AGENT"];
    //User-agent as to be seen by MySpace server.
    
    //Headers. This script uses two cURL sessions over two separate pages
    //solely for logging in, mimicing the redirect MySpace performs when you
    //login. We need to specify separate headers for each page which I've done.
    
    $header_myspace_collect = array(
    "Host: collect.myspace.com",
    $agent,
    "Content-Type: application/x-www-form-urlencoded",
    "Content-Length: " . $contentlength);
    
    $header_myspace_home = array(
    "Host: home.myspace.com",
    $agent);
    
    
    //URL 1: MySpace Main Login
    
    $ch = curl_init();
    //Initiate cURL session.
    
    curl_setopt($ch, CURLOPT_URL, $url1);
    //Set URL to POST to.
    
    curl_setopt($ch, CURLOPT_HEADER, 1);
    //Allow headers to be returned.
    
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    //Don't follow redirects. We'll change pages ourself.
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //Return page data instead of printing it.
    
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    //Cookie file to save cookies to.
    
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    //Cookie file MySpace will seek for cookies.
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header_myspace_collect);
    //Header to use.
    
    curl_setopt($ch, CURLOPT_POST, 1);
    //Allow HTTP POST.
    
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    //User-Agent to be seen by server.
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
    //Allocate fields to POST.
    
    $myspace_collect_return = curl_exec($ch);
    //Execute this cURL session, allocating contents of page.
    
    
    
    //URL 2: User's MySpace homepage. Necessary to connect here so the
    //MySpace server acknowledges cURL's request to continue authorizing
    //your login.
    
    curl_setopt($ch, CURLOPT_URL, $url2);
    //Set URL.
    
    curl_setopt($ch, CURLOPT_HEADER, 1);
    //Allow headers.
    
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    //Don't redirect us.
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //Return page, don't print it.
    
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    //Use cookie file for cookies.
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header_myspace_home);
    //Use header.
    
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    //Use agent.
    
    $myspace_home_return = curl_exec($ch);
    //Execute cURL session and return data to variable.
    
    
    
    //URL3: Specified URL of your choice.
    //In my case it was a user-submitted bulletin URL.
    
    curl_setopt($ch, CURLOPT_URL, $page);
    //Same basic routine.
    
    curl_setopt($ch, CURLOPT_HEADER, 1);
    //Header.
    
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    //No redirect.
    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //Return, don't print.
    
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    //Use file for cookies.
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header_myspace_home);
    //Header.
    
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    //Agent.
    
    $pagecontents = curl_exec($ch);
    //Execute cURL session, and place page conents into variable.
    
    curl_close($ch);
    //Close cURL session.
    
    $file = fopen("cookie.txt", "w+"); fclose($file);
    //Dump cookies again for security.
    
    //Process complete. MySpace page $page sucessfully
    //stored into $pagecontents.
    //Now, you can do whatever you want with it. Parse it.
    //Extract something from it.
    //Use a regular expression on it.
    //Etc.
    ?>
    
    Code (markup):
     
    tobes, Jun 19, 2006 IP
  9. yugu

    yugu Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You can look how it works here
    http://dev.4clever.com/projects/myspacelogin/
     
    yugu, Jun 20, 2006 IP
  10. yugu

    yugu Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    nice work, tobes.
    c_url is probably the best way :)
     
    yugu, Jun 20, 2006 IP
  11. sral

    sral Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Can I use this to update my MySpace layout from my site. Is there an example of a PHP script that I can use?
     
    sral, Jul 12, 2006 IP
  12. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Yes, you can use cURL to update your myspace from another site. I don't think there is any freely available right now, but I will be altering one of my scripts so it can do this sometime this week.
     
    giraph, Jul 12, 2006 IP
  13. alassy

    alassy Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Hello - I tried the example posted by yugu above and it doesn't seem to work anymore. Has MySpace taken steps to block dynamic logins to their site? Does anyone have a script that is working currently? Thanks! - Adam
     
    alassy, Aug 5, 2006 IP
  14. ArcticPro

    ArcticPro Banned

    Messages:
    1,273
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Yeah it does.
     
    ArcticPro, Aug 5, 2006 IP
  15. fajitatx

    fajitatx Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I installed this script and attempted to use it.

    The result I am getting when I print $pagecontents is:

    HTTP/1.1 400 Bad Request Content-Type: text/html Date: Tue, 09 Jan 2007 20:31:03 GMT nnCoection: close Content-Length: 42
    Bad Request (Invalid Header Name)



     
    fajitatx, Jan 9, 2007 IP
  16. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Maybe because the script was posted in June 2006...
     
    giraph, Jan 9, 2007 IP
  17. ILiketohelp

    ILiketohelp Guest

    Messages:
    756
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Does anybody have a working script for this?
     
    ILiketohelp, Apr 18, 2009 IP