Page 1 of 1

Code won't work

Posted: Fri Jul 11, 2008 8:01 pm
by vexus
Ok so heres the situation I have code to echo data from a db and when I include the Function.php which is suppose to grab 3 urls from 3 websites it doesn't do anything. Without the included function it works fine.. and testing the function by itself works fine as well with this code:

Code: Select all

 
<?PHP
include ('Function.php');
?>
<html>
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
 
<body>
<?PHP
 $array = 
 
array('http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=128237478', 
 
'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=165087792');
        $links = imageGrabber($array);
        echo $links[0][0];
        echo "\n";
        echo $links[1][0];
?>
</body>
 
</html>
 

Function:

Code: Select all

 
<?php
function imageGrabber($url, $unique = 1)
{
    $startTag = 'hlDefaultImage';
    $srcTag = 'src=';
    $endTag = '>';
    $counter = 0;
   
    if(!is_array($url))
    {
        $url = array($url);
    }
   
    if ($unique !== 0 && $unique !== 1)
    {
        printf('Invalid parameter for $unique. The parameter must be either 1 or 0.');
        exit();
    }
   
    foreach ($url as $value)
    {
        $contents = file_get_contents($value);
       
        $domain = $value;
        $domain = substr($domain, 7);
        $pos = stripos($domain, '/');
       
        if ($pos)
        {
            $domain = substr($domain, 0, stripos($domain, '/'));
        }
       
        while ($contents)
        {
            set_time_limit(0);                                    # In case we have several large 
 
pages
           
            $quotes = array('"', "'", "\n");
            $contents = str_replace($quotes, '', $contents);    # Strip " and ' as well as \n from 
 
input string
            $contents = stristr($contents, $startTag);            # Drop everything before the start 
 
tag '<img'
            $contents = stristr($contents, $srcTag);            # Drop everything before the 'src'
           
            $endTagPosition = stripos($contents, $endTag);        # Position of the end tag '>'
            $src = substr($contents, 4, $endTagPosition - 4);    # Get everything from src to end tag 
 
--> 'src="path" something>'
           
            $spacePosition = stripos($src, ' ');                # Position of space (if it exists)    
 
           
           
            if ($spacePosition !== false)
            {
                $src = substr($src, 0, $spacePosition);            # Drop everything after space, 
 
keeping 'src="path"'
            } 
        $questionMarkPosition = stripos($src, '?');
           
            if ($questionMarkPosition !== false)
            {
                $src = substr($src, 0, $questionMarkPosition);    # Remove any part after a '?'
            }
           
            $contents = stristr($contents, $endTag);            # Drop everything before the end tag 
 
'>'
           
            if ($src)
            {
                if (stripos($src, '/') === 0)
                {
                    $src = 'http://'.$domain.$src;                # Relative link, so add domain 
 
before '/'
                }
                else
                {
                    if (stripos($src, 'http://') !== 0 && stripos($src, 'https://') !== 0 && 
 
stripos($src, 'ftp://') !== 0)
                    {
                        $src = 'http://'.$domain.'/'.$src;        # Relative link, so add domain and 
 
'/'
                    }
                }
               
                $paths[] = $src;
            }
        }
       
        if ($unique === 1)
        {
            $results[] = array_unique($paths);        # Create final array with unique $paths
        }
        else
        {
            $results[] = $paths;                    # Create final array with all $paths
        }
       
        $paths = array();                            # Reset links
        $counter++;                                    # Increment counter
    }
 
    return $results;
} 
?>
 
