Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: I have a new code... now what?

  1. #21
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You can use the window.prompt(message) function.
    password = window.prompt("Please enter your password.");
    I'm not at home at the moment, I'll write you an example when I get back - if Mike or John hasn't got there first.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  2. #22
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    HTML Code:
    <script type="text/javascript">
    function getPass(url) {
     window.location.href = url + "?pass=" + urlencode(window.prompt("Please enter the password:"));
     return false;
    }
    </script>
    <a href="passcheck.php" onclick="getPass(this.href);">Go to password page</a>
    passcheck.php:
    PHP Code:
    <?php
    $pass 
    $_GET['pass'];
    if(
    $pass == "john") {
     
    // Do stuff
    } else {
    ?>
    <form method="get" action="<?=$PHP_SELF?>">
     <input type="text" name="pass"/><input type="submit" value="OK"/>
    </form>
    <?php ?>
    Enjoy.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #23
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    So if I understand right, I make the passcheck.php its own page, in its own folder, then I make the link to that and it will show up as a pop up box?

    Will this also protect the file I redirect to if you already know the URL?

    And I am guessing i need to add
    Code:
    <input type= "text" name= "user"/>
    As well as change the GET_ to include the username...

    the problem I have now is that if you KNOW the exact URL to the page I want to protect you can bypass this pop up box.

    I don't mind using the .htaccess, more what I want is to "make" my own, personalized, pop up box.

    will this code do that?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  4. #24
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Sort of.
    For a username as well, you'll need two popup prompts because of the limitations of window.prompt().
    HTML Code:
    <script type="text/javascript">
    function getPass(url) {
      window.location.href = url
        + "?user=" + urlencode(window.prompt("Please enter your username:"))
        +  "&pass=" + urlencode(window.prompt("Please enter the password:"));
      return false;
    }
    </script>
    <a href="passcheck.php" onclick="getPass(this.href);">Go to password page</a>
    It's never a good idea to redirect the user to another page when checking authentication. Try to include the check and the content on the same page.

    passcheck.php:
    PHP Code:
    <?php
    $user 
    $_GET['user'];
    $pass $_GET['pass'];
    if(
    $user == "john" && $pass == "travolta") {
    ?>

    <!-- Success page goes here. -->
    <html>
      <head>
        <title>Passcheck passed!</title>
      </head>
      <body>
        <p>
          Congratulations.  You've passed the password check!
        </p>
      </body>
    </html>

    <?php
    } else {
    ?>

    <!-- Failure page goes here.  We include an HTML form for non-JS users who couldn't use the prompts. -->
    <html>
      <head>
        <title>Wrong Password</title>
      </head>
      <body>
        <p>
          Either you have entered the wrong username/password, or your browser does not support Javascript.  Try again below.
        </p>
        <form method="get" action="<?=$PHP_SELF?>">
          User: <input type="text" name="user"/><br/>
          Password: <input type="text" name="pass"/>
          <input type="submit" value="OK"/>
        </form>
      </body>
    </html>

    <?php ?>
    Last edited by Twey; 08-24-2005 at 10:29 AM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •