Jump to content

My php function will not completely run, it seems to just stop execution


Hardwarez

Recommended Posts

???
Ok, my php is doing something weird!  It seem that one of my functions will no completely run.
I placed echo through-out my function and it just stops working half way throug the function.

Is there some kind of buffer/size limit to a function?

My Function:
function IsUserValid ($ipaddr,$Usr)  //--------------Check database FUNCTION
{
echo '<font color="red"><P>Address: ' . $ipaddr . ', User: ' . $Usr;
$query = "SELECT id FROM userlist WHERE clientip='$ipaddr' && user='$Usr'";
$result = mysql_query($query) or die (mysql_error());
$number = mysql_num_rows($result);
// check time out time and kill valid IP if timeout
$Utime = date("U");
$query = "SELECT Utime FROM userlist WHERE clientip='$ipaddr'";
$result = mysql_query($query) or die (mysql_error());
echo '<P>' . $result;
$row = mysql_fetch_array($result) or die(mysql_error());
echo '<BR>rowTime: ' . $row['Utime'] . '</font>';
xxxxxxxxxxxxxxxxxxxxxxxNOTHING BELOW THIS RUNS, THE ECHOs DO NOT EVEN WORKxxxxxxxx
if ($Utime > $row['Utime']) {
$query="UPDATE userlist SET clientip='1.0.0.1' WHERE clientip='$ipaddr' LIMIT 1";
mysql_query($query) or die (mysql_error());
$r='0';// clear flag to require re-validation
}

if ($r != '0' && $number > '0') $x='1';
else $x ='0';
echo 'returning from IsUservalid with: ' . $x;
return $x; //END OF FUNCTION
}
You have two conditional statements starting right after you say the method stops.  

1.) if $UTime is not greater than $row['UTime'] then that statement will not fire, are you sure $UTime is assigned the right value?

2.) if ($r does not equal 0 AND $number is not greater than 0 then $x will equal 0, otherwise it would be 1.  Are you sure that $r AND $x are assigned the right values?

3.) are you able to use display_errors = on in PHP.INI

I also noticed you have several OR die()'s,  your method might be breaking on one of them.

P.S When comparing variables to digits it's best to keep the digit outside of single/double quotes  (0 Vs. '0')

Is it possable to use to many IF statments?  Or make them to long?

I have error reporting turned on, but I'm not getting any errors..

Also, moving my numbers outside the quotes did make the function run completely.  Why whould this have forzen the codes execution?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.