Jump to content

Login Page


frisiandi

Recommended Posts

Hi....I have create login page like below :<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><br><form name="form1" method="post" action="">Username : <input name="username" type="text" id="username"><br><br>Password : <input name="password" type="password" id="password"><br><br> <input type="submit" name="Submit" value="Submit"> <input type="button" name="Submit2" value="cancel"><?if(isset($_POST['Submit'])) { mysql_connect ('server08', 'root', ''); mysql_select_db ('accsys'); $hasil = mysql_query("SELECT * FROM userpassword where username='$_POST[username]' and password='$_POST[password]' "); $num_rows = mysql_num_rows($hasil); if ($num_rows>0) {echo "Login Successfull ";} else {echo "Fail ";} }else{}?> </form></body></html>It's already worked fine, but what i want is : if the login is succesfull it would go to another page automatically (ex: home.php)Pls help

Link to comment
Share on other sites

Hi....I have create login page like below :<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><br><form name="form1" method="post" action="">Username : <input name="username" type="text" id="username"><br><br>Password : <input name="password" type="password" id="password"><br><br> <input type="submit" name="Submit" value="Submit"> <input type="button" name="Submit2" value="cancel"><?if(isset($_POST['Submit'])) { mysql_connect ('server08', 'root', ''); mysql_select_db ('accsys'); $hasil = mysql_query("SELECT * FROM userpassword where username='$_POST[username]' and password='$_POST[password]' "); $num_rows = mysql_num_rows($hasil); if ($num_rows>0) {echo "Login Successfull ";} else {echo "Fail ";} }else{}?> </form></body></html>It's already worked fine, but what i want is : if the login is succesfull it would go to another page automatically (ex: home.php)Pls help
what is the buttons action???you can use more options, but I need to say you right now that header wont work there. What you can do is to seperate this two pages:
<html><body><form method="processlogin.php" method="POST"><input type="text" size="20" name="user"><input type="password" size="20" name="pass"><input type="submit" value="Login"></form></body></html>
<?phpif(isset($_POST['Submit'])) { mysql_connect ('server08', 'root', ''); mysql_select_db ('accsys'); $hasil = mysql_query("SELECT * FROM userpassword where username='$_POST[username]' and password='$_POST[password]' "); $num_rows = mysql_num_rows($hasil); if ($num_rows>0) {echo "Login Successfull "; header( 'Location:http://www.domain.com/members/index.php'); } else {echo "Fail ";} }else{}?>
This should work.Good luck.
Link to comment
Share on other sites

what is the buttons action???you can use more options, but I need to say you right now that header wont work there. What you can do is to seperate this two pages:This should work.Good luck.
you mean i have to save this code in 2 files?, so pls explain it to me clearly since i am a newbethanks
Link to comment
Share on other sites

Hi....I have create login page like below :<html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><br><form name="form1" method="post" action="">Username : <input name="username" type="text" id="username"><br><br>Password : <input name="password" type="password" id="password"><br><br> <input type="submit" name="Submit" value="Submit"> <input type="button" name="Submit2" value="cancel"><?if(isset($_POST['Submit'])) { mysql_connect ('server08', 'root', ''); mysql_select_db ('accsys'); $hasil = mysql_query("SELECT * FROM userpassword where username='$_POST[username]' and password='$_POST[password]' "); $num_rows = mysql_num_rows($hasil); if ($num_rows>0) {echo "Login Successfull ";} else {echo "Fail ";} }else{}?> </form></body></html>It's already worked fine, but what i want is : if the login is succesfull it would go to another page automatically (ex: home.php)Pls help
I modified your file. Try to see if that's what you want.<?if(isset($_POST['Submit'])) { mysql_connect ('server08', 'root', ''); mysql_select_db ('accsys'); $hasil = mysql_query("SELECT * FROM userpassword where username='$_POST[username]' and password='$_POST[password]' "); $num_rows = mysql_num_rows($hasil); if ($num_rows>0) { header("Location: http://www.example.com/home.php"); } else {echo "Fail ";} }else{}?> <html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><br><form name="form1" method="post" action="">Username : <input name="username" type="text" id="username"><br><br>Password : <input name="password" type="password" id="password"><br><br> <input type="submit" name="Submit" value="Submit"> <input type="button" name="Submit2" value="cancel"> </form></body></html>You can find more detail description of the function header here:http://php.net/headerBut in order for the header to work I transfer your php code segment to the top most part of your codes. Header will fail if there is already an output sent to the browser. (i.e. html codes or even a single white space)
Link to comment
Share on other sites

I hope this is not you're final login code. because you're not setting any session variables clearing that the person has logged in. They could still just go to http://www.example.com/home.php without logging in.you should add something like this on your login.php

$_SESSION['loggedin'] = true;

and this to your loggedinpage

if (!$_SESSION['loggedin']) {  exit("You need to be logged in to view this page"); // sorry if i got this method wrong haven't coded PHP in a while.}

Link to comment
Share on other sites

  • 2 weeks later...
I hope this is not you're final login code. because you're not setting any session variables clearing that the person has logged in. They could still just go to http://www.example.com/home.php without logging in.you should add something like this on your login.php
$_SESSION['loggedin'] = true;

and this to your loggedinpage

if (!$_SESSION['loggedin']) {  exit("You need to be logged in to view this page"); // sorry if i got this method wrong haven't coded PHP in a while.}

Thanks a lot friend
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...