Philip Kirkbride
Philip Kirkbride

Reputation: 22859

Shell command not working via exec() in php

I'm executing a php function via the PHP exec() function but it seems to only pass through 1 variable at time.

$url = "http://domain.co/test.php?phone=123&msg=testing"
exec('wget '.$url);

Within test.php file I have

$msg = "msg =".$_GET["msg"]." number=".$_GET["phone"];
mail('[email protected]', 'Working?', $msg);

I get an email which returns phone variable only.

But if I change the url as follows

$url = "http://domain.co/test.php?msg=testing&phone=123"

I get msg but not phone? Any ideas on what is causing this strange behavior?

Upvotes: 0

Views: 146

Answers (2)

Eun
Eun

Reputation: 4178

$url = "http://domain.co/test.php?phone=123&msg=testing"
exec('wget "'.$url.'"');

you need to qoute the url


& is the sign for putting a task into background

Upvotes: 1

We Are All Monica
We Are All Monica

Reputation: 13336

The & sign is a special character in the Unix shell. You need to escape it:

exec("wget '$url'");

Also, if your URL is based on user input in any way, be very careful to escape it with escapeshellarg. Otherwise your users will be able to run arbitrary Unix commands on your server.

Upvotes: 4

Related Questions