Open-source rich HTML editor [closed]

孤街浪徒 提交于 2019-11-29 18:55:08

you are doing it wrong way, i highly doubt that you can develop the application so sooner, as you said you only started learning PHP from yesterday, your examples shows that you are very poor in understating the basics of server side language, you said you would check the login with if (username == x && password == x) this is totally wrong way of doing it, instead you should use database like MySQL to store and check the login credentials i.e via $_SESSION (Session Variable), to be more precise,

Consider a Login Form

<form action="checkLogin.php" method="post">
    <input type = "text" name="username"/>
    <input type = "password" name = "password"/>
    <input type = "submit" name = "submit" value ="login"/>
</form>

It is always better to have database, consider the following database with the following tables and values.

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
);
INSERT INTO `users` VALUES('First User', '6c049bc0f30da673d0a82c5bd1a13cde');
INSERT INTO `users` VALUES('Second User', '6a6150f8eb2c263a31eb91487bebf1d6');
INSERT INTO `users` VALUES('Third User', '2fd7e7348da8dd5f67103b15be525859');

the second argument is hashed values of your password, i have used md5(), you can use sha1() or others too.

Now to check the login credentials you need to write the following code in your checkLogin.php

<?php
if(isset($_POST['submit'])) {
    $username = mysql_real_escape_string($_POST['username']);
    $password = sha1(mysql_real_escape_string($_POST['password']));
    $result = mysql_query('SELECT id, username FROM users WHERE users.username = '.$username.' AND users.username =.'$password) or die('unable to select database');
    if(mysql_num_rows($sesult) > 0) {
        $row = mysql_fetch_array($result);
        $_SESSION['userId'] = $row['userId'];
    }   
}
?>

in other pages if you want to check if the user is logged so that you can give him access, then you simply need to check Session Variables

if(isset($_SESSION['userId'])) {
    //Give Page Access to this user.
}

This is just a basic and rough idea about how PHP works, to get you started i would recommend you check out this tutorial for Novice. http://devzone.zend.com/article/627

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!