Jump to content

[SOLVED] Saving logon in sessions


heckler0077

Recommended Posts

I have a script like this:

 

<?php 
session_start(); 
// Define your username and password 
$username = "username"; 
$password = "password"; 
$_SESSION['txtUsername'] = $_POST['txtUsername']; 
$_SESSION['txtPassword'] = $_POST['txtPassword']; 
if ($_SESSION['txtUsername'] != $username || $_SESSION['txtPassword'] != $password) { 

?> 

<h1>Login</h1> 

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> 
    <p><label for="txtUsername">Username:</label> 
    <br /><input type="text" title="Enter your Username" name="txtUsername" /></p> 

    <p><label for="txtpassword">Password:</label> 
    <br /><input type="password" title="Enter your password" name="txtPassword" /></p> 

    <p><input type="submit" name="Submit" value="Login" /></p> 

</form> 

<?php 

} 
else { 
//--------------------------------------------------------------------------------------- 
$filename = $_GET['filename']; 
if (empty($filename)) 
{ 
?> 
<form action="" method="GET"> 
<input type="text" name="filename"> 
<input type="submit"> 
</form> 
<?php 
} 

else 
{ 
if (strpos($filename,".zip") >= 1) 
{ 
exec('unzip $filename',$ret); 
echo "Successful unzipping"; 
session_destroy(); 
} 
elseif ((strpos($filename,".tgz") >= 1) || (strpos($filename,".tar.gz") >= 1)) 
{ 
exec('tar -xzf $filename',$ret); 
echo "Successful untargzing"; 
session_destroy(); 
} 
else 
{ 
?> 
<form action="" method="GET"> 
<input type="text" name="filename"> 
<input type="submit"> 
</form> 
<?php 
} 
} 
} 
?>

 

The only part we need to worry about is logging in. The problem is that After I logon and use the text box to submit my filename, it takes me to the login screen again. I thought I had solved this by using session variables that only expire after a successfull uncompressing, but apparently I was wrong. Help!

Link to comment
https://forums.phpfreaks.com/topic/48200-solved-saving-logon-in-sessions/
Share on other sites

humm this is kinda weird

 

<?php 
session_start(); 
// Define your username and password 
$username = "username"; 
$password = "password"; 
$_SESSION['txtUsername'] = $_POST['txtUsername']; 
$_SESSION['txtPassword'] = $_POST['txtPassword']; 
if ($_SESSION['txtUsername'] != $username || $_SESSION['txtPassword'] != $password) { 

?> 

if the username is correct it will login even if password is wrong!

not sure how thats is meant to work!

Well, that's not part of my original problem, but if that's true, then that only compounds it.  That needs to be solved, too, but I'm a little unsure.

 

Please thorpe, let the man be!

 

<?php
if ($_SESSION['txtUsername'] != $username || $_SESSION['txtPassword'] != $password) 
?>

should be

<?php
if ($_SESSION['txtUsername'] != $username && $_SESSION['txtPassword'] != $password) 
?>

 

 

 

Thank you, Trium, and thorpe, I apologize.  As to changing or: || to and: &&

That lets me login as long as either the password or username is correct, even if both are not, because now the code states that if both are incorrect, show the login screen, otherwise, proceed to content.  It also still takes me back to the login screen when I use the form to enter my compressed file's name.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.