Login / Password

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FP

    #1

    Login / Password

    I want to put some code at the top of my pages which will prompt the
    user for a name & password if the session variable IDUser is not set.

    How do I get the browser to display the login / password dialog and how
    do I access the data the user entered.

    Can I put the code that gets the login / password in a page of it's own
    and have the browser call that page when the IDUser isn't set, and if
    so how do I do it eg.
    <?
    session_start() ;
    If($_SESSION['IDUser']==''){
    //how do I tell it to do the authentication page
    }else{
    //rest of my code
    } ?>


    Once the user entered a login / password and I set the IDUser on the
    authentication page, how do I tell it to resume loading the original
    page (the one that had the above mentioned code on it)?

  • Rik

    #2
    Re: Login / Password

    FP wrote:
    I want to put some code at the top of my pages which will prompt the
    user for a name & password if the session variable IDUser is not set.
    >
    How do I get the browser to display the login / password dialog and
    how do I access the data the user entered.


    Grtz,
    --
    Rik Wasmus


    Comment

    • Sheldon Glickler

      #3
      Re: Login / Password

      Look into header("Locatio n: foo.php");

      Go to the login page if not set. Upon success, go to this page.

      Shelly


      "FP" <ad@pottnercons ulting.cawrote in message
      news:1153161943 .943170.185580@ h48g2000cwc.goo glegroups.com.. .
      >I want to put some code at the top of my pages which will prompt the
      user for a name & password if the session variable IDUser is not set.
      >
      How do I get the browser to display the login / password dialog and how
      do I access the data the user entered.
      >
      Can I put the code that gets the login / password in a page of it's own
      and have the browser call that page when the IDUser isn't set, and if
      so how do I do it eg.
      <?
      session_start() ;
      If($_SESSION['IDUser']==''){
      //how do I tell it to do the authentication page
      }else{
      //rest of my code
      } ?>
      >
      >
      Once the user entered a login / password and I set the IDUser on the
      authentication page, how do I tell it to resume loading the original
      page (the one that had the above mentioned code on it)?
      >

      Comment

      • clashers5@gmail.com

        #4
        Re: Login / Password

        I've always done somthing like this:

        At the begining of your secure scripts
        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        // Start the sesion
        session_start() ;

        // Check for login
        if(!isset($_SES SION["IDUser"])){
        $page = urlencode($_SER VER["REQUEST_UR I"]);
        exit("<script>w indow.location. href='login.php ?page=$page</script>");
        }

        // Secured code goes here
        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


        On your login.php page
        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
        // Code used to authenticate

        // On authentication, go to passed page
        exit("<script>w indow.location. href='".$_GET["post"]."'</script>");
        =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

        HTH

        Sheldon Glickler wrote:
        Look into header("Locatio n: foo.php");
        >
        Go to the login page if not set. Upon success, go to this page.
        >
        Shelly
        >
        >
        "FP" <ad@pottnercons ulting.cawrote in message
        news:1153161943 .943170.185580@ h48g2000cwc.goo glegroups.com.. .
        I want to put some code at the top of my pages which will prompt the
        user for a name & password if the session variable IDUser is not set.

        How do I get the browser to display the login / password dialog and how
        do I access the data the user entered.

        Can I put the code that gets the login / password in a page of it's own
        and have the browser call that page when the IDUser isn't set, and if
        so how do I do it eg.
        <?
        session_start() ;
        If($_SESSION['IDUser']==''){
        //how do I tell it to do the authentication page
        }else{
        //rest of my code
        } ?>


        Once the user entered a login / password and I set the IDUser on the
        authentication page, how do I tell it to resume loading the original
        page (the one that had the above mentioned code on it)?

        Comment

        • FP

          #5
          Re: Login / Password

          Rik wrote:
          FP wrote:
          I want to put some code at the top of my pages which will prompt the
          user for a name & password if the session variable IDUser is not set.

          How do I get the browser to display the login / password dialog and
          how do I access the data the user entered.
          >

          >
          Grtz,
          --
          Rik Wasmus

          I had a look at the manual and it's clear as mud.
          Tomorrow I'm going to try to put the following code in an include and
          call it from the different pages; it's currently working with 1 page.
          If anyone sees potential problems with it, could you please point them
          out.

          if ($_SESSION['IDUser']=='') {
          if (!isset($_SERVE R['PHP_AUTH_USER'])) {
          header('WWW-Authenticate: Basic realm="Demo"');
          header('HTTP/1.0 401 Unauthorized');
          exit;
          }
          //connect to database searching for record where
          Login = $_SERVER['PHP_AUTH_USER'];
          Pwd = $_SERVER['PHP_AUTH_PW'];
          if(no records found){
          header('WWW-Authenticate: Basic realm="Demo"');
          header('HTTP/1.0 401 Unauthorized');
          }else{
          $_SESSION['IDUser'] = database record ID
          }
          }

          Comment

          • Geoff Berrow

            #6
            Re: Login / Password

            Message-ID: <1153193066.107 423.267520@m79g 2000cwm.googleg roups.comfrom
            clashers5@gmail .com contained the following:
            exit("<script>w indow.location. href='login.php ?page=$page</script>");
            Fine but why rely on Javascript? Why not just do:

            header("Locatio n:login.php?pag e=$page");
            exit();

            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • william.clarke

              #7
              Re: Login / Password


              Geoff Berrow wrote:
              Message-ID: <1153193066.107 423.267520@m79g 2000cwm.googleg roups.comfrom
              clashers5@gmail .com contained the following:
              >
              exit("<script>w indow.location. href='login.php ?page=$page</script>");
              >
              Fine but why rely on Javascript? Why not just do:
              >
              header("Locatio n:login.php?pag e=$page");
              exit();

              Exactly what I was about to post, but Geoff beat me to it :)

              header("Locatio n:login.php?pag e=$page");
              will work no matter what Javascript settings the user has, while:

              exit("<script>w indow.location. href='login.php ?page=$page</script>");
              relies on the visitor's browser understanding javascript (not such a
              big problem these days) and on them allowing JavaScript redirects
              (which can still be a problem)

              Comment

              • clashers5@gmail.com

                #8
                Re: Login / Password

                Good point. Thank you

                william.clarke wrote:
                Geoff Berrow wrote:
                Message-ID: <1153193066.107 423.267520@m79g 2000cwm.googleg roups.comfrom
                clashers5@gmail .com contained the following:
                exit("<script>w indow.location. href='login.php ?page=$page</script>");
                Fine but why rely on Javascript? Why not just do:

                header("Locatio n:login.php?pag e=$page");
                exit();
                >
                >
                Exactly what I was about to post, but Geoff beat me to it :)
                >
                header("Locatio n:login.php?pag e=$page");
                will work no matter what Javascript settings the user has, while:
                >
                exit("<script>w indow.location. href='login.php ?page=$page</script>");
                relies on the visitor's browser understanding javascript (not such a
                big problem these days) and on them allowing JavaScript redirects
                (which can still be a problem)

                Comment

                Working...