Lunes, Marso 14, 2011

php login code

connect_to_database.php
<?php
mysql_connect("localhost","your_username","your_password") or die(mysql_error());
mysql_select_db("your_database");
?>
login.php
<?php
include 'connect_to_database.php'; //connect the connection page
if(empty($_SESSION)) // if the session not yet started
   session_start();


if(isset($_SESSION['username'])) { // if already login
   header("location: home.php"); // send to home page
   exit; 
}

?>
<html>
<head></head>
<body>
<form action = "login_proccess.php" method = "post">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type = "submit" name="submit" value="login" />
</form>
</body>
</html>
login_proccess.php
<?php
include 'connect_to_database.php'; //connect the connection page
 
if(empty($_SESSION)) // if the session not yet started
   session_start();
if(!isset($_POST['submit'])) { // if the form not yet submitted
   header("Location: login.php");
   exit;
}
//check if the username entered is in the database.
$test_query = "SELECT * FROM table_name WHERE username_field = '".$_POST[username]."'";
$query_result = mysql_query($test_query);
//conditions
if(mysql_num_rows($query_result)==0) {
//if username entered not yet exists
    echo "The username you entered is invalid.";
}else {
//if exists, then extract the password.
    while($row_query = mysql_fetch_array($query_result)) {
        // check if password are equal
        if($row_query['password_field']==$_POST['password']){
            $_SESSION['password'] = $_POST['password'];
            header("Location: home.php");
            exit;
        } else{ // if not
            echo "Invalid Password";
        }
    }
}
?>
home.php
<?php
include 'connect_to_database.php'; //connect the connection page

if(empty($_SESSION)) // if the session not yet started
   session_start();

if(!isset($_SESSION['username'])) { //if not yet logged in
   header("Location: login.php");// send to login page
   exit;
}
?>
<html>
<body>
Welcome <?php echo $_SESSION['username']; ?>,
 <a href="logout.php">logout</a>
</body>
</html>
logout.php
<?php
session_start();
unset($_SESSION['username']);
session_destroy();

header("Location: login.php");
exit;
?>

19 (na) komento:

  1. login logout in xml
    http://www.wefinding.com/258/xml/signup-login-using-data-stored-in-xml-file/

    TumugonBurahin
  2. Nice! Thanks, man!
    There's just an error in your code.
    In login_proccess.php it should be:

    if($row_query['password_field']==$_POST['password']){
    $_SESSION['username'] = $_POST['username'];
    header("Location: home.php");
    exit;

    TumugonBurahin
  3. These ways are very very much useful, these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    PHP training institute in Chandigarh

    TumugonBurahin
  4. I am really happy to say it’s an interesting post to read. I learn new information from your article, you are doing a great job.
    php training in IndoreKeep Posting:)

    TumugonBurahin
  5. I have read this article it is really helpful for getting amazing tips on related topic. You have described everything in a professional way.

    marketing companies buffalo ny are available but Crysal Tech Solution provides professional digital marketing service for growing your business.





    TumugonBurahin
  6. very nice..post.
    https://shayarihindishayari.com/

    TumugonBurahin
  7. Really your content is so informative. So please share some more content ..
    PHP training in Delhi

    TumugonBurahin
  8. thanks for sharing login and log out page. I learn new information from your article. Hire PHP Developer

    TumugonBurahin
  9. Your articel is very good sir, let's also visit my articel Bandar Togel Online VillaBetting
    and many more interesting articel that belongs to me like Prediksi Togel - Bandar Judi Online VillaBetting
    - Prediksi Hongkong Pools and more, friends will definitely like my articel.every day I always update interesting art articles such as Bandar Judi Bola Online VillaBetting
    You must be happy to see my website.

    TumugonBurahin
  10. We Create This Blog Learn Php at home is for learner Programmers and Developers that ought to learn web advancement utilizing php bit by bit and can do instances of php with simple approaches to Explain. Bluehost hosting plans

    TumugonBurahin
  11. Really nice blog, very infromative. You can refer more topics related to PHP Language, PHP error handling from here for future articles
    thanks !

    TumugonBurahin
  12. The post you've shared here is great because it contains some best knowledge which is extremely useful on my behalf. Thanks for posting it. Keep it up. best php institute in delhi

    TumugonBurahin
  13. The details you've shared here areIt’sextremely instructive because it contains some best knowledge, which is extremely helpful. Thanks for posting it. best php institute in delhi

    TumugonBurahin
  14. Many cricket matches have over a hundred markets. These are the markets from which you will choose one or a few. If you don't have world777 strategy in place, you'll most likely choose a market at random, glance at the chances, and make a wild estimate in the hopes of winning.

    TumugonBurahin
  15. What is the average salary for a Java full-stack Java developer with 3 to 4 years of experience in India?
    For a food full stack developer salary in India you should have at least 6 LPA for service-based IT firms, but investment banks like JP & BNP may be able to give you more. It doesn't matter what company you work for. It is your skills that matter. Working as a freelancer or in a small business can give you the best salary. Upwork lets you bid for clients and pay hourly in dollars. Clients who like your work can earn 2-3 lacs monthly and even more if you have a larger team.

    TumugonBurahin