Jump to content

Trouble with variable insertion in backticked curl command


dwest100

Recommended Posts

When this code runs in my php file...

 

`curl https://inklines.art/process_emails.php?url={$full_site_url}&domain={$domain}&site={$site_title}&title={$title}&permalink={$permalink}`;
 
This is all that is sent to the shell:

 

https://MYSITE.COM/process_emails.php?url={$full_site_url}
 
What am I doing wrong in building the command??
Link to comment
Share on other sites

Obviously, I have reasons or I would not have bothered posting here.

The two isolated strings are within my php code.

To make a long story short, I am running the curl command to execute a separate php emailing process outside of my Wordpress site whenever there is a new post. There are 5000+ subscribers each getting an email notification. This technique will let them process in the background...safely.

 

It's no more unsafe than Wordpress site itself.

 

So can you simply answer the question? Which is about syntax I believe?

Link to comment
Share on other sites

I'm not sure if you thought I was attacking you or something, but from my point of view I was wondering why you were using shell commands to do something that's possible with native PHP. You gave an answer that makes sense. End of story.

 

escapeshellarg

 

Construct the URL as one complete string and escape the whole value for the command. I'd ask if you already prepared the assorted variables for use as query strings, since that's something you have to consider, but that might offend you so I won't.

$url = escapeshellarg("https://inklines.art/process_emails.php?url={$full_site_url}&domain={$domain}&site={$site_title}&title={$title}&permalink={$permalink}");
Link to comment
Share on other sites

Good answer! After much searching and sifting on Google this works very simply:

 

`curl "MY_WEBSITE.com/process_emails.php?url={$full_site_url}&domain={$domain}&site={$site_title}&title={$title}&permalink={$permalink}"`;
Enclose entire php command string in backticks —same as typing shell_exec(command string)—

 

Enclose entire argument to curl command in double quotes so the shell interprets the ENTIRE command.

 

Enclose variables in

{}
instead of concatenating. Simpler and easier to read.

 

The shell was halting the command after the first

&
because that's what the
&
does in the linux shell.

With the entire string interpreted, it works properly and all 5000 emails are processed outside of my Wordpress site through Amazon SES all nice and tidy and properly authorized with DKIM, SPF and encryption.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.