Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-28-2006, 04:12 PM   #1
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49

Rep: Reputation: 15
Apache And Iptables - Help Please

i am trying to generate a script that will input an ip address "" and output the results. The following code works fine if i declare the ip address in the code, but if i want to include it as a string it doesnt work?

#$ip = $_POST['ip_address_dia'];

exec('ping -c 4', $cmdOutput);
foreach ($cmdOutput as $outputLine) {
echo $outputLine;

#header ("Location: Diagnostic.php");

If i change it to include the string:
exec('ping -c 4 '$ip'', $cmdOutput);

this is the error i get:
Parse error: parse error, unexpected T_VARIABLE in /var/www/html/Diagnostic_session.php on line 4

could someone help me out, i would release appriciate it.

Old 04-28-2006, 06:32 PM   #2
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
Instead of
PHP Code:
exec('ping -c 4 '$ip''$cmdOutput); 
PHP Code:
exec("ping -c 4 $ip"$cmdOutput); 
Variables inside single-quotes aren't interpolated, so your original code would be like literally asking the system to

ping -c 4 $ip

Variables inside double-quotes get interpolated, so the suggested code would be (assuming $ip is assigned, e.g.,

ping -c 4


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
php and iptables using APACHE Richtown Linux - Newbie 13 04-22-2006 06:51 AM
Help with apache virtual hosts (and iptables too) dhbiker Linux - Software 8 12-07-2005 11:46 AM
Dynamic ip and Apache with iptables props666999 Linux - Security 4 09-28-2005 04:08 AM
iptables for apache bobbens Debian 6 03-11-2005 09:21 AM
apache iptables inq. Robin01 Linux - Newbie 1 10-04-2003 11:53 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration