mister X Posted August 14, 2009 Share Posted August 14, 2009 Hi, Currently, im doing on a login page using PHP. It requires to match the (username and password) database i created in Mysql. Once it matches, it will bring me to the index page. So can anyone help me with the coding? thanks. Its urgent! Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/ Share on other sites More sharing options...
timmah1 Posted August 14, 2009 Share Posted August 14, 2009 Dong a basic search on Google for basic php login script returns NUMEROUS tutorials http://www.google.com/search?q=basic+php+login+script&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897826 Share on other sites More sharing options...
kratsg Posted August 14, 2009 Share Posted August 14, 2009 I'm going to assume the following: the passwords in your database table are hashed (that is, you're not storing the actual passsword in plaintext). <?php if(isset($_POST) && !empty($_POST)){//check to see if they submitted the form $username = mysql_real_escape_string($_POST['username']);//escape username $password = md5(mysql_real_escape_string($_POST['password']));//escape and hash $result = @mysql_fetch_array(@mysql_query("SELECT `password` FROM `users` WHERE `username` = '$username' LIMIT 1")); if($password == $result){//the two match echo "Access Granted"; //do stuff } else { echo "Access Denied"; //do other stuff } } ?> Meh, if you can't get this part down, I suggest googling some tutorials for a log in system and trying to understand how it comes together. Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897827 Share on other sites More sharing options...
mister X Posted August 14, 2009 Author Share Posted August 14, 2009 Thanks guys. I will try it out first. Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897833 Share on other sites More sharing options...
mister X Posted August 14, 2009 Author Share Posted August 14, 2009 Hey, did try out but somehow, it cant seem to proceed on.. I get the page loaded up. But after I enter in my username and password. It just doesnt redirect me to index page. <?php // we must start the session session_start(); $_SESSION['flag'] = true; if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { // store the user's input in the variables $userid = $_POST['txtUserId']; $password = $_POST['txtPassword']; // connect to the lcoalhost and select the appropriate database $sql_index = mysql_connect('localhost', 'root', 'password'); $db_select = mysql_select_db('network_deployment_system', $sql_index); echo $db_select; // retrieve the username and password base on the user's input $sql_query = mysql_query('select * from authorised_user where UserID=\''.$userid.'\' and Password=\''.$password.'\''); // check whether there is a match if (mysql_num_rows($sql_query) == 1) { // fetch data from the table $data = mysql_fetch_row($sql_query); // store the data into session variables $_SESSION['UserID'] = $data[0]; $_SESSION['Password'] = $data[1]; $_SESSION['Administrator'] = $data[2]; // response and redirect to index page once login successful header('Location: Index.php'); } else { $_SESSION['flag'] = false; } } ?> Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897870 Share on other sites More sharing options...
mister X Posted August 14, 2009 Author Share Posted August 14, 2009 Adding on, whenever I enter in my password and UserID, and click on login, they will redirect to a blank page. Isit a case of wrong coding? pls advice. Thanks Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897916 Share on other sites More sharing options...
Coreye Posted August 14, 2009 Share Posted August 14, 2009 Adding on, whenever I enter in my password and UserID, and click on login, they will redirect to a blank page. Isit a case of wrong coding? pls advice. Thanks Add error reporting to the top of the script and see what it says. error_reporting(E_ALL); ini_set("display_errors", 1); Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897957 Share on other sites More sharing options...
Bjom Posted August 14, 2009 Share Posted August 14, 2009 Check out my authentication class if you like - or use it. Can be found from this thread it's fairly easy to integrate has quite some nice features and does the actual authentication, while you define your login page's design yourself. Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897963 Share on other sites More sharing options...
Bricktop Posted August 14, 2009 Share Posted August 14, 2009 hi mister x, Try chaging: $sql_query = mysql_query('select * from authorised_user where UserID=\''.$userid.'\' and Password=\''.$password.'\''); // check whether there is a match if (mysql_num_rows($sql_query) == 1) to: $sql = mysql_query('select UserID, Password from authorised_user where UserID='$userid' and Password='$password'); // check whether there is a match if (mysql_num_rows($sql) == 1) Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-897992 Share on other sites More sharing options...
Bricktop Posted August 14, 2009 Share Posted August 14, 2009 Also, I notice your line: header('Location: Index.php'); I assume this file is stored on your server as "Index.php" and not "index.php". A lot of servers use case sensitive URL's so make sure you use the right case for the "i" at the beginning of "Index.php". Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-898006 Share on other sites More sharing options...
chriscloyd Posted August 14, 2009 Share Posted August 14, 2009 dreamweaver blows go notepad Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-898021 Share on other sites More sharing options...
mister X Posted August 17, 2009 Author Share Posted August 17, 2009 Hmm.. I got the following error msg after i enter in my userid and password. Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver-soft\Login.php on line 17 What should I do now then? Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-899848 Share on other sites More sharing options...
peter_anderson Posted August 17, 2009 Share Posted August 17, 2009 Hmm.. I got the following error msg after i enter in my userid and password. Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\terminalserver-soft\Login.php on line 17 What should I do now then? That means you cannot connect to your Database. Is your information correct? Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-899920 Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 No that means that php is enabled on his server but MySQL is not. If you have access to php.ini uncomment the line that says extension=php_mysql.dll On windows. I'm not sure what the exact name is on linux based systems... but basically search through the file for "mysql" and you should find it under the extension section of the ini. Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-899929 Share on other sites More sharing options...
mister X Posted August 18, 2009 Author Share Posted August 18, 2009 So how do I uncomment that line? Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-900567 Share on other sites More sharing options...
gergy008 Posted August 18, 2009 Share Posted August 18, 2009 dreamweaver blows go notepad No it doesn't... Dreamweaver makes the coding easier to read when echoing HTML as it tells you if your missing any backslashes ect. Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-900568 Share on other sites More sharing options...
play_ Posted August 18, 2009 Share Posted August 18, 2009 dreamweaver blows go notepad Do tell how notepad makes coding easier than DW. Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-900585 Share on other sites More sharing options...
mister X Posted August 18, 2009 Author Share Posted August 18, 2009 hmm.. I uncomment that line extension=php_mysql.dll. but somehow, the error is still the there? I did a restart to my apache already.. Link to comment https://forums.phpfreaks.com/topic/170201-login-authentication/#findComment-900586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.