I'm not sure what to do with PHP so I need help. I run a myspace friend adder website, and myspace has recently updated their layout (You can choose which one to use, meaning each has its own code) The code I have fetches the users picture if they use the old layout, but fetches nothing if they are using the new onw. I need someone to update the code for me, these are the 2 layout codes. Old Layout: <a id="ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage" rel="searchMonkey-photo" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=27574110"> <img border="0" alt="" src="http://a542.ac-images.myspacecdn.com/images01/80/m_09d0fd70791bc2cd75d0ddd9bc70bf15.jpg" /> </a> Code (markup): New Layout: <a rel="searchMonkey-photo" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=27574110" > <img class="photo " alt="Photo" src="http://a542.ac-images.myspacecdn.com/images01/80/m_09d0fd70791bc2cd75d0ddd9bc70bf15.jpg" /> </a> Code (markup): And here is the code that I have that fetches the users picture. preg_match("/<a id=\"ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage\" rel=\"searchMonkey-photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img border=\"0\" alt=\"\" [^\>]*src=\"([^\">]+)/is",$hold,$match); PHP: I would like someone to alter that 1 line of code, so it can fetch the users picture regardless of what layout they are using. I'll send anyone the money via paypal once they have it working.
$hold is the variable carrying the whole pages html? this way you get the photo-url: $photourl=explode("<img class=\"photo \" alt=\"Photo\" src=\"",$hold);$photourl=explode("\"",$photourl[1]);$photourl=$photourl[0]; Code (markup): the photo´s url will be in the $photourl variable.
Hey I'm running the same script as Loryman =) and I am having the same problem with the MySpace Profile 2.0 Update as well. I will pay $25 American dollars via paypal to whoever can fix my problem. There is a difference in the code that we use - I beleive that MySpace is still also using "ctl00_cpMain_ctl01_UserBasicInformation1_hlDefaultImage" as well as "ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage" Here is a copy of the code that I use to "Update" the images on my site, but I think it is almost exactly the same as what Loryman is using on his site <?php session_start(); include 'config.php'; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $fid = $_SESSION['fid']; define ("profile_url","http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=" ); $full_file_path = profile_url.$fid; $handle = fopen($full_file_path,"r"); if (!$handle){ echo "<p>Sorry Myspace Is Slow Try Again.\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; } preg_match("/<a id=\"ctl00_cpMain_ctl01_UserBasicInformation1_hlDefaultImage\" rel=\"searchMonkey-photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match); $pic_url = $match[1]; preg_match("/<span class=\"nametext\">(.*)<br \/>/",$hold,$match); $name = $match[1]; if(empty($pic_url)) { preg_match("/<a type=\"text\/javascript\" id=\"ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage\" rel=\"searchMonkey-photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match); $pic_url = $match[1]; } if(empty($name)) { preg_match("/<span class=\"nametext\">(.*)<\/span>/",$hold,$match); $name = $match[1]; } fclose($handle); ini_restore('max_execution_time'); ini_restore('default_socket_timeout'); $pic = $pic_url; $ip = $_SERVER['REMOTE_ADDR']; mysql_query("UPDATE xtrm_users SET name='$name', pic='$pic', ip='$ip' WHERE fid='$fid'"); header("location:home.php"); } ?> Code (markup): Anyone Interested in "fixing" this for me? I'll send anyone the money via paypal once they have it working as well!
well chuck, try this one now, i had no chance now to fully test it, since i miss the database but i tested and it digs the exact pic url from the myspace pages. so it should work like this now: <?php session_start(); include 'config.php'; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $fid = $_SESSION['fid']; define ("profile_url","http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=" ); $full_file_path = profile_url.$fid; $handle = fopen($full_file_path,"r"); if (!$handle){ echo "<p>Sorry Myspace Is Slow Try Again.\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; } preg_match("/<a id=\"ctl00_cpMain_ctl01_UserBasicInformation1_hlDefaultImage\" rel=\"searchMonkey-photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match); $photourl=explode("<img border=\"0\" alt=\"\" src=\"",$hold);$photourl=explode("\"",$photourl[1]);$photourl=$photourl[0]; preg_match("/<span class=\"nametext\">(.*)<br \/>/",$hold,$match); $name = $match[1]; if(empty($name)) { preg_match("/<span class=\"nametext\">(.*)<\/span>/",$hold,$match); $name = $match[1]; } fclose($handle); ini_restore('max_execution_time'); ini_restore('default_socket_timeout'); $pic = $photourl; $ip = $_SERVER['REMOTE_ADDR']; mysql_query("UPDATE xtrm_users SET name='$name', pic='$pic', ip='$ip' WHERE fid='$fid'"); header("location:home.php"); } ?> Code (markup): i removed your old code portion that was doing the extraction of the pic url and put my own routine in it. i use a slightly different approach. first i break the whole htmlcode which is in the variable $hold in parts by the single html-code that only appears before the images url, see php function EXPLODE: $photourl=explode("<img border=\"0\" alt=\"\" src=\"",$hold); explode puts all content around the explode-factor in an array. now i know that occurence nr.2 which is "1" in an array, cause it starts at "0" i now explode it again with " cause thats the sign that ends the url. $photourl=explode("\"",$photourl[1]); then i know the photourl is nr.0 in the new array, but i want the array flushed and a nice variable name to work any further: $photourl=$photourl[0]; sure my code is not really how you learn it in school and using PREG_MATCH is way stylisher, but it always works to scrape sites like this for me i learned php alone by doing, so i have my very own ways to achieve lots of stuff... looks thru this, you can sure learn a little. make sure to look in PHP ARRAYS and PHP STRING FUNCTIONS enjoy this tut/fix, happpy
i could not test it cause i have no example-myspace-urls, but this should again work with all 3 variants: <?php session_start(); include 'config.php'; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $fid = $_SESSION['fid']; define ("profile_url","http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=" ); $full_file_path = profile_url.$fid; $handle = fopen($full_file_path,"r"); if (!$handle){ echo "<p>Sorry Myspace Is Slow Try Again.\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; } preg_match("/<a id=\"ctl00_cpMain_ctl01_UserBasicInformation1_hlDefaultImage\" rel=\"searchMonkey-photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match); $hold=eregi_replace("<img class=\"photo \" alt=\"Photo\" src=\"","<img border=\"0\" alt=\"\" src=\"",$hold); $photourl=explode("<img border=\"0\" alt=\"\" src=\"",$hold);$photourl=explode("\"",$photourl[1]);$photourl=$photourl[0]; if(eregi("ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage",$hold)) {$photourl=explode("ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage",$hold);$photourl=explode("\"",$photourl[1]);$photourl=photourl[6];} preg_match("/<span class=\"nametext\">(.*)<br \/>/",$hold,$match); $name = $match[1]; if(empty($name)) { preg_match("/<span class=\"nametext\">(.*)<\/span>/",$hold,$match); $name = $match[1]; } fclose($handle); ini_restore('max_execution_time'); ini_restore('default_socket_timeout'); $pic = $photourl; $ip = $_SERVER['REMOTE_ADDR']; mysql_query("UPDATE xtrm_users SET name='$name', pic='$pic', ip='$ip' WHERE fid='$fid'"); header("location:home.php"); } ?> Code (markup):
Closer yet! I get an Error Parse error: syntax error, unexpected '[' in /home/supremea/public_html/test/update.php on line 28 Example URL's Profile 2.0 Example Profile http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=75619630 ctl01 Example Profile http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=6221 ctl02 Example Profile http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=136804968
oh sorry man, it was a typo of me..... i forgot one $ sign. damn now try this: <?php session_start(); include 'config.php'; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $fid = $_SESSION['fid']; define ("profile_url","http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendID=" ); $full_file_path = profile_url.$fid; $handle = fopen($full_file_path,"r"); if (!$handle){ echo "<p>Sorry Myspace Is Slow Try Again.\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; } preg_match("/<a id=\"ctl00_cpMain_ctl01_UserBasicInformation1_hlDefaultImage\" rel=\"searchMonkey-photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match); $hold=eregi_replace("<img class=\"photo \" alt=\"Photo\" src=\"","<img border=\"0\" alt=\"\" src=\"",$hold); $photourl=explode("<img border=\"0\" alt=\"\" src=\"",$hold);$photourl=explode("\"",$photourl[1]);$photourl=$photourl[0]; if(eregi("ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage",$hold)) {$photourl=explode("ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage",$hold);$photourl=explode("\"",$photourl[1]);$photourl=$photourl[6];} preg_match("/<span class=\"nametext\">(.*)<br \/>/",$hold,$match); $name = $match[1]; if(empty($name)) { preg_match("/<span class=\"nametext\">(.*)<\/span>/",$hold,$match); $name = $match[1]; } fclose($handle); ini_restore('max_execution_time'); ini_restore('default_socket_timeout'); $pic = $photourl; $ip = $_SERVER['REMOTE_ADDR']; mysql_query("UPDATE xtrm_users SET name='$name', pic='$pic', ip='$ip' WHERE fid='$fid'"); header("location:home.php"); } ?> Code (markup):