Jump to content

Recommended Posts

Hello,

 

Im new to website building. I have created a login system.

 

The login system echoes some text when the username and password is correct. However, if correct i would like it to open another page on my site.

 

<form name="form1" method="post" action="">
  <p>Username
    <label>
    <input type="text" name="username" id="username">
    </label>
  Password
    <label>
      <input type="password" name="password" id="password">
    </label>
    <input name="login" type="submit" id="login" value="Login">
    <?php
$username = $_POST ["username"];
$password = $_POST ["password"];

if ($username == "admin" && $password == "password"){
echo"Logged In";}
?>
  </p>
</form>

 

I am a novice and learnt this via youtube. However, can't find a tutorial for what i want.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/
Share on other sites

You will need to create a page with some validation on, so when you press submit say for example the page goes to memberspage.php

 

Then in members page you will need something to check if this person has entered the correct login information:

 

<?php
if($_POST["username"] == "admin" && $_GET["password"] == "password"){

// Have some member information in here that needs viewing

// You could maybe set a cookie for the user so they dont have to keep logging in
setcookie("memberlogin", "loggedin", time() + 3600);

}else{

// Redirect the user to the login page as authentication failed.
header("Location: loginpage.php");

}

?>

 

This is very basic and you would need to put some sort of validation in to check for people trying to hack your site or anything.

 

Hope this helps, if you need more information on the cookie side check this out http://php.net/manual/en/function.setcookie.php

 

 

 

Regards

Albos

Hi vengod,

 

You should redirect the submit to a page where the credentials are checked and then let it redirect to th hidden page if the credentials are ok.

 

Ryflex

 

Yeah, trying to do this with the username and password being the credentials..

 

 

My current code

 

<form name="form1" method="post" action="welcome.html"">
  <p>Username
    <label>
    <input type="text" name="username" id="username">
    </label>
  Password
    <label>
      <input type="password" name="password" id="password">
    </label>
    <input name="login" type="submit" id="login" value="Login">
<?php 

if($_POST["username"] == "admin" && $_GET["password"] == "password"){		

setcookie("memberlogin", "loggedin", time() + 3600);	}else{		

header("Location: members.html");	}?>

Setting a cookie with a simple value in it is not secure (anyone can put that value in a cookie and become logged in as an administrator to your site.)

 

Also, you are not using the GET method in your form, so $_GET["password"] won't ever be set (don't blindly copy code that someone posts.)

 

There are literally 100's of thousands of php log in scripts posted all over the Internet that you can find and examine to see how you can create you own code.

Where i am at with my code now.

 

<?php
session_start();

$username = "admin";
$password = "password";

if ($_POST['Username'] != $username || $_POST['Password'] !=$password) {

?>

<form name="form" method="post" action="<?php echo $_SERVER['PHP SELF']; ?>">

  <p><label for="txtUsername">Username:</label>
    <input type="text" name="username" id="username" />
    
   <p><label for="txtPassword">Password:</label>
      <input type="password" name="password" id="password" />
      
    <input type="submit" name="login" value="Login" id="login" /> 
    
    </form>
    
<?php

}
else {

?>

LOAD NEW WINDOW

<?php

}
?>

 

I followed this tutorial

 

 

 

Still not working  :-[

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.