[WTT] preg_match for a MySpace Site - would like it to be fixed.

Discussion in 'Programming' started by DigitalChuck, Jul 30, 2009.

  1. #1
    Edit - Now Offering $10 by PayPal

    Hi, I'm having some trouble with my preg_match for a MySpace Site.

    I would like some help with this because I don't quite understand how to make the necessary changes to make it work again.:confused:

    This worked yesterday and for several months to allow users to login to my site, today, it does not return an image URL, so it does not let users login.

    I need this code to scrape a MySpace users profile picture URL, and then store it in $pic_url

    Here is my old code

    if(empty($pic_url))
    
            {
    
            $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("user.viewAlbums&friendID",$hold)) {$photourl=explode("user.viewAlbums&friendID",$hold);$photourl=explode("\"",$photourl[1]);$photourl=$photourl[6];}
    
    
            $pic_url = $photourl;
    
            }
    
    Code (markup):
    Here is the code that I am scraping from the MySpace Profile
    
            
    
            <a href="[URL="http://forums.digitalpoint.com/view-source:http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=463756834"]http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&friendID=463756834[/URL]" >
                <img class="photo " alt="Photo of Monica Marchese" src="[URL="http://forums.digitalpoint.com/view-source:http://c2.ac-images.myspacecdn.com/images02/107/m_07ab24e4655d45b7b34a6807d4067a95.jpg"]http://c2.ac-images.myspacecdn.com/images02/107/m_07ab24e4655d45b7b34a6807d4067a95.jpg[/URL]" />
            </a>         </a>
    Code (markup):
    The biggest changes I can see between the code that I am scraping, and the code that my preg_match is looking for, is that the IMG BORDER and the ALT are no longer present in the code on the MySpace Profile page.

    But, then again, I don't know how to fix it, so there may be other changes that I don't realize yet.

    Any help will be massively appreciated - I can pay $10 by PayPal for this fix.

    If you would like more information - please send me a PM or email (link is on my profile page)


    I am going to continue to search for the solution until this is resolved

    Best Regards
    Chuck
     
    Last edited: Jul 30, 2009
    DigitalChuck, Jul 30, 2009 IP
  2. manjifera

    manjifera Well-Known Member

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    118
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Last edited: Jul 30, 2009
    manjifera, Jul 30, 2009 IP
  3. DigitalChuck

    DigitalChuck Peon

    Messages:
    241
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    Thank you to those that have replied - your help is much appreciated

    There have been a few developments:


    The reason that I was trying to repair those lines of code, is because it is part of a larger chunk of code that is also no longer working, and I am trying to repair all of the code. So to make it easier for you to see what I am doing, I will show you the login.php from my site. The entire preg_match section of the code is not functioning - all the different profile types are returning "Invalid User" if they are not already in the database. Here is the code.


    <?php
    session_start();
    if(isset($_POST['submit']))
    {
    include 'config.php';
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    $ip   = $_SERVER['REMOTE_ADDR'];
    $fid = $_POST['fid'];
    if($fid == 6221){ ?>
    <script language="javascript"><!--
    alert("I know Tom doesn't use adding sites! There for your childish behavior brings you to a site that suits your mental capacity! Peace.")
    location.replace("http://www.disney.com")
    //-->
    </script>
    <?PHP }
    else {
    $pass = $_POST['password'];
    $sql="SELECT * FROM xtrm_users WHERE fid='$fid'";
    $result=mysql_query($sql);
    $check=mysql_fetch_array($result);
      if($check[fid]==$fid) {
                       if($check[password]=='xxxxxxxx') {
    mysql_query("UPDATE xtrm_users SET ip = '$ip', last_login=CURRENT_TIMESTAMP WHERE fid = '$fid'");
              $_SESSION["fid"] = $fid;
             header("location:home.php"); }
                           else {
                              if($pass==$check[password]) {
    mysql_query("UPDATE xtrm_users SET ip = '$ip', last_login=CURRENT_TIMESTAMP WHERE fid = '$fid'");
                          $_SESSION["fid"] = $fid;
                         header("location:home.php"); }
                   else { ?>
                          
    
    <script language="javascript"><!--
    alert("Invalid Password!")
    location.replace("index.php")
    //-->
    </script> <?PHP }
    
    
                         }
    }
    else {
    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=\"myspace:photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match);
    
        $string_ahref = $match[1];
    
        $subjectstr = substr($string_ahref,0,350);
    
        $trimed = strip_tags($subjectstr,"<img>");
    
        $trimed = trim($trimed);
    
        $len = strlen($trimed);
    
        $pic_url = substr($trimed,0,($len-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];
                    }
    
            if(empty($pic_url))
    
            {
    
            preg_match("/<a id=\"ctl00_cpMain_ctl01_UserBasicInformation1_hlDefaultImage\" rel=\"myspace:photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match);
    
            $pic_url = $match[1];
    
            }
    
            if(empty($pic_url))
    
            {preg_match("/<a id=\"ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage\" rel=\"myspace:photo\" href=\"http:\/\/viewmorepics.myspace.com\/index\.cfm\?fuseaction=user\..*?friendID=$fid\">.*?<\s*img [^\>]*src=\"([^\">]+)/is",$hold,$match);
    
            $pic_url = $match[1];
    
            }
    
            if(empty($pic_url))
    
            {
    
            $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("user.viewAlbums&friendID",$hold)) {$photourl=explode("user.viewAlbums&friendID",$hold);$photourl=explode("\"",$photourl[1]);$photourl=$photourl[6];}
    
    
    
    
            $pic_url = $photourl;
    
            }
    
    if(empty($name))
            {
                    preg_match("/<h2 class=\"fn nickname\">(.*)<\/h2>/",$hold,$match);
                    $name = $match[1];
                    }
                    
                    if(empty($name))
            {
                    preg_match("/<h2 class=\"nickname\">(.*)<\/h2>/",$hold,$match);
                    $name = $match[1];
                    }
            
            fclose($handle);
            ini_restore('max_execution_time');
            ini_restore('default_socket_timeout');
            if(empty($pic_url))
            { ?>
    <script language="javascript"><!--
    alert("Invalid ID!")
    location.replace("index.php")
    //-->
    </script>                            
    <?PHP
            
            }
    else
    {
    $oldip = $_POST['new'];
    $sql = "SELECT * FROM xtrm_users WHERE fid = '$oldip'";
    $res = mysql_query($sql);
    echo mysql_error();
    $check = mysql_fetch_array($res);
       $newip = $check['ip'];
     if($newip!=$ip) {
    mysql_query("UPDATE xtrm_users SET points = points+2500 WHERE fid = '$oldip'");
    mysql_query("UPDATE xtrm_users SET total_points = total_points+2500 WHERE fid = '$oldip'");
    mysql_query("UPDATE xtrm_users SET refs = refs+1, prix = prix+1 WHERE fid = '$oldip'");
    
    }
    
    else {
    
    //add a feature here in the future..
    
    }
    
    
    
      $sql="SELECT * FROM xtrm_users WHERE fid='$oldip'";
    
    $earnvip = mysql_query($sql);
    
    $freevip = mysql_fetch_array($earnvip);
    
    $frefs = $freevip['refs'];
    
    
    
    if( $frefs >=20)
    
    {
    
            mysql_query("UPDATE xtrm_users SET days = days+5 WHERE fid = $oldip");
    
    mysql_query("UPDATE xtrm_users SET prix = '0', refs = '0' WHERE fid = $oldip");
    
    }
    elseif( $frefs >=10)
    
    {
    
            mysql_query("UPDATE xtrm_users SET days = days+3 WHERE fid = $oldip");
    
    mysql_query("UPDATE xtrm_users SET prix = '0', refs = '0' WHERE fid = $oldip");
    
    }
    
    
    
    $pic = $pic_url;
    $date = date(Ymd);
    mysql_query("INSERT INTO xtrm_users SET
    pic='$pic_url',
    name='$name',
    ip='$ip',
    whorf='$oldip',
    joindate='$date',
    points='100',
    fid='$fid'");
     $_SESSION["fid"] = $fid;
    
    header("location:home.php");
     }
    }
    }
    }
    }
    ?>
    Code (markup):
    Maybe there is a way to do the login with 1 function to check the profile for an image, but there are several types of profiles on MySpace, and they will return different blocks of code for the profile picture URL here are a few examples,

    Profile type 1 looks like this:

    <a id="ctl00_cpMain_ctl01_UserBasicInformation1_hlDefaultImage" rel="myspace:photo" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&amp;friendID=486542745">
    img border="0" alt="" src="http://c4.ac-images.myspacecdn.com/images02/103/m_2d4f6aaef1264bcca1021ae16a3bb263.jpg" />
    </a>
    Code (markup):

    Profile type 1(a?) looks the same, but has one change in the "ct100_cpMain_ct101_UserBasicInformation_h1_defaultImage":

    <a id="ctl00_cpMain_ctl02_UserBasicInformation1_hlDefaultImage" rel="myspace:photo" href="http://viewmorepics.myspace.com/index.cfm?fuseaction=user.viewAlbums&amp;friendID=486542745">
    <img border="0" alt="" src="http://c4.ac-images.myspacecdn.com/images02/103/m_2d4f6aaef1264bcca1021ae16a3bb263.jpg" />
    Code (markup):
    </a> And then Finally the Profile 2.0 type that is in the original post



    Is there any way to make my Login.php work with the 3 types of profiles?

    That would really solve my problem -

    I wanted to include this new information about the other types of profiles not working now as well - these changes have been taking place all day with MySpace.

    Thanks Again
    Chuck
     
    DigitalChuck, Jul 30, 2009 IP
  4. viral2583

    viral2583 Well-Known Member

    Messages:
    352
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    Hello,

    I have 5 years of experience in PHP, mysql and ajax. PM me more details.

    I can give you best quality work.




    Thanks you.
     
    viral2583, Jul 31, 2009 IP