why can''t I session_start() from a PHP CLI application with hashbang?
for example this:
--- beginning of page ---
it says output/headers already output, cannot send session cookie etc. etc. - you've seen the message before.
Is it possible I have a \n\r between -q and <?php ?? I have to have the hashbang at the top, so what am I supposed to do here? I can't ob_start() before the hashbang either.
I'm thinking there is a solution to this - I realize with a CLI executable I really don't "start" a session with a cookie but it would be nice to not change my coding for a bunch of scripts..
Hey! You may have inadvertently stumbled onto some genius there! :-)
From the manual:
"To use cookie-based sessions, session_start() must be called before outputing anything to the browser. "
How are you calling the script? Assuming it's marked executable, you'd just call it by nameI generally pass the file to the PHP interpreter explicitly, myself (i.e., no shebang).
Of course, I'm wondering in what context having session data in a command-line script would mean anything anyway: as soon as the script completed that would be the end of the session.
Last edited by Weedpacket; 11-23-2012 at 03:38 AM.
Would it not be easier to simply have two separate ini files and use the web ini file to set the auto_prepend_file directive to a file containing "session_start();"?
To use cookie-based sessions, session_start() must be called before outputing anything to the browser.
This function sends out several HTTP headers depending on the configuration. See session_cache_limiter() to customize these headers.
I really doubt you will be able to make sessions work in CLI (even if "work" simply means allow the rest of the script to run).
A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.
Or in what context one would need a shebang in a script hosted by a web server.
Originally Posted by Weedpacket
That's not much of a mystery, really... reminds me of the good ol' /cgi-bin/. Throw in a script that is to be parsed by any program you like (perhaps even one you create) - it doesn't matter, because the webserver doesn't care. It just executes the script as it would any shell script and passes along the output to the user.
Originally Posted by sneakyimp
Settled 4 red convertible
NET 1, PERL 2?
Originally Posted by bradgrafelman
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread