LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 15
Apache And Iptables - Help Please


Hi,
i am trying to generate a script that will input an ip address "www.google.com" 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?

<?php
#$ip = $_POST['ip_address_dia'];

exec('ping -c 4 www.google.com', $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.

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

Rep: Reputation: 30
Instead of
PHP Code:
exec('ping -c 4 '$ip''$cmdOutput); 
try
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., 1.2.3.4)

ping -c 4 1.2.3.4
 
  


Reply


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 07:51 AM
Help with apache virtual hosts (and iptables too) dhbiker Linux - Software 8 12-07-2005 12:46 PM
Dynamic ip and Apache with iptables props666999 Linux - Security 4 09-28-2005 05:08 AM
iptables for apache bobbens Debian 6 03-11-2005 10:21 AM
apache iptables inq. Robin01 Linux - Newbie 1 10-04-2003 12:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:42 AM.

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