/    Sign up×
Community /Pin to ProfileBookmark

Function problems

Trying to include a function and its not working properly.
I have a Ping function thats in a file called pinger.php
Im trying to add this into a table for a form that im putting togeither.
I have tried to just put the function into my orginaly script but thats not working.
SO i tried to include it into my script still not working
How would i add the pinger.php into my table?

[code]
<table>
<tr>
<td>
<php include pinger.php; ?>
</td>
</tr>
</table>
[/code]

Something like is what i would like to have. Also i want my pinger script to pull and ip from a database.
Here is my pinger.php script

[code]
<?php

function Ping(){
// false proxy used to generate connection error
$ProxyServer = $row[‘ip’];
$ProxyPort = 80;
$timeout=3;
//echo “Opening ProxyServer $ProxyServer<br>”;
// must use next two statements
Set_Time_Limit(0); //Time for script to run .. not sure how it works with 0 but you need it
Ignore_User_Abort(True); //this will force the script running at the end

$handle = fsockopen($ProxyServer, $ProxyPort,$errno,$errstr,$timeout);
if (!$handle){
echo “<img src=’images/red.jpg’><br>”;
return 0;
} else {
// copied method for PING like time operation
$status = socket_get_status($handle);
//echo “Opened ProxyServer $ProxyServer<br>”;

//Time the responce
list($usec, $sec) = explode(” “, microtime(true));
$start=(float)$usec + (float)$sec;

$timeout=120;
stream_set_timeout($handle,$timeout);
//send somthing
ini_set(‘display_errors’,’0′);
$write=fwrite($handle,”echo thisn”);
if(!$write){
return 0;
}

//echo “Try To Read<br>”;
stream_set_blocking($handle,0);
//Try to read. the server will most likely respond with a “ICMP Destination Unreachable” and end the read. But that is a responce!
fread($handle,1024);
fclose($handle);
echo “<img src=’images/green.jpg’><br>”;
ini_set(‘display_errors’,’1′);

//Work out if we got a responce and time it
list($usec, $sec) = explode(” “, microtime(true));
$laptime=((float)$usec + (float)$sec)-$start;
if($laptime>$timeout)
return 0;
//else
// $laptime = round($laptime,3);
return $laptime;
}
}

// must use ErrorHandler to avoid php error being printed to screen
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
// you can set this to what ever you like.
//echo “In Error Handler<br>”;
return 0;
}

$old_error_handler = set_error_handler(“userErrorHandler”);

$time = Ping();
//echo “Time=n$time<br>”;
//echo “Done Checking<br>”;

?>

[/code]

Thanks for help!!

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 24.2006 — Quote the file name in your include statement.
Copy linkTweet thisAlerts:
@prophitauthorDec 24.2006 — Ya i have it like that in my script. I just didnt do it for my example. Here is my full scripte
<i>
</i>&lt;LINK REL=stylesheet HREF="inc/work.css" TYPE="text/css"&gt;

&lt;form action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
Search:&lt;input type="text" name="find" size="20"&gt;&lt;input type="submit" name="submit" value="Search"&gt;
&lt;/form&gt;



&lt;?php
require_once ("inc/conn.php");
if (isset($_POST["submit"])) {

$prop = $_POST['find'];
$query = "SELECT * FROM projdb WHERE property=$prop";
$result = mysql_query($query);
if (mysql_num_rows($result)==0){
echo "No Match Found";
}else{
while ($row = mysql_fetch_array($result)){
echo
// Main Table <br/>
'&lt;table border="1" width="950" bgcolor="87CEFA" &gt;'.
'&lt;td width="325" valign="top" &gt;'.
// Property Info Table <br/>
'&lt;table border="1" id="db"&gt;'.
'&lt;tr&gt;&lt;td&gt;Prop # :&lt;/td&gt;&lt;td bgcolor="FFFF66" width="95"&gt;'.$row['property'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;Name :&lt;/td&gt;&lt;td bgcolor="FFFF66" colspan="3" width="200"&gt;'.$row['propname'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;Street :&lt;/td&gt;&lt;td bgcolor="FFFF66" colspan="3" width="200"&gt;'.$row['address'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;City :&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['city'].'&lt;/td&gt;&lt;td&gt;State :&lt;/td&gt;&lt;td bgcolor="FFFF66" width="91"&gt;'.$row['state'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;Zip # :&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['zip'].'&lt;/td&gt;&lt;td&gt;Country :&lt;/td&gt;&lt;td bgcolor="FFFF66" width="91"&gt;'. $row['country'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;Phone # :&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['phone'].'&lt;/td&gt;&lt;td&gt;Fax # :&lt;/td&gt;&lt;td bgcolor="FFFF66" width="91"&gt;'.$row['fax'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;/table&gt;'.
// Room Info <br/>
'&lt;table border="1" id="db" width="200"&gt;'.
'&lt;tr&gt;&lt;td align="center" width="66"&gt;Wired&lt;/td&gt;&lt;td align="center" width="66"&gt;Wireless&lt;/td&gt;&lt;td align="center" width="66"&gt;Rooms&lt;/td&gt;&lt;/tr&gt;' .
'&lt;tr&gt;' .
'&lt;td align="center" bgcolor="FFFF66"&gt;'.$row['wired'].'&lt;/td&gt;' .
'&lt;td align="center" bgcolor="FFFF66"&gt;'.$row['wireless'].'&lt;/td&gt;' .
'&lt;td align="center" bgcolor="FFFF66"&gt;'.$row['rooms'].'&lt;/td&gt;' .
'&lt;/tr&gt;' .
'&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;' .
'&lt;td align="center"&gt;SL&lt;/td&gt;' .
'&lt;td align="center"&gt;Terminated&lt;/td&gt;&lt;td align="center"&gt;Non-SL&lt;/td&gt;' .
'&lt;/tr&gt;' .
'&lt;tr&gt;' .
'&lt;td align="center" bgcolor="FFFF66"&gt;' .
'&lt;input type="checkbox" name="maint" ' .(($row['maint'] == "1")? 'checked="checked"' : '' ).'/&gt;&lt;/td&gt;' .
'&lt;td align="center" bgcolor="FFFF66"&gt;' .
'&lt;input type="checkbox" name="term" ' .(($row['term'] == "1")? 'checked="checked"' : '' ).'/&gt;&lt;/td&gt;' .
'&lt;td align="center" bgcolor="FFFF66"&gt;' .
'&lt;input type="checkbox" name="nonsl" ' .(($row['nonsl'] == "1")? 'checked="checked"' : '' ).'/&gt;&lt;/td&gt;' .
'&lt;/tr&gt;'.
'&lt;/table&gt;'.
'&lt;/td&gt;'.
// ISP &amp; IP Info
'&lt;td valign="top" &gt;'.
'&lt;table border="1" width="520" id="db"&gt;'.
'&lt;tr&gt;&lt;td width="90"&gt;ISP :&lt;/td&gt;&lt;td bgcolor="FFFF66" width="115"&gt;'.$row['isp'].'&lt;/td&gt;&lt;td&gt;IP Address Type:&lt;/td&gt;&lt;td bgcolor="FFFF66" width="140"&gt;'.$row['iptype'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;Service Type:&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['isptype'].'&lt;/td&gt;&lt;td&gt;Primary IP Address:&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['ip'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;ISP #:&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['ispnum'].'&lt;/td&gt;&lt;td&gt;Subnet Mask:&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['subnet'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Gateway :&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['dg'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Primary DNS&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['pridns'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Secondary DNS&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['secdns'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;'.
'&lt;/table&gt;'.
// AAA &amp; HSG Info
'&lt;table border="1" id="db"&gt;'.
'&lt;tr&gt;&lt;td&gt;AAA Pw&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['aaapw'].'&lt;/td&gt;&lt;td&gt;HSG FW:&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['hsgfw'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;HSG Lic:&lt;/td&gt;&lt;td bgcolor="FFFF66"&gt;'.$row['hsglic'].'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;/table&gt;'.
'&lt;/td&gt;'.
// IP Monitor
'&lt;td valign="top"&gt;'.
'&lt;table border="1" id="db" width="50"&gt;'.
'&lt;tr&gt;&lt;td&gt;'. include "pinger.php" .'&lt;/td&gt;&lt;/tr&gt;'.
'&lt;/table&gt;'.
'&lt;/td&gt;'.

<i> </i> '&lt;/td&gt;'.
<i> </i> '&lt;/table&gt;';





}
}
}

mysql_close();

?&gt;



The //IP Monitor part is what im working on.

the pinger.php script is located here
<i>
</i>&lt;?php


function Ping(){
// false proxy used to generate connection error
$ProxyServer = $row['ip'];
$ProxyPort = 80;
$timeout=3;
//echo "Opening ProxyServer $ProxyServer&lt;br&gt;";
// must use next two statements
Set_Time_Limit(0); //Time for script to run .. not sure how it works with 0 but you need it
Ignore_User_Abort(True); //this will force the script running at the end

<i> </i> $handle = fsockopen($ProxyServer, $ProxyPort,$errno,$errstr,$timeout);
<i> </i> if (!$handle){
<i> </i> echo "&lt;img src='images/red.jpg'&gt;&lt;br&gt;";
<i> </i> return 0;
<i> </i> } else {
<i> </i> // copied method for PING like time operation
<i> </i> $status = socket_get_status($handle);
<i> </i> //echo "Opened ProxyServer $ProxyServer&lt;br&gt;";

<i> </i> //Time the responce
<i> </i> list($usec, $sec) = explode(" ", microtime(true));
<i> </i> $start=(float)$usec + (float)$sec;


<i> </i> $timeout=120;
<i> </i> stream_set_timeout($handle,$timeout);
<i> </i> //send somthing
<i> </i> ini_set('display_errors','0');
<i> </i> $write=fwrite($handle,"echo thisn");
<i> </i> if(!$write){
<i> </i> return 0;
<i> </i> }

<i> </i> //echo "Try To Read&lt;br&gt;";
<i> </i> stream_set_blocking($handle,0);
<i> </i> //Try to read. the server will most likely respond with a "ICMP Destination Unreachable" and end the read. But that is a responce!
<i> </i> fread($handle,1024);
<i> </i> fclose($handle);
<i> </i> echo "&lt;img src='images/green.jpg'&gt;&lt;br&gt;";
<i> </i> ini_set('display_errors','1');

<i> </i> //Work out if we got a responce and time it
<i> </i> list($usec, $sec) = explode(" ", microtime(true));
<i> </i> $laptime=((float)$usec + (float)$sec)-$start;
<i> </i> if($laptime&gt;$timeout)
<i> </i> return 0;
<i> </i> //else
<i> </i> // $laptime = round($laptime,3);
<i> </i> return $laptime;
<i> </i> }
}

// must use ErrorHandler to avoid php error being printed to screen
function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
{
// you can set this to what ever you like.
//echo "In Error Handler&lt;br&gt;";
return 0;
}

$old_error_handler = set_error_handler("userErrorHandler");

$time = Ping();
//echo "Time=n$time&lt;br&gt;";
//echo "Done Checking&lt;br&gt;";

?&gt;
Copy linkTweet thisAlerts:
@NightShift58Dec 24.2006 — I think you're including the script successfully but after a very brief check, I don't see where you're doing anything with the the returned value. You're storing the result of Ping() to $Time and that's it.

You may want to echo that.
Copy linkTweet thisAlerts:
@prophitauthorDec 24.2006 — If i set a manual IP in the pinger.php script and load that in my browser it works fine

$ProxyServer = "192.168.0.100";

But doesnt work with the

$ProxyServer = $row['ip'];

Not sure why..
Copy linkTweet thisAlerts:
@prophitauthorDec 24.2006 — im going to rewrite the pinger script actually..
Copy linkTweet thisAlerts:
@NightShift58Dec 24.2006 — Where does:[code=php]$ProxyServer = $row['ip'];[/code]come from?

I think you have to declare [B]global $row;[/B] in your Ping() function, so that the value will be made available from the main/calling script.

Since $row['ip'] is the only variable used from outside the function, you could pass that value to the function as a parameter - which would make the function Ping() more "portable".
×

Success!

Help @prophit spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...