Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Ping Script | Newbie Confusion

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Ping Script | Newbie Confusion

Postby mikeincousa » Wed Jun 26, 2013 8:57 pm

I'm a brand new to php, and very rusty with programming techniques (forty years rusty roughly).

I took a script from Beginnng Php and MySQL From Novice to Professional, pg 348, Pinging a server.
I embeded it an HTML page and set the permissions to 777. I have also tried to run it as a script without an HTML frame. When I call the script page from my Bluehost account, the page returns blank. They state the system() command has not been locked out. I tried to vailidate the code. One validator stalled forever and the other tagged several items with ?? I have tried this as *.php and *.html. The html version simply echoes the code. A search returns the exact same code from another source, but I could not get that to run either. The error log shows [26-Jun-2013 21:58:22] PHP Parse error: syntax error, unexpected '>'

I am so so new I can't help but suspect I've missed a very basic idea somewhere.

My goal here is cutting through the muck at PayPal and effectively engaging IPN and PDT scripts. I am slowly figuring out those php basics.

Pinging their server seems like it should be the first step.

Thank for guidance and any needed hand-holding.
===
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>ping.5.php</title>
</head>
<body>
<?php

$server = "www.example.com";

$count = 3;

echo "<pre>";
system("/bin/ping -c $count $server");
echo "</pre>";

system("killall -q ping");

?>

</body>
</html>
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm

Re: Ping Script | Newbie Confusion

Postby johnj » Wed Jun 26, 2013 9:44 pm

....They state the system() command has not been locked out.....


If the system command is locked then you need to change it (if you have the permissions) or take the help of the system admin.

Also, you may try this modified version:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>ping.5.php</title>
</head>
<body>
<?php

$server = "www.example.com";

$count = 3;

echo "<br /> Start of this script";
echo "<pre>";
$output = system("/bin/ping -c $count $server",$retval);
echo "</pre>";

system("killall -q ping", $retval);
echo '<br />Output: ' . $output . '
echo '<br />Return value: ' . $retval;
echo "<br/>End of this script";
?>

</body>
</html>
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Ping Script | Newbie Confusion

Postby mikeincousa » Thu Jun 27, 2013 5:27 pm

I think you missed the "not" in my original post.

Bluehost says they have NOT locked out system or like drop to shell commands.

But if there is way to test that claim, that test might be worth a trial.
==============================
I cut and pasted the revised version.
The results are at http://improve-my-english.org/ping8.html
And here is that rendering.
******************************************************
Start of this script"; echo "

";
$output = system("/bin/ping -c $count $server",$retval);
echo "

"; system("killall -q ping", $retval); echo '
Output: ' . $output . ' echo '
Return value: ' . $retval; echo "
End of this script"; ?>
******************************************************************

Have I messed something up?
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm

Re: Ping Script | Newbie Confusion

Postby johnj » Thu Jun 27, 2013 8:19 pm

You need to save that revised version as ping8.php and not as ping8.html
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Ping Script | Newbie Confusion

Postby mikeincousa » Tue Jul 02, 2013 3:16 pm

Am I still missing something?

_
I saved the file as *.php but it seems to still have some problems.
[02-Jul-2013 16:14:52] PHP Parse error: syntax error, unexpected '>' in /home2/improvh9/public_html/ping.johnj.php on line 21
******************
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>ping.5.php</title>
</head>
<body>
<?php

$server = "www.example.com";

$count = 3;

echo "<br /> Start of this script";
echo "<pre>";
$output = system("/bin/ping -c $count $server",$retval);
echo "</pre>";

system("killall -q ping", $retval);
echo '<br />Output: ' . $output . '
echo '<br />Return value: ' . $retval;
echo "<br/>End of this script";
?>

