Need help updating script on website (Will pay $20 for quick fix)

Discussion in 'PHP' started by Loryman, Nov 10, 2008.

  1. #1
    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&amp;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.
     
    Loryman, Nov 10, 2008 IP
  2. Tommy Arnold

    Tommy Arnold Active Member

    Messages:
    525
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Job taken by PM
     
    Tommy Arnold, Nov 10, 2008 IP
    Loryman likes this.
  3. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #3
    $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.
     
    happpy, Nov 10, 2008 IP
  4. DigitalChuck

    DigitalChuck Peon

    Messages:
    241
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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!
     
    DigitalChuck, Nov 10, 2008 IP
  5. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #5
    is it really so hard to implement the fix i posted????
    if yes, hire me via PM :)
     
    happpy, Nov 10, 2008 IP
  6. DigitalChuck

    DigitalChuck Peon

    Messages:
    241
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <---UberNoob

    Yes friend, this is difficult for me - this is my php cherry being popped
     
    DigitalChuck, Nov 10, 2008 IP
  7. DigitalChuck

    DigitalChuck Peon

    Messages:
    241
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    happpy is hired via PM
     
    DigitalChuck, Nov 10, 2008 IP
  8. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #8
    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
     
    happpy, Nov 10, 2008 IP
  9. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #9
    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):
     
    happpy, Nov 10, 2008 IP
  10. DigitalChuck

    DigitalChuck Peon

    Messages:
    241
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #10
    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

    ;)
     
    DigitalChuck, Nov 10, 2008 IP
  11. DigitalChuck

    DigitalChuck Peon

    Messages:
    241
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I know there is a way - Loryman's site is working fine
     
    DigitalChuck, Nov 10, 2008 IP
  12. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #12
    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):
     
    happpy, Nov 10, 2008 IP
  13. DigitalChuck

    DigitalChuck Peon

    Messages:
    241
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Thank you soooo much! Check your PayPal ;)
     
    DigitalChuck, Nov 10, 2008 IP
  14. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #14
    thank YOU so much!
     
    happpy, Nov 11, 2008 IP