vengod Posted May 20, 2011 Share Posted May 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/ Share on other sites More sharing options...
dreamwest Posted May 20, 2011 Share Posted May 20, 2011 http://www.wizecho.com/nav=php&s=forms Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1217920 Share on other sites More sharing options...
vengod Posted May 20, 2011 Author Share Posted May 20, 2011 Thanks, But i'd like it so if the login details are correct, when submit is clicked, it opens up a new page? I can't see that on the link you provided. Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1217928 Share on other sites More sharing options...
dreamwest Posted May 20, 2011 Share Posted May 20, 2011 Change the action to the page you want to post to action="/page.php" Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1217936 Share on other sites More sharing options...
vengod Posted May 20, 2011 Author Share Posted May 20, 2011 That is great, thank you Learn something new everyday Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1217938 Share on other sites More sharing options...
vengod Posted May 20, 2011 Author Share Posted May 20, 2011 Sorry to bug again. But The submit button works (ie takes to another page) But it does this regardless of username and password? So anyone can access the "hidden" page? Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1217950 Share on other sites More sharing options...
Ryflex Posted May 20, 2011 Share Posted May 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1217985 Share on other sites More sharing options...
Albos Posted May 20, 2011 Share Posted May 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1217987 Share on other sites More sharing options...
vengod Posted May 20, 2011 Author Share Posted May 20, 2011 Thanks i will give this a go Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1218008 Share on other sites More sharing options...
vengod Posted May 20, 2011 Author Share Posted May 20, 2011 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"); }?> Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1218013 Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2011 Share Posted May 20, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1218017 Share on other sites More sharing options...
vengod Posted May 20, 2011 Author Share Posted May 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/236938-submit-button-to-another-page/#findComment-1218051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.