582033
V2EX  ›  问与答

如何判断 php 当前是否以脚本方式执行?

  •  
  •   582033 · Nov 3, 2014 · 5078 views
    This topic created in 4242 days ago, the information mentioned may be changed or developed.
    问题有2:

    1.如何判断当前php文件是以web方式运行还是作为脚本执行的呢?

    2.这个问题应该怎么表述的更专业一些呢?
    7 replies    2014-11-03 16:56:10 +08:00
    pimin
        2
    pimin  
       Nov 3, 2014   ❤️ 1
    php_sapi_name()
    582033
        3
    582033  
    OP
       Nov 3, 2014
    CoX
        4
    CoX  
       Nov 3, 2014
    PHP_SAPI === 'cli' OR defined('STDIN')
    julyclyde
        5
    julyclyde  
       Nov 3, 2014   ❤️ 1
    @CoX CGI也有stdin吧

    lz所谓的“以脚本方式”本身就不是个明确正确的说法
    tabris17
        6
    tabris17  
       Nov 3, 2014
    命令行方式运行 or CGI方式运行
    582033
        7
    582033  
    OP
       Nov 3, 2014
    @julyclyde thx,所以才有了问题2
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5868 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 06:08 · PVG 14:08 · LAX 23:08 · JFK 02:08
    ♥ Do have faith in what you're doing.