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

2
  • does your functions.php have white space after the ?> ? Commented Jun 9, 2017 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 Commented Jun 9, 2017 at 16:58

1 Answer 1

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?

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

1 Comment

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" ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.