Welcome Guest, Not a member yet? Register   Sign In
CI from command line. $_SERVER['SCRIPT_NAME'] not populated.
#1

[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.
#2

[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. :-(
#3

[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.
#4

[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.va...server.php.
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB