Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass username and password in URL to PHP page?

I have deployed a simple PHP-based application (http://www.bigprof.com/appgini/) on my local network. I would like a way to implement a way for users to automatically log in. Security is a non-issue. Would it be possible to modify the login page to accept something like http://user:[email protected]/?

This is the source of the login page, if that helps.

Any help would be greatly appreciated.

like image 268
AaronJAnderson Avatar asked Nov 06 '25 14:11

AaronJAnderson


1 Answers

HTTP Basic Auth credentials are available in PHP in the $_SERVER superglobal in the keys PHP_AUTH_USER and PHP_AUTH_PW.

From http://php.net/manual/en/features.http-auth.php

if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Text to send if user hits Cancel button';
    exit;
} else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>You entered {$_SERVER['PHP_AUTH_PW']} as your password.</p>";
}

For more sophisticated ways of doing authentication check out

  • http://pear.php.net/package/Auth or
  • http://framework.zend.com/manual/en/zend.auth.html
like image 165
Gordon Avatar answered Nov 09 '25 08:11

Gordon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!