Display page code(REMOVED HOST, and password for obvious reasons, this is the code that just displays a blank page because Function.php is included. :(

Code: Select all

 
<?PHP  
include ('Function.php');
$dbhost = '';
$dbuser = 'vexus';
$dbpass = '';
$dbname = 'cheaters';
$gcheater = $_GET['Cheater'];
$gwith = $_GET['CWith'];
 
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
 
 
mysql_select_db($dbname) or die(mysql_error()); 
 
 
$data = sprintf("SELECT Name, Cheater, CheaterURL, CWith, WithURL, Victim, VictimURL, Info, Info2, Story FROM cheater WHERE Cheater='%s' AND CWith='%s'", 
 
mysql_real_escape_string($gcheater), mysql_real_escape_string($gwith));
 
$result = mysql_query($data) or die(mysql_error());  
 
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
 
while ($row = mysql_fetch_assoc($result)) {
    $name = $row['Name'];
    $cheater = $row['Cheater'];
    $cheaterurl = $row['CheaterURL'];
    $cwith = $row['CWith'];
    $withurl = $row['WithURL'];
    $victim = $row['Victim'];
    $victimurl = $row['VictimURL'];
    $info = $row['Info'];
    $info2 = $row['Info2'];
    $story = $row['Story'];
 
$sarray = array($cheaterurl, $withurl, $victimurl);
$piclink = imageGrabber($sarray);
 
   echo "<table border=\"0\" width=\"100%\" cellspacing=\"1\" cellpadding=\"0\" height=\"59\">";
   echo "     <tr>";
   echo "       <td width=\"100%\" height=\"21\">";
   echo "         <table border=\"0\" width=\"100%\" bordercolor=\"#000000\" cellspacing=\"0\" bordercolorlight=\"#000000\" bordercolordark=\"#000000\">";
   echo "           <tr>";
   echo "             <td width=\"33%\" bgcolor=\"#6B6D6B\">";
   echo "               <p align=\"center\"><b><font face=\"Arial\" color=\"#000000\">" . $cheater . "</font></b></td>";
   echo "             <td width=\"33%\" bgcolor=\"#6B6D6B\">";
   echo "               <p align=\"center\"><b><font face=\"Arial\" color=\"#000000\">&nbsp;John"; 
   echo "               Doe&nbsp;</font></b></td>";
   echo "             <td width=\"34%\" bgcolor=\"#6B6D6B\">";
   echo "               <p align=\"center\"><b><font face=\"Arial\" color=\"#000000\">on ";
   echo "               Ricky Bobby</font></b></td>";
   echo "           </tr>";
   echo "           <tr>";
   echo "             <td width=\"33%\" bgcolor=\"#D7D7D7\">";
   echo "<p align=\"center\"><img border=\"0\" src=\"" . $piclink[0][0] . "\" style=\"border: 1 solid #000000\" width=\"170\" height=\"127\"></td>";
   echo "             <td width=\"33%\" bgcolor=\"#D7D7D7\">";
   echo "<p align=\"center\"><img border=\"0\" src=\"" . $piclink[1][0] . "\" style=\"border: 1 solid #000000\" width=\"170\" height=\"127\"></td>";
   echo "             <td width=\"34%\" bgcolor=\"#D7D7D7\">";
   echo "<p align=\"center\"><img border=\"0\" src=\"" . $piclink[1][0] . "\" style=\"border: 1 solid #000000\" width=\"170\" height=\"164\"></td>";
   echo "           </tr>";
   echo "           <tr>";
   echo "             <td width=\"33%\"></td>";
   echo "             <td width=\"33%\"></td>";
   echo "             <td width=\"34%\"></td>";
   echo "           </tr>";
   echo "           <tr>";
   echo "             <td width=\"33%\" bgcolor=\"#6B6D6B\"><font face=\"Arial\"><b>Information:</b></font></td>";
   echo "             <td width=\"33%\" bgcolor=\"#6B6D6B\">";
   echo "               <p align=\"center\">&nbsp;</td>";
   echo "             <td width=\"34%\" bgcolor=\"#6B6D6B\">&nbsp;</td>";
   echo "           </tr>";
   echo "         </table>";
   echo "         </td>";
   echo "       </tr>";
 
   echo "     <tr>";
   echo "       <td width=\"100%\" height=\"21\">";
   echo "         <table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">";
   echo "           <tr>";
   echo "             <td width=\"100%\"><font face=\"Arial\"><b>Informants name:</b></font> ";
   echo "               <font face=\"Arial\">Anonymous</font></td> ";
   echo "           </tr>";
   echo "           <tr>";
   echo "             <td width=\"100%\"><font face=\"Arial\"><b>Heard the information";
   echo "               from: </b>Friend of a friend</font></td>";
   echo "           </tr>";
   echo "           <tr>";
   echo "             <td width=\"100%\"><font face=\"Arial\"><b>What they did together: </b>Had";
   echo "               sex</font></td>";
   echo "           </tr>";
   echo "         </table>";
   echo "       </td>";
   echo "     </tr>";
   echo "     <tr>";
   echo "       <td width=\"100%\" height=\"21\"><font face=\"Arial\"><b>Credibility rating(";
   echo "         + / -- ): </b>5/10</font></td>";
   echo "     </tr>";
   echo "     <tr>";
   echo "       <td width=\"100%\" height=\"21\"><font face=\"Arial\"><b>Story:</b></font></td>";
   echo "     </tr>";
   echo "     <tr>";
   echo "       <td width=\"100%\" height=\"21\"><font face=\"Arial\">Lindsey met John at a";
   echo "         party one Saturday night and they both got drunk she cheated on";
   echo "         ricky and that was that!</font></td>";
   echo "     </tr>";
   echo "     <tr>";
   echo "       <td width=\"100%\" height=\"21\" bgcolor=\"#6B6D6B\"><b><font face=\"Arial\">User";
   echo "         comments:</font></b></td>";
   echo "     </tr>";
   echo "     <tr>";
   echo "       <td width=\"100%\" height=\"21\"><b><font face=\"Arial\">xx</font></b></td>";
   echo "     </tr>";
   echo "   </table>";
}
mysql_free_result($result);
?>
 

Re: Code won't work

Posted: Fri Jul 11, 2008 11:05 pm
by vexus
Not trying to be pushy.. I know this isn't really the smallest or easiest code question but it would be really appreciated if some one could help me out. Thanks guys.

Re: Code won't work

Posted: Sat Jul 12, 2008 1:57 am
by Apollo
Just a matter of simple debugging by boxing in the problem: start including an empty Function.php, then fill up Function.php step by step and see when the page becomes blank. Add an empty function imageGrabber($url, $unique = 1) first, then put in the first block of statements, etc.