Jump to content

Help with a simpel login code


Flaki

Recommended Posts

Hi folks

 

I have some problems. When I type the wrong password or username i can still log in.

 

Is there anything wrong with this code, any typos? If not, can I possible change the else statement, like connecting to another side if the password is wrong?

 

<form action=projekt2.php method=POST>                    <----------- when the pass is korrekt, it shall go to projekt.php.

Username <input type=text name=user><br/>

Password <input type=password name=pass>

<input type=submit value="bekräfta"><p>

</form>

 

<?php

 

$user=$_POST['user'];

$pass=$_POsT['pass'];

 

if (($user=="Adrian") && ($pass=="hello")) echo "yes";

 

elseif (($user=="Janoo") && ($pass=="bye")) echo "yes";

 

else  echo "no";          <----------- change to connect to another side, like Google for instance?

 

?>

-------------------------------------------------------------------------------------------

The first thing I wanted to do was to make a page before the login page.

Here you shall write your name. It will be displayed on login.php. If names like "adrian" are typed it shall display  "Hi Adrian, you're the GOD", although it does not work, whats missing?

 

<form action="login.php" method="POST">   

write your name: <input type="text" name="name" />

<input type="submit" value="puss this button to go to login section" />

</form>

 

 

-----------------------------------------------------------------------------

// this is on login.php

 

Hi <?php echo $_POST["namn"];

 

$person=$_POST['namn'];

 

if ($person=="Adrian") echo "Hi Adrian, you're the GOD";

 

?> 

 

 

 

 

Link to comment
Share on other sites

Hi folks

 

I have some problems. When I type the wrong password or username i can still log in.

 

Is there anything wrong with this code, any typos? If not, can I possible change the else statement, like connecting to another side if the password is wrong?

 

<form action=projekt2.php method=POST>              
   Username <input type=text name=user>

   Password <input type=password name=pass>
<input type=submit value="bekräfta"><p>
</form>

<?php

   $user=$_POST['user'];
   $pass=$_POsT['pass'];

if (($user=="Adrian") && ($pass=="hello")) echo "yes";

elseif (($user=="Janoo") && ($pass=="bye")) echo "yes";

else  echo "no";          <----------- change to connect to another side, like Google for instance?

   ?>

------------------------------------------------------------------------------------------- 

The first thing I wanted to do was to make a page before the login page.

Here you shall write your name. It will be displayed on login.php. If names like "adrian" are typed it shall display  "Hi Adrian, you're the GOD", although it does not work, whats missing?

 

<form action="login.php" method="POST">   
write your name: <input type="text" name="name" />
<input type="submit" value="puss this button to go to login section" />
</form>

 

 

-----------------------------------------------------------------------------

// this is on login.php

 

Hi <?php echo $_POST["namn"];

   $person=$_POST['namn'];

if ($person=="Adrian") echo "Hi Adrian, you're the GOD";

?>  

 

(just making it more readable)

Link to comment
Share on other sites

login.php

<form action=login.php method=POST>              
Username <input type=text name=user>

Password <input type=password name=pass>
<input type=submit name="submit" value="bekräfta"><p>
</form>

login Check:<br>
<?php
if (isset ($_POST['submit']))
{
   $username = $_POST['user'];
   $password = $_POST['pass'];

if ($username == "Adrian" && $password == "hello")
	{ echo "yes"; }
elseif ($username == "Janoo" && $password == "bye")
	{ echo "yes"; }
else
	{ echo "<script language='javascript'>window.location='http://www.google.com/';</script>"; }
}
?>

 

An example of what you might be looking for

Link to comment
Share on other sites

I think maybe it has someting to do with calling the Name field user in the html then trying to _get it as namn (which is spelled wrong anyway)

 

This part is fixed, thanks!

 

 

 

(just making it more readable)

 

Thanks a lot!

Link to comment
Share on other sites

I think maybe it has someting to do with calling the Name field user in the html then trying to _get it as namn (which is spelled wrong anyway)

 

This part is fixed, thanks!

 

 

 

(just making it more readable)

 

Thanks a lot!

 

I replied with actual code after that

Link to comment
Share on other sites

login.php

<form action=login.php method=POST>              
Username <input type=text name=user>

Password <input type=password name=pass>
<input type=submit name="submit" value="bekräfta"><p>
</form>

login Check:<br>
<?php
if (isset ($_POST['submit']))
{
   $username = $_POST['user'];
   $password = $_POST['pass'];

if ($username == "Adrian" && $password == "hello")
	{ echo "yes"; }
elseif ($username == "Janoo" && $password == "bye")
	{ echo "yes"; }
else
	{ echo "<script language='javascript'>window.location='http://www.google.com/';</script>"; }
}
?>

 

An example of what you might be looking for

 

Hmm the code looks neat but it doesn't work as it should do, it doesn't go to Google if I type wrong.  I'm using linux/xampp by the way.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.