I am running a PHP script via linux cronjob and I want to make sure that it can be run remotely only from the computer whose ip address I specify, plus via cronjob.
Now, I can check the remote ip addresses from $_SERVER['REMOTE_ADDR']
, but doing so would also stop execution via cronjob.So, how to make both things work?
确保php脚本仅在本地运行
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- dongliehuan3925 2013-02-13 09:48关注
You'll need to check if it is run from the command-line too to handle the cron case
if (php_sapi_name() == 'cli' || $_SERVER['REMOTE_ADDR'] == 'your.ip.add.ress') { // allow }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报