Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP, cURL, Sessions and Cookies - Oh my
    text
    copied!<p>I wrote a PHP web application which uses authentication and sessions (no cookies though). All works fine for the users in their browsers. At this point though I need to add functionality which will perform a task automatically... users don't need to see anything and can't interact with this process. So I wrote my new PHP, import.php, which works in my browser. I set up a new cron job to call 'php import.php'. Doesn't work. Started Googling and it seems maybe I need to be using cURL and possibly cookies but I'm not certain. Basically import.php needs to authenticate and then access functions in a separate file, funcs.php, in the same directory on the local server. So I added cURL to import.php and reran from the command line; I see the following:</p> <pre><code>[me@myserver]/var/www/html/webapp% php ./import.php * About to connect() to myserver.internal.corp port 443 (#0) * Trying 192.168.111.114... * connected * Connected to myserver.internal.corp (192.168.111.114) port 443 (#0) * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * Remote Certificate has expired. * SSL certificate verify ok. * SSL connection using SSL_RSA_WITH_3DES_EDE_CBC_SHA * Server certificate: * subject: CN=dept,O=Corp,L=Some City,ST=AK,C=US * start date: Jan 11 16:48:38 2012 GMT * expire date: Feb 10 16:48:38 2012 GMT * common name: myserver * issuer: CN=dept,O=Corp,L=Some City,ST=AK,C=US &gt; POST /webapp/import.php HTTP/1.1 Host: myserver.internal.corp Accept: */* Content-Length: 356 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------2c5ad35fd319 &lt; HTTP/1.1 100 Continue &lt; HTTP/1.1 200 OK &lt; Date: Thu, 27 Dec 2012 22:09:00 GMT &lt; Server: Apache/2.4.2 (Unix) OpenSSL/0.9.8g PHP/5.4.3 &lt; X-Powered-By: PHP/5.4.3 * Added cookie webapp="tzht62223b95pww7bfyf2gl4h1" for domain myserver.internal.corp, path /, expire 0 &lt; Set-Cookie: webapp=tzht62223b95pww7bfyf2gl4h1; path=/ &lt; Expires: Thu, 19 Nov 1981 08:52:00 GMT &lt; Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 &lt; Pragma: no-cache &lt; Content-Length: 344 &lt; Content-Type: text/html &lt; * Connection #0 to host myserver.internal.corp left intact * Closing connection #0 </code></pre> <p>I'm not sure what I'm supposed to do after I authenticate via cURL. Or is there an alternate way to authenticate with which I don't use cURL? Currently all pages in the web app take action (or not) based on $_SESSION and $_POST value checks. If cURL is the only way, do I need cookies? If I need cookies, once I send it back to the server why do I need to do to process it?</p> <p>Basically import.php checks for and reads files from the same directory. Supposing there are files when the cron runs and parses them and inserts data into the DB. Again, everything works in the browser, just not the import from the command line.</p> <p>Having never done this before (or much PHP for that matter), I'm completely stumped.</p> <p>Thanks for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload