Jump to content

[SOLVED] Preg_match and Myspace Profile Pic URL - friendID returned as "0"


koppykat

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.