</body>
</html>
********************
*********************
This next version seems to work save for capturing the ping values. It did not throw any errors.
************
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>ping.11.php</title>
</head>
<body>
<pre>
<?php
$server = "www.example.com";
$count = 3;
echo "<br />Start of this script";
$output = system("/bin/ping -c $count $server",$retval);
system("killall -q ping", $retval);
echo '<br />Output value: ' . $output;
echo '<br />Return value: ' . $retval;
echo "<br/>End of this script"
?>
</pre>
</body>
</html>
***************
Start of this script
Output value:
Return value: 1
End of this script
*****************
An aside, the Php from Novice to .... ping code puts the "<pre>" inside the script, while the system() example in hp Functions Essential Reference puts them outside the script (p. 473).

I'll go over some of the hits in response “ping a server using php” next time.

Thanks for any further thoughts.
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm

Re: Ping Script | Newbie Confusion

Postby johnj » Wed Jul 03, 2013 5:41 am

If the output is empty then it means your system command failed. Try to give the exact same command from the command prompt and see what is the output.

The '<pre>' is a formatting HTML tag. Outside the php script you can use the tag in a straight forward manner but inside the script you will have to echo it as a string.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Ping Script | Newbie Confusion

Postby westwade » Wed Jul 03, 2013 10:07 pm

The secret is coach online outlet store not in whether it is a good buy or not, but in getting the information and techniques right. Usually, when you've got the system all figured out, you know the seller will call you - which means, you have ample time to go down and check coach outlet online applications out the land before offering a suitable price for the land.
RS 2007 Gold
rs money
westwade
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Jul 03, 2013 9:31 pm

Re: Ping Script | Newbie Confusion

Postby mikeincousa » Thu Jul 04, 2013 3:47 pm

Thanks for your inputs.

Bluehost support helped me find my way to their command line via the SSH connection.
Contrary to their earlier statments "ping" is not allowed, but "traceroute" is.

***********************************
improvh9@improve-my-english.org [~]# ping example.com
ping: icmp open socket: Operation not permitted

improvh9@improve-my-english.org [~]# traceroute example.com
1 * * *
2 port100.ar01.prov.acedc.net (199.58.199.113) 24.624 ms 24.621 ms 24.606 ms
3 tg1-1.br02.lsan.acedc.net (199.58.196.82) 22.711 ms 22.726 ms 22.712 ms
4 eqx-ix.icann.org (206.223.123.86) 14.819 ms 14.894 ms 14.787 ms
5 43-10.any.icann.org (192.0.43.10) 14.845 ms 14.694 ms 14.773 ms
******************************************************

I tried modifying the code to show the traceroute output, but I did not succeed.
I removed what I thought were all the ping related commands and replaced them with traceroute. The screen went blank when I tried to run it.
Should I go back to putting the </pre tags backt they way there were inside the script and in quotes?

Any suggestions?
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm

Re: Ping Script | Newbie Confusion

Postby johnj » Thu Jul 04, 2013 8:25 pm

the <pre> and </pre> tags are html tags and have nothing to do with your ping and traceroute commands.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Ping Script | Newbie Confusion

Postby johnj » Thu Jul 04, 2013 8:27 pm

please post the script that you used for traceroute so that we can take a look at it.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Ping Script | Newbie Confusion

Postby mikeincousa » Wed Jul 10, 2013 9:41 am

Thanks again for your reply. Sorry for my delay in responding to your question. "Life" trigged a subroutine that branched me away :).
===
I did not use a script.

After connecting through SSH and gaining access to the Bluehost command line, I recall now all I needed was #traceroute example.com. That generated the pasted response.

Given #ping can NOT be accessed from the hosted account, I redefined my immediate goals for driving a command from a script and capturing the output.

In studying string basics I happened on a basic example in a discussion of backticks.

It deploys a routine that returns the server system date. It looks simpler and should provide a teething exercise for other system() scripting such as traceroute captures. Namely, $result = 'date';.....with further discussion of shell_exec() as an alternate to system().

These will anchor my next attempts at project.

The final goal now is building skills for scripting shell commands and capturing the output of them.

But please let me know of your suggestions for the traceroute captures and I will blend them into the mix.

Thanks again.
mikeincousa
New php-forum User
New php-forum User
 
Posts: 8
Joined: Wed Jun 26, 2013 8:17 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 10 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron