koppykat Posted August 4, 2009 Share Posted August 4, 2009 I have a Myspace Train Site and the simple process of it is that you either enter your FriendID or your Myspace userid and using fopen - I go to the user's page and using preg_match I extract the profile picture URL and place it in an img src along with an add me link onto the train site. I'm not sure when it started (past couple days or few weeks) - when I use fopen to grab the site - the page that is returned will have substituted a "0" throughout the page for the friendid that is needed - thus is never finds the one being searched for and I cannot assemble the img src for the profile pic or the add me link. Normally when you check the source code of the myspace page ... http://www.myspace.com/starry1st ... you would see ... MySpace.ClientContext = {"UserId":32086620,"DisplayFriendId":80992001,"IsLoggedIn":true,"FunctionalContext":"UserViewProfile","UserType":1}; and I would want to pick up the ... 80992001 after the displayfriendid. The regex I am using had done that just fine for the past few months. It appears as though Music Myspaces still work fine and contain the friendid for me to locate what I need, but personal myspaces are the ones to somehow substitute the "0" for the friendID or username which prevents me from going on. so what I end up getting on the starry1st personal myspace when I FOPEN it is ... MySpace.ClientContext = {"UserId":32086620,"DisplayFriendId":0,"IsLoggedIn":true,"FunctionalContext":"UserViewProfile","UserType":1}; My regex works fine, but it is picking up the "0" after the displayfriendid which is not what is wanted. Somehow Myspace appears to be doing this "0" zero translation ... maybe because I'm not calling it through the browser? I've simplified the code below to illustrate how a music myspace is able to return the proper friendid while a personal myspace only returns 0. <?php // be sure to uncomment one of the define lines to test // The following one is a Personal MySpace and it returns 0 for the FriendID //define ("full_profile_url","http://www.myspace.com/starry1st" ); // The following one is a Music MySpace and it properly returns the FriendID //define ("full_profile_url","http://www.myspace.com/chriswillismusic" ); $handle = fopen(full_profile_url,"r"); if (!$handle){ echo "<p>Sorry - Unable to Open Site.\n"; $arr = 0; } else { $timeout = 300; ini_set('max_execution_time','120'); set_time_limit(120); ini_set('default_socket_timeout','120'); while($contents = fread($handle,'1024')) { $hold .= $contents; } if(preg_match("/DisplayFriendId\"\d{1,}),/is",$hold,$match)){ echo "<br>"; echo "This should be the FriendID: "; echo $match[1];echo "<br>"; echo "<br>"; }} ?> Anyone have any ideas for me? Thanks, Dan Quote Link to comment https://forums.phpfreaks.com/topic/168846-solved-preg_match-and-myspace-profile-pic-url-friendid-returned-as-0/ Share on other sites More sharing options...
thebadbad Posted August 4, 2009 Share Posted August 4, 2009 That's weird. I tested your code (good on ya for setting up an easy testing script, BTW ), and the right friend ID is returned with both MySpace pages (both when setting the user agent string, and when leaving it empty; read below). I'm guessing that MySpace noticed your automated usage of their pages, and decided to stop serving the friend IDs to you. Although that seems a little far fetched. One way they could be detecting automated usage, is by checking the user agent string of the client requesting the page. In PHP, the user agent string is empty by default. You can set it with ini_set(), to be used with fopen(): ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; da; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1'); But if your server's IP is already on a black list, that won't help you now, unless the IP changes. Quote Link to comment https://forums.phpfreaks.com/topic/168846-solved-preg_match-and-myspace-profile-pic-url-friendid-returned-as-0/#findComment-890947 Share on other sites More sharing options...
koppykat Posted August 5, 2009 Author Share Posted August 5, 2009 Hey ... Thanks thebadbad ... Not sure why it worked both ways in your testing ... but I tried adding ... ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; da; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1'); ... before the fopen ... and it did the trick!!! Thanks So Much!!! Dan Quote Link to comment https://forums.phpfreaks.com/topic/168846-solved-preg_match-and-myspace-profile-pic-url-friendid-returned-as-0/#findComment-890996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.