0

I'm trying to run a php script through ssh doing that:

 /usr/bin/php "/path/to/the/script.php"

But it gives errors that won't happen running the script from a web browser. For example if I have:

<?
include("functions.php");
SetCookie("mycookie",1);
?>

It will say it can't set cookie because the headers are already sent by functions.php at line 100 which is the last line. Also it displays the script content before showing the errors (don't know if it's normal).

So why I don't get the same thing with command line and apache ? Thanks

Entretoize
  • 2,124
  • 3
  • 23
  • 44
  • does your `functions.php` have white space after the `?>` ? – WheatBeak Jun 09 '17 at 16:57
  • what if you try something more general then setting a cookie? try to echo a string or something. Im betting that it cant set the cookie because the context of the application doesnt have access to cookies because the php file isnt running on a server. Just a guess tho – victor Jun 09 '17 at 16:58

1 Answers1

0

Cookies are sent by the browser, you can't use them in the command line. More details here: Is it possible to read cookie/session value while executing PHP5 script through command prompt?

Juan Techera
  • 1,192
  • 2
  • 14
  • 25
  • I could explain the error. Can you explain the error message ? Maybe because php just tries to set the cookie as if it executed "from the web" ? – Entretoize Jun 09 '17 at 19:26