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){
?>
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.
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?
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 .
Originally Posted by
lmfaoown
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
Ahh... I have version 5.2.17... Are there any other commands close to goto that I can use?
Originally Posted by
lmfaoown
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.
mmmmmmmm!!!
what about ?
PHP Code:
if ( $_SESSION [ 'views' ]== "10" && $pass == $passA ){ $_SESSION [ 'views' ] = 10 ; }
I really dont know what your going to suggest :P like I said my knowledge with PHP is really bad
Originally Posted by
pallap
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
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
Forum Rules
Bookmarks