Rednarb Posted January 3, 2008 Share Posted January 3, 2008 Looking for suggestions on how to have a script check that it is being run from the command line instead of from a browser. I want it to be able to bail on the script if for some reason it gets hit with a browser. TIA, Eric Quote Link to comment https://forums.phpfreaks.com/topic/84383-solved-command-line-only/ Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 WHAT? do you mean you want php to run in command line for users to use the application but running in command line only........ are you talking about creating a shell program with php and users got to telnet to use the shell program? example an old bulition board Quote Link to comment https://forums.phpfreaks.com/topic/84383-solved-command-line-only/#findComment-429778 Share on other sites More sharing options...
awpti Posted January 3, 2008 Share Posted January 3, 2008 Check for $_SERVER['SHELL'] This is not set via browser, only via shell. Also, none of the $_SERVER['HTTP_***'] values are set when run via the console either. Don't rely on those though. $_SERVER['SHELL'] should be checked for a value (/bin/bash or whatever the default shell is). if it's set, you're good. Quote Link to comment https://forums.phpfreaks.com/topic/84383-solved-command-line-only/#findComment-429798 Share on other sites More sharing options...
Rednarb Posted January 3, 2008 Author Share Posted January 3, 2008 WHAT? do you mean you want php to run in command line for users to use the application but running in command line only........ are you talking about creating a shell program with php and users got to telnet to use the shell program? example an old bulition board No no, not so devious as that! I simply have a php script that does some daily reporting that I want to run, and without going into too much detail as to why, its in a location where it could be accessible from a browser. This is all internal use, not on the Internet, so I'm not too concerned with security.. but just in case someone (like another administrator after I get hit by a bus) tries to run the .php from a browser then the script dies saying it can't run that way. I recall seeing a way to do it a long time ago... I think it checked some sort of $_SERVER variable and if it equaled ~something~ that meant it was the web service or a browser running it then it would die. I don't want to reinvent the wheel but I can't seem to find it anywhere so I thought I'd post here for suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/84383-solved-command-line-only/#findComment-429800 Share on other sites More sharing options...
Rednarb Posted January 3, 2008 Author Share Posted January 3, 2008 Check for $_SERVER['SHELL'] This is not set via browser, only via shell. Also, none of the $_SERVER['HTTP_***'] values are set when run via the console either. Don't rely on those though. $_SERVER['SHELL'] should be checked for a value (/bin/bash or whatever the default shell is). if it's set, you're good. Exactly what I needed! THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/84383-solved-command-line-only/#findComment-429804 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.