0

Possible Duplicate:
Making variable from HTML-file work in PHP-file

I have another file (HTML-file) that passes an argument to this PHP-file. It does so I have checked it with "echo" and it throws back the same argument I wrote in the HTML-file, so so far, so good. The PHP-file looks like this.

<?
       $filepath = "/usr/sbin";
       exec("ONE $search -command $filepath ");
       fopen($filepath, "rw");
?>

The command "ONE" which is a bash-script I wrote to do some "greps" in files takes one argument and that is "$search" which in deed is passed over to this PHP-file. And if I exchange "$search" to the actual word "searchword" it works like a charm. Why doesn't it accept "$search" as argument? It just seem to ignore it and throws back a blank page, but if I use "searchword" it gives back just what I want.

11
  • 1
    Where do you define $search? Commented Sep 20, 2012 at 17:03
  • not a duplicate, it's an elaboration Commented Sep 20, 2012 at 17:17
  • it's defined as "name" in the HTML-file <form action="test.php" method="post"> Search for: <input type="text" name="search" /> <input type="submit" name="submit" value="Search" /> </form> Commented Sep 20, 2012 at 17:21
  • So you've defined it as $search = $_REQUEST["search"];, then? Commented Sep 20, 2012 at 17:25
  • Well, when I put a line echo($_POST['search']); it will throw up my "searchword" passed from the HTML-page, so the variable is there for sure, but it will not become the argument of my command:( Commented Sep 20, 2012 at 18:57

3 Answers 3

3

You have a syntax error in fopen (probably a transcription error).

Do you mean to use $_REQUEST['search'] as opposed to just $search? By "HTML-file that passes an argument to this PHP-file" I assume you mean via a link or asynchronous request of some kind. If that's the case, you should use escapeshellarg.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, what's an escapeshellarg?
0

Check this out:

exec("ONE {$search} -command {$filepath} ");

Does it work?

2 Comments

{$var} is used only when concatained with other chars. Such as echo "{$var}s";, avoiding PHP to search $vars variable instead of $var.
Nice tries all of you, but it seems impossible to get PHP to accept the variable as an argument to the command. It's a mystery.
0
exec("ONE $search -command $filepath ");

trailing space?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.