www.webdeveloper.com
Results 1 to 11 of 11

Thread: Asks for password everytime page refresh/reloads

  1. #1
    Join Date
    Aug 2011
    Posts
    6

    Asks for password everytime page refresh/reloads

    Hey there, I have a website with a pretty simple login form, and when someone puts the password, it'll show everything below the code, which is what I want it to do. But everytime someone would refresh/reload the page, it would ask for the password again, is there a way that I can make it so they only have to put the password in once, then they can reload/refresh the page all they want without repeatedly putting in the password everytime?

    Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <b>Password:</b><input name="pass" type="password"/>
    <input name="sub" type="submit" value="Login"/>
    </form>
    <?php
    if ($_SERVER['REQUEST_METHOD']=="POST"){
    include("config.php");
    $pass = $_POST['pass'];
    if ($pass==$passA){
    ?>

  2. #2
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    Once they are logged in you could set a $_SESSION['variable'] and then test for it being set, or you set a $_COOKIE['variable'] and do the same thing.

  3. #3
    Join Date
    Aug 2011
    Posts
    6
    I'm not that great with PHP, I got this bit of code from my friend, where should I put the bit of code you gave me?

  4. #4
    Join Date
    Aug 2011
    Posts
    6
    I made this bit of code with the information you gave me and with some google information, but I get some error that I cant seem to get rid of.

    Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <b>Password:</b><input name="pass" type="password"/>
    <input name="sub" type="submit" value="Login"/>
    </form>
    <?php
    session_start(); 
    echo "". $_SESSION['views']; //retrieve data
    if ($_SERVER['REQUEST_METHOD']=="POST"){
    include("config.php");
    $pass = $_POST['pass'];
    if ($_SESSION['views']=="10"){
    goto a;
    } else if ($pass==$passA){
    a:
    $_SESSION['views'] = 10;
    ?>
    Error:
    Code:
    Parse error: syntax error, unexpected T_STRING in /home/u592360535/public_html/staff.php on line 26
    edit:
    Line 26 is "goto a;" I dont see whats wrong with the code though?
    Last edited by lmfaoown; 08-23-2011 at 02:28 PM.

  5. #5
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by lmfaoown View Post
    I made this bit of code with the information you gave me and with some google information, but I get some error that I cant seem to get rid of.

    Code:
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <b>Password:</b><input name="pass" type="password"/>
    <input name="sub" type="submit" value="Login"/>
    </form>
    <?php
    session_start(); 
    echo "". $_SESSION['views']; //retrieve data
    if ($_SERVER['REQUEST_METHOD']=="POST"){
    include("config.php");
    $pass = $_POST['pass'];
    if ($_SESSION['views']=="10"){
    goto a;
    } else if ($pass==$passA){
    a:
    $_SESSION['views'] = 10;
    ?>
    Error:
    Code:
    Parse error: syntax error, unexpected T_STRING in /home/u592360535/public_html/staff.php on line 26
    edit:
    Line 26 is "goto a;" I dont see whats wrong with the code though?
    What version of PHP are you using? goto is only available as of 5.3.x

    http://php.net/manual/en/control-structures.goto.php

  6. #6
    Join Date
    Aug 2011
    Posts
    6
    Ahh... I have version 5.2.17... Are there any other commands close to goto that I can use?

  7. #7
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by lmfaoown View Post
    Ahh... I have version 5.2.17... Are there any other commands close to goto that I can use?
    If you look at the image on the documentation page I'm sure you can guess what I'll suggest... flow your logic properly.

  8. #8
    Join Date
    Nov 2010
    Posts
    6
    mmmmmmmm!!!
    what about ?
    PHP Code:
    if ($_SESSION['views']=="10" && $pass==$passA ){
    $_SESSION['views'] = 10;


  9. #9
    Join Date
    Aug 2011
    Posts
    6
    I really dont know what your going to suggest :P like I said my knowledge with PHP is really bad

  10. #10
    Join Date
    Aug 2011
    Posts
    6
    Quote Originally Posted by pallap View Post
    mmmmmmmm!!!
    what about ?
    PHP Code:
    if ($_SESSION['views']=="10" && $pass==$passA ){
    $_SESSION['views'] = 10;

    I modified this code to make it what I wanted, thanks for this

  11. #11
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    You have to put the session start at the top of the page before any html code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles