Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:45:54+00:00 2026-05-25T15:45:54+00:00

how to create user authentication in php just the same way when we try

  • 0

how to create user authentication in php just the same way when we try to login to a router.

enter image description here

when i enter the url for example http://www.example.com/portal there should be a prompt like the above image asking username and password.

what type of authentication is this. how to code that in php.

NOTE: i have to full control of the server that i run. so is there any special module that needs to be installed i can do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:45:54+00:00Added an answer on May 25, 2026 at 3:45 pm

    This is called Basic Auth. See this example from the documentation:

    <?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>";
    }
    ?>
    

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

    Essentially, you send the right headers with the status code of 401 Unauthorized. the browser sees this along with your WWW-Authenticate header and prompts the user for you. Once this is done, you are able to see the username and password in $_SERVER['PHP_AUTH_USER'] as well as $_SERVER['PHP_AUTH_PW'].

    You should know though that if you are using basic auth, the username/password are sent plaint-text. You must use HTTPS if you want any sort of security. Also, depending on your application, you will see that there is no way to effectively “log out”. Most browsers remember the username/password for the entire session, and send it with every subsequent request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a safe user authentication system. The code is from http://net.tutsplus.com/tutorials/php/simple-techniques-to-lock-down-your-website/
I would create a login authentication using php, The requirement is : one username
I have created a user login page and am using Forms Authentication. Users are
I'm trying to create user profiles for my site where the URL is something
Consider this T-SQL: CREATE USER my_test_user WITHOUT LOGIN; SELECT USER_NAME(), USER, SUSER_SNAME(),SYSTEM_USER, suser_name(); EXECUTE
I'd like to use this method to create user-friendly URL. Because my site is
I'm trying to create an authentication mechanism for my PHP Application and I'm having
I'm using the popular restful authentication app/tutorial found here: http://railsforum.com/viewtopic.php?pid=74245#p74245 I have been using
I am trying to create authentication for my php website. I am using the
I have the following PHP code which simply grabs a URL behind HTTP-Basic authentication

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.