Search code examples
phpweb-servicesphp-5.3http-authentication

scope of server variables in php


As we know that session variable $_SESSION is different for each user. I want to know the scope of Server variable like $_SERVER. I am doing http authentication in my RestFul API. If I set the $_SERVER['PHP_AUTH_USER'], will that be set for 1 user or all the user who access my server page?

Thanks


Solution

  • That will be set only for current user, but why don't you use $GLOBALS instead of $_SERVER?

    $GLOBALS — References all variables available in global scope

    This superglobal array would be more appropriate than $_SERVER for such a task. Mind, that $GLOBALS or $_SERVER don't save its data after request is finished. So if you want to keep some data from one request to another you should use $_SESSION.