CodeIgniter Forums
CI from command line. $_SERVER['SCRIPT_NAME'] not populated. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CI from command line. $_SERVER['SCRIPT_NAME'] not populated. (/showthread.php?tid=14565)



CI from command line. $_SERVER['SCRIPT_NAME'] not populated. - El Forum - 01-07-2009

[eluser]srisa[/eluser]
Hello,

I am making use of the technique posted here to invoke some CodeIgniter scripts from the command line. In the controller which is being invoked I am using $_SERVER['SCRIPT_NAME'] to make sure that the calling script is indeed script for command line tasks.
On my local development environment (Win XP, php 5.2.0, apache 2.2.8) $_SERVER['SCRIPT_NAME' and $_SERVER['PHP_SELF'] are populated but on hosting environment (Linux Red hat 3.4.6, php 5.0.4, apache 1.3.33) $_SERVER['PHP_SELF'] is empty and $_SERVER['SCRIPT_NAME'] is not set. As per the comparison posted here $_SERVER['SCRIPT_NAME'] is set for apache. Why is this difference in the $_SERVER array?

I am planning to use $_SERVER[argv][0] to verify the calling script. Will that be okay?

Thank you.


CI from command line. $_SERVER['SCRIPT_NAME'] not populated. - El Forum - 01-07-2009

[eluser]Phil Sturgeon[/eluser]
You can do. There are several different ways to check if PHP is called via command line or the browser. I always use $_SERVER['REQUEST_URI'] but it doesn't really matter.

Just do a print_r($_SERVER) and see what you have to work with. $_SERVER[argv][0] will always be the file name anyway.

Edit: Annoyed with the poster of that blog article, his way of getting CI on the command line is better. :-(


CI from command line. $_SERVER['SCRIPT_NAME'] not populated. - El Forum - 01-23-2009

[eluser]awells527[/eluser]
I have found that $_SERVER['REMOTE_ADDR'] is populated with the script is called in the browser, but not when called from the command line.

If you are wanting to know how the script is called from one of your controllers, check for the existence of the 'CMD' constant if you are using the code from the blog article.


CI from command line. $_SERVER['SCRIPT_NAME'] not populated. - El Forum - 01-23-2009

[eluser]Phil Sturgeon[/eluser]
Lots of the $_SERVER items are specific to web server or command line, they are not all in both. Take a look at http://www.php.net/manual/en/reserved.variables.server.php.


CI from command line. $_SERVER['SCRIPT_NAME'] not populated. - El Forum - 01-25-2009

[eluser]srisa[/eluser]
Thanks @awells527, i missed the CMD constant completely. That is one thing that won't fail. Thanks to @pyromaniac too.