Login Register


Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) filter_list
Author
Message
Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #1
I created this on my own free time entirely from scratch for another forum. It was going to be used as a member ranks table to display points and username data on a GFX forum for top 10 GFX battle winners as I was requested to make, but maybe it will help others out here as well. This is very basic, and i've split apart everything into separate files for easier view.

I did NOT put in the MySQL queries so you'll have to create the database yourself, if anyone is serious about this i'll tell you how i've set up the database, but most of what you'll learn here is inside the scripting half of it.

My main localhost version is a bit compressed, in terms of my newest script, but this i'm sure will look a bit more appealing for learners out there. You CAN loop through the values to insert and retrieve data, you can put them into an array if you want, really it's up to you.

I'm going to go over the main files I have in this project being:
  • db.php
  • checklogin.php
  • editvalues.php
  • getvalues_names.php
  • getvalues_values.php
  • mod_time.php
  • insert.php
  • login.php
  • login_status.php
  • logout.php
  • member_ranks.php

Here's a preview first:


I realize I could have put some of these files into one, but it's easier for people to understand this way. I won't include the CSS for this because this is only meant to give you an idea of how it all works. Any questions feel free to ask.

I actually originally created this kindly for a graphics forum that needed a way to store a member ranks page with configurable and savable information for member rankings, due to gfx battles, but it will also greatly help people here i'm sure, which is why I did it.

Be sure to make sure that you've set each file permission properly if you can on your ftp, however people shouldn't be able to view any of the strict php files anyway.

db.php: This is our global variable storage.
Code:
<? //Database Information $host='localhost'; $username="root"; $password=""; $database="pixels"; //Table Information $member_tbl='`members`'; $modified_tbl='`modified`'; $users_tbl='`data_user`'; $points_tbl='`data_count`'; ?>

checklogin.php:
Code:
<?php ob_start(); include("db.php"); /* Connect to server and select databse. */ mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$database")or die("cannot select DB"); /* Define Inputs */ $username=$_POST['myusername']; $input_pass=$_POST['mypassword']; $encrypt_pass=md5($input_pass); /* SQL Injection Protect */ $username = stripslashes($username); $input_pass = stripslashes($input_pass); $username = mysql_real_escape_string($username); $input_pass = mysql_real_escape_string($input_pass); /* XSS Protect */ $username = htmlspecialchars($username, ENT_QUOTES); $input_pass = htmlspecialchars($input_pass, ENT_QUOTES); $query="SELECT * FROM $member_tbl WHERE username='$username' and password='$encrypt_pass'"; $result=@mysql_query($query); //hide errors for the query /* Mysql_num_row is counting table row */ $count=mysql_num_rows($result); /* If result matched $username and $input_pass, table row must be 1 row */ if($count==1){ /* Register $username, $input_pass and redirect to file "login_success.php" */ session_register("myusername"); session_register("mypassword"); $_SESSION['isadmin'] = True; header("location:login_status.php"); } else { header("location:login.php"); } ob_end_flush(); ?>

editvalues.php:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Member Ranks - Edit</title> <link rel="shortcut icon" href="favicon.ico"> <link href="style.css" rel="stylesheet" type="text/css"/> <link href="textfield.css" rel="stylesheet" type="text/css"/> <script language="JavaScript"> if (document.images) { img1_on =new Image(); img1_on.src ="images/buttons/signout_h.png"; img1_off=new Image(); img1_off.src="images/buttons/signout.png"; } if (document.images) { img2_on =new Image(); img2_on.src ="images/buttons/edit_values_h.png"; img2_off=new Image(); img2_off.src="images/buttons/edit_values.png"; } if (document.images) { img3_on =new Image(); img3_on.src ="images/buttons/main_page_h.png"; img3_off=new Image(); img3_off.src="images/buttons/main_page.png"; } if (document.images) { img4_on =new Image(); img4_on.src ="images/buttons/info_h.png"; img4_off=new Image(); img4_off.src="images/buttons/info.png"; } if (document.images) { img5_on =new Image(); img5_on.src ="images/buttons/forum_h.png"; img5_off=new Image(); img5_off.src="images/buttons/forum.png"; } if (document.images) { img6_on =new Image(); img6_on.src ="images/buttons/help_h.png"; img6_off=new Image(); img6_off.src="images/buttons/help.png"; } if (document.images) { img7_on =new Image(); img7_on.src ="images/buttons/signin_h.png"; img7_off=new Image(); img7_off.src="images/buttons/signin.png"; } function handleOver() { if (document.images) document.imgName.src=img_on.src; } function handleOut() { if (document.images) document.imgName.src=img_off.src; } function movr(k) { if (document.images) eval('document.img'+k+'.src=img'+k+'_on.src'); } function mout(k) { if (document.images) eval('document.img'+k+'.src=img'+k+'_off.src'); } function handleOver() { if (document.images) document.imgName.src=img_on.src; } function handleOut() { if (document.images) document.imgSource.src=img_off.src; } </script> </head> <?php include("getvalues_names.php"); include("getvalues_values.php"); session_start(); if (@$_SESSION['isadmin']) { ?> <!-- Content here for Admin Users --> <!-- Administration Control Panel Bar --> <div id="nav_bar"> <div id="nav_text">You are now logged in as an :: <strong>Administrator</strong></div> <div id="nav_buttons"> <a href="#" onMouseOver="movr(6);return true;" onMouseOut="mout(6);return true;"><img name=img6 src="images/buttons/help.png" border="0"></a> <a href="#" onMouseOver="movr(4);return true;" onMouseOut="mout(4);return true;"><img name=img4 src="images/buttons/info.png" border="0"></a> <a href="http://tech.reboot.pro" target="_blank" onMouseOver="movr(5);return true;" onMouseOut="mout(5);return true;"><img name=img5 src="images/buttons/forum.png" border="0"></a> <a href="member_ranks.php" onMouseOver="movr(3);return true;" onMouseOut="mout(3);return true;"><img name=img3 src="images/buttons/main_page.png" border="0"></a> <a href="logout.php" onMouseOver="movr(1);return true;" onMouseOut="mout(1);return true;"><img name=img1 src="images/buttons/signout.png" border="0"></a> </div> </div> <!-- End of Admin Bar --> <div id="content"> <!-- Table for Data --> <form id="edit_form" action="insert.php" method="post"> <table id="edit_table" cellpadding="2" cellspacing="10"> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 1 </strong></font>]: <input class="t_effect" type="text" name="field1_user" id="field1_user" value="<?php echo "$return_name1"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 1 </strong></font>]: <input class="t_effect" type="text" name="field1_value" id="field1_value" value="<?php echo "$return_value1"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 2 </strong></font>]: <input class="t_effect" type="text" name="field2_user" id="field2_user" value="<?php echo "$return_name2"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 2 </strong></font>]: <input class="t_effect" type="text" name="field2_value" id="field2_value" value="<?php echo "$return_value2"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 3 </strong></font>]: <input class="t_effect" type="text" name="field3_user" id="field3_user" value="<?php echo "$return_name3"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 3 </strong></font>]: <input class="t_effect" type="text" name="field3_value" id="field3_value" value="<?php echo "$return_value3"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 4 </strong></font>]: <input class="t_effect" type="text" name="field4_user" id="field4_user" value="<?php echo "$return_name4"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 4 </strong></font>]: <input class="t_effect" type="text" name="field4_value" id="field4_value" value="<?php echo "$return_value4"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 5 </strong></font>]: <input class="t_effect" type="text" name="field5_user" id="field5_user" value="<?php echo "$return_name5"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 5 </strong></font>]: <input class="t_effect" type="text" name="field5_value" id="field5_value" value="<?php echo "$return_value5"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 6 </strong></font>]: <input class="t_effect" type="text" name="field6_user" id="field6_user" value="<?php echo "$return_name6"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 6 </strong></font>]: <input class="t_effect" type="text" name="field6_value" id="field6_value" value="<?php echo "$return_value6"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 7 </strong></font>]: <input class="t_effect" type="text" name="field7_user" id="field7_user" value="<?php echo "$return_name7"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 7 </strong></font>]: <input class="t_effect" type="text" name="field7_value" id="field7_value" value="<?php echo "$return_value7"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 8 </strong></font>]: <input class="t_effect" type="text" name="field8_user" id="field8_user" value="<?php echo "$return_name8"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 8 </strong></font>]: <input class="t_effect" type="text" name="field8_value" id="field8_value" value="<?php echo "$return_value8"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 9 </strong></font>]: <input class="t_effect" type="text" name="field9_user" id="field9_user" value="<?php echo "$return_name9"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 9 </strong></font>]: <input class="t_effect" type="text" name="field9_value" id="field9_value" value="<?php echo "$return_value9"; ?>" autocomplete="off"></td> </tr> <tr> <td class="edit_tbltext">User[<font color="#5375bd"><strong> 10 </strong></font>]: <input class="t_effect" type="text" name="field10_user" id="field10_user" value="<?php echo "$return_name10"; ?>" autocomplete="off"></td> <td class="edit_tbltext">Points[<font color="#5375bd"><strong> 10 </strong></font>]: <input class="t_effect" type="text" name="field10_value" id="field10_value" value="<?php echo "$return_value10"; ?>" autocomplete="off"></td> </tr> </table> <input type="hidden" name="filed10_time" id="filed10_time" value="<?php echo "$current_time"; ?>"> <p>Click the button below to save all changes.<br />(Note: Make sure that you do not have empty values, and that each value is the correct type)</p> <input type="Submit" value=" Save Data "> </form><br /> <!-- End of Table for Data --> <table> <tr> <td style="background: #ffffff;"> <a href="http://www.facebook.com/pages/Tech-Life-Forum/104697536290384" alt="Visit Our Facebook Page" title="Visit Our Facebook Page" target="_blank"><img src="images/buttons/social/facebook_btn.png" border="0"></a> </td> <td style="background: #ffffff;"> <a href="http://twitter.com/#TechLifeForum" alt="Visit Our Twitter Page" title="Visit Our Twitter Page" target="_blank"><img src="images/buttons/social/twitter_btn.png" border="0"></a> </td> <tr> </table> </div> <div id="footer"> <p>Copyright Ace ©2011 - Tech.Reboot.Pro</p> </div> <?php } else { ?> <!-- Content here for non-Admin Users --> <div id="content"> <p>You do not have access to this page</p> </div> <?php } ?>

getvalues_names.php:
Code:
<?php include("db.php"); mysql_connect($host,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM $users_tbl"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $return_name1=mysql_result($result,$i,"user1"); $return_name2=mysql_result($result,$i,"user2"); $return_name3=mysql_result($result,$i,"user3"); $return_name4=mysql_result($result,$i,"user4"); $return_name5=mysql_result($result,$i,"user5"); $return_name6=mysql_result($result,$i,"user6"); $return_name7=mysql_result($result,$i,"user7"); $return_name8=mysql_result($result,$i,"user8"); $return_name9=mysql_result($result,$i,"user9"); $return_name10=mysql_result($result,$i,"user10"); $i++; } ?>

getvalues_values.php:
Code:
<?php include("db.php"); mysql_connect($host,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM $points_tbl"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $return_value1=mysql_result($result,$i,"value1"); $return_value2=mysql_result($result,$i,"value2"); $return_value3=mysql_result($result,$i,"value3"); $return_value4=mysql_result($result,$i,"value4"); $return_value5=mysql_result($result,$i,"value5"); $return_value6=mysql_result($result,$i,"value6"); $return_value7=mysql_result($result,$i,"value7"); $return_value8=mysql_result($result,$i,"value8"); $return_value9=mysql_result($result,$i,"value9"); $return_value10=mysql_result($result,$i,"value10"); $i++; } ?>

mod_time.php:
Code:
<?php include("db.php"); mysql_connect($host,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM $modified_tbl"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $return_time=mysql_result($result,$i,"time"); $i++; } ?>

insert.php:
Code:
<?php include("db.php"); $row1_user=$_POST['field1_user']; $row2_user=$_POST['field2_user']; $row3_user=$_POST['field3_user']; $row4_user=$_POST['field4_user']; $row5_user=$_POST['field5_user']; $row6_user=$_POST['field6_user']; $row7_user=$_POST['field7_user']; $row8_user=$_POST['field8_user']; $row9_user=$_POST['field9_user']; $row10_user=$_POST['field10_user']; $row1_val=$_POST['field1_value']; $row2_val=$_POST['field2_value']; $row3_val=$_POST['field3_value']; $row4_val=$_POST['field4_value']; $row5_val=$_POST['field5_value']; $row6_val=$_POST['field6_value']; $row7_val=$_POST['field7_value']; $row8_val=$_POST['field8_value']; $row9_val=$_POST['field9_value']; $row10_val=$_POST['field10_value']; mysql_connect($host,$username,$password); mysql_select_db($database) or die( "Unable to select database"); /* $query = "UPDATE `data_user` SET `id`=1, `user1`='user1value', `user2`=$row2_user, `user3`=$row3_user, `user4`=$row4_user, `user5`=$row5_user, `user6`=$row6_user, `user7`='user7value', `user8`=$row8_user, `user9`=$row9_user, `user10`=$row10_user WHERE 1"; */ $query_users = "UPDATE `data_user` SET `id`=1, `user1`='$row1_user', `user2`='$row2_user', `user3`='$row3_user', `user4`='$row4_user', `user5`='$row5_user', `user6`='$row6_user', `user7`='$row7_user', `user8`='$row8_user', `user9`='$row9_user', `user10`='$row10_user' WHERE 1"; $query_values = "UPDATE `data_count` SET `id`=1, `value1`=$row1_val, `value2`=$row2_val, `value3`=$row3_val, `value4`=$row4_val, `value5`=$row5_val, `value6`=$row6_val, `value7`=$row7_val, `value8`=$row8_val, `value9`=$row9_val, `value10`=$row10_val WHERE 1"; $query_modified = "UPDATE `modified` SET `id`=1,`time`=UTC_TIMESTAMP() WHERE 1"; mysql_query($query_users) or die( "An error had occured while updating the users database: " .mysql_error (). ":" .mysql_errno () ); mysql_query($query_values) or die( "An error had occured while updating the users database: " .mysql_error (). ":" .mysql_errno () ); mysql_query($query_modified) or die( "An error had occured while updating the modified timestamp: " .mysql_error (). ":" .mysql_errno () ); mysql_close(); header("location:member_ranks.php"); ?>

login.php:
Code:
<html> <head> <title>Member Rank Authentication</title> <link rel="shortcut icon" href="favicon.ico"> <link href="textfield.css" rel="stylesheet" type="text/css" /> <link href="login.css" rel="stylesheet" type="text/css"/> </head> <div id="logo"> <p align="center"><img src="images/authorization.png"></p> </div> <div id="content"> <table class="login_form" border="0px"> <tr border="0"> <form name="form1" method="post" action="checklogin.php"> <td> <table class="innertable" cellpadding="3" cellspacing="1" border="0"> <tr><br /> <td colspan="3"><strong>AdminCP Login</strong></td> </tr> <tr> <td class="tbl_row">Username:</td> <td class="input_textfield"><input class="t_effect" name="myusername" type="text" id="myusername" autocomplete="off"></td> </tr> <tr> <td class="tbl_row">Password:</td> <td class="input_textfield"><input class="t_effect" name="mypassword" type="password" id="mypassword" autocomplete="off"></td> </tr> <tr> <td></td> <td align="left" height="50px">      <input type="submit" name="Submit" value=" Sign In "><br /></td> </tr> </table> </td> </form> </tr> </table> <p class="smalltext" align="center">Authorization Required To Proceed. Please Login First</p> </div> </html>

login_status.php:
Code:
<html> <head> <title>Login Status</title> <link rel="shortcut icon" href="favicon.ico"> <link href="login.css" rel="stylesheet" type="text/css"/> <meta type="style/css" link="login.css"> </head> <body> <?php session_start(); if ($_SESSION['isadmin'] = 'yes') { ?> <div class="login_success">Login Successful - Redirecting you in a few seconds...</div> <!-- Redirect towards the member_ranks.php page --> <meta http-equiv="refresh" content="1;url=member_ranks.php"> </body> </html> <?php } ?>

logout.php:
Code:
<? session_start(); session_destroy(); header("location:member_ranks.php"); //Move back to the login page ?>

member_ranks.php:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Member Ranks - View</title> <link rel="shortcut icon" href="favicon.ico"> <link href="style.css" rel="stylesheet" type="text/css"/> <script language="JavaScript"> if (document.images) { img1_on =new Image(); img1_on.src ="images/buttons/signout_h.png"; img1_off=new Image(); img1_off.src="images/buttons/signout.png"; } if (document.images) { img2_on =new Image(); img2_on.src ="images/buttons/edit_values_h.png"; img2_off=new Image(); img2_off.src="images/buttons/edit_values.png"; } if (document.images) { img3_on =new Image(); img3_on.src ="images/buttons/main_page_h.png"; img3_off=new Image(); img3_off.src="images/buttons/main_page.png"; } if (document.images) { img4_on =new Image(); img4_on.src ="images/buttons/info_h.png"; img4_off=new Image(); img4_off.src="images/buttons/info.png"; } if (document.images) { img5_on =new Image(); img5_on.src ="images/buttons/forum_h.png"; img5_off=new Image(); img5_off.src="images/buttons/forum.png"; } if (document.images) { img6_on =new Image(); img6_on.src ="images/buttons/help_h.png"; img6_off=new Image(); img6_off.src="images/buttons/help.png"; } if (document.images) { img7_on =new Image(); img7_on.src ="images/buttons/signin_h.png"; img7_off=new Image(); img7_off.src="images/buttons/signin.png"; } function handleOver() { if (document.images) document.imgName.src=img_on.src; } function handleOut() { if (document.images) document.imgName.src=img_off.src; } function movr(k) { if (document.images) eval('document.img'+k+'.src=img'+k+'_on.src'); } function mout(k) { if (document.images) eval('document.img'+k+'.src=img'+k+'_off.src'); } function handleOver() { if (document.images) document.imgName.src=img_on.src; } function handleOut() { if (document.images) document.imgSource.src=img_off.src; } </script> </head> <?php include("getvalues_names.php"); include("getvalues_values.php"); include("mod_time.php"); session_start(); if (@$_SESSION['isadmin']) { ?> <!-- Content here for Admin Users --> <!-- Administration Control Panel Bar --> <div id="nav_bar"> <div id="nav_text">You are now logged in as an :: <strong>Administrator</strong></div> <div id="nav_buttons"> <a href="#" onMouseOver="movr(6);return true;" onMouseOut="mout(6);return true;"><img name=img6 src="images/buttons/help.png" border="0"></a> <a href="#" onMouseOver="movr(4);return true;" onMouseOut="mout(4);return true;"><img name=img4 src="images/buttons/info.png" border="0"></a> <a href="http://tech.reboot.pro" target="_blank" onMouseOver="movr(5);return true;" onMouseOut="mout(5);return true;"><img name=img5 src="images/buttons/forum.png" border="0"></a> <a href="edit_values.php" onMouseOver="movr(2);return true;" onMouseOut="mout(2);return true;"><img name=img2 src="images/buttons/edit_values.png" border="0"></a> <a href="logout.php" onMouseOver="movr(1);return true;" onMouseOut="mout(1);return true;"><img name=img1 src="images/buttons/signout.png" border="0"></a> </div> </div> <!-- End of Admin Bar --> <div id="content"> <!-- Table for Data --> <table id="data_table" border=1> <tr> <th scope="col" id="table_header">Username</th> <th scope="col" id="table_header">Points</th> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name1"; ?></td> <td width="200px" height="30px"><?php echo "$return_value1"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name2"; ?></td> <td width="200px" height="30px"><?php echo "$return_value2"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name3"; ?></td> <td width="200px" height="30px"><?php echo "$return_value3"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name4"; ?></td> <td width="200px" height="30px"><?php echo "$return_value4"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name5"; ?></td> <td width="200px" height="30px"><?php echo "$return_value5"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name6"; ?></td> <td width="200px" height="30px"><?php echo "$return_value6"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name7"; ?></td> <td width="200px" height="30px"><?php echo "$return_value7"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name8"; ?></td> <td width="200px" height="30px"><?php echo "$return_value8"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name9"; ?></td> <td width="200px" height="30px"><?php echo "$return_value9"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name10"; ?></td> <td width="200px" height="30px"><?php echo "$return_value10"; ?></td> </tr> </table> <!-- End of Table for Data --> <p class="smalltext">Last Modified: [<?php echo "$return_time"; ?> UTC]</p> <table> <tr> <td style="background: #ffffff;"> <a href="http://www.facebook.com/pages/Tech-Life-Forum/104697536290384" alt="Visit Our Facebook Page" title="Visit Our Facebook Page" target="_blank"><img src="images/buttons/social/facebook_btn.png" border="0"></a> </td> <td style="background: #ffffff;"> <a href="http://twitter.com/#TechLifeForum" alt="Visit Our Twitter Page" title="Visit Our Twitter Page" target="_blank"><img src="images/buttons/social/twitter_btn.png" border="0"></a> </td> <tr> </table> </div> <div id="footer"> <p>Copyright Ace ©2011 - Tech.Reboot.Pro</p> </div> <?php } else { ?> <!-- Administration Control Panel Bar --> <div id="nav_bar"> <div id="nav_text">You are now authenticated as a :: <strong>Regular User</strong></div> <div id="nav_buttons"> <a href="#" onMouseOver="movr(6);return true;" onMouseOut="mout(6);return true;"><img name=img6 src="images/buttons/help.png" border="0"></a> <a href="#" onMouseOver="movr(4);return true;" onMouseOut="mout(4);return true;"><img name=img4 src="images/buttons/info.png" border="0"></a> <a href="http://tech.reboot.pro" target="_blank" onMouseOver="movr(5);return true;" onMouseOut="mout(5);return true;"><img name=img5 src="images/buttons/forum.png" border="0"></a> <a href="login.php" onMouseOver="movr(7);return true;" onMouseOut="mout(7);return true;"><img name=img7 src="images/buttons/signin.png" border="0"></a> </div> </div> <!-- End of Admin Bar --> <!-- Content here for non-Admin Users --> <div id="content"> <!-- Table for Data --> <table id="data_table" border=0> <tr> <th scope="col" id="table_header">Username</th> <th scope="col" id="table_header">Points</th> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name1"; ?></td> <td width="200px" height="30px"><?php echo "$return_value1"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name2"; ?></td> <td width="200px" height="30px"><?php echo "$return_value2"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name3"; ?></td> <td width="200px" height="30px"><?php echo "$return_value3"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name4"; ?></td> <td width="200px" height="30px"><?php echo "$return_value4"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name5"; ?></td> <td width="200px" height="30px"><?php echo "$return_value5"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name6"; ?></td> <td width="200px" height="30px"><?php echo "$return_value6"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name7"; ?></td> <td width="200px" height="30px"><?php echo "$return_value7"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name8"; ?></td> <td width="200px" height="30px"><?php echo "$return_value8"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name9"; ?></td> <td width="200px" height="30px"><?php echo "$return_value9"; ?></td> </tr> <tr> <td width="250px" height="30px"><?php echo "$return_name10"; ?></td> <td width="200px" height="30px"><?php echo "$return_value10"; ?></td> </tr> </table> <!-- End of Table for Data --> <p class="smalltext">Last Modified: [<?php echo "$return_time"; ?> UTC]</p> <table> <tr> <td style="background: #ffffff;"> <a href="http://www.facebook.com/pages/Tech-Life-Forum/104697536290384" alt="Visit Our Facebook Page" title="Visit Our Facebook Page" target="_blank"><img src="images/buttons/social/facebook_btn.png" border="0"></a> </td> <td style="background: #ffffff;"> <a href="http://twitter.com/#TechLifeForum" alt="Visit Our Twitter Page" title="Visit Our Twitter Page" target="_blank"><img src="images/buttons/social/twitter_btn.png" border="0"></a> </td> <tr> </table> </div> <div id="footer"> <p>Copyright Ace ©2011 - Tech.Reboot.Pro</p> </div> <?php } ?>

There's also some cool html tricks in here that I share with you about meta tag redirects, even though php redirects are included here as well. This is a more bulky version just so that you have a better understanding of how things work. For getting the values and sending them in you could replace the number in the variables themselves with an external variable and increment it for example to shorten the code.

Protection in here for SQL injections, and XSS cross site scripting attacks as well for login.php. We define a session variable to determine whether user has successfully authenticated or not on each page that requires authentication. Which is why you see the no access page for edit_values.php in the video when signed off. For both edit_values.php and member_ranks.php we GET information from the database and store it in specific locations on page load because when you're viewing the ranks page you want to see the updated content in the database and editing you can't have null values or you'll get a minor mysql error so it's a lot easier to paste the data into the edit boxes to make sure that you know what you're editing (1) and also to make sure that you don't have to fill everything in all the time even if you're just editing a single value (2).

This page was built entirely from scratch on my part so it's very exclusive really. All the javascript, php, css, html, images.

If i'm allowed to post a live demo of this, here: http://www.pimped-pixels.net/forum/ranks..._ranks.php
Take a look for yourself. Otherwise, someone remove it please.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #2
I didn't look at all of it, but you have some SQL injection vulns in insert.php.

With out access to it actually being hosting I can't give you an exact string that would work, but something like

field1_value=admin;sql here--

would work


Reply

RE: Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #3
(11-27-2011, 11:07 PM)puma Wrote: I didn't look at all of it, but you have some SQL injection vulns in insert.php.

With out access to it actually being hosting I can't give you an exact string that would work, but something like

field1_value=admin;sql here--

would work

I check for access to even use that file before the end user can use it, so no vulnerabilities there.

And this wouldn't work:
Code:
field1_value=admin;sql here--

Why would you focus on each value when all you really need to focus on is the sql query at the end of the file after those values?

It's used through editvalues.php
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #4
(11-27-2011, 11:18 PM)Infinity Wrote:
(11-27-2011, 11:07 PM)puma Wrote: I didn't look at all of it, but you have some SQL injection vulns in insert.php.

With out access to it actually being hosting I can't give you an exact string that would work, but something like

field1_value=admin;sql here--

would work

I check for access to even use that file before the end user can use it, so no vulnerabilities there.

And this wouldn't work:
Code:
field1_value=admin;sql here--

Why would you focus on each value when all you really need to focus on is the sql query at the end of the file after those values?

It's used through editvalues.php

It would work if you called insert.php directly. It doesn't matter which query you target the result is the same, sql injection. You need to sanitize your input.

Reply

RE: Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #5
There you go, quick simple solution
Code:
<?php include("db.php"); $row1_user=mysql_real_escape_string($_POST['field1_user']); $row2_user=mysql_real_escape_string($_POST['field2_user']); $row3_user=mysql_real_escape_string($_POST['field3_user']); $row4_user=mysql_real_escape_string($_POST['field4_user']); $row5_user=mysql_real_escape_string($_POST['field5_user']); $row6_user=mysql_real_escape_string($_POST['field6_user']); $row7_user=mysql_real_escape_string($_POST['field7_user']); $row8_user=mysql_real_escape_string($_POST['field8_user']); $row9_user=mysql_real_escape_string($_POST['field9_user']); $row10_user=mysql_real_escape_string($_POST['field10_user']); $row1_val=mysql_real_escape_string($_POST['field1_value']); $row2_val=mysql_real_escape_string($_POST['field2_value']); $row3_val=mysql_real_escape_string($_POST['field3_value']); $row4_val=mysql_real_escape_string($_POST['field4_value']); $row5_val=mysql_real_escape_string($_POST['field5_value']); $row6_val=mysql_real_escape_string($_POST['field6_value']); $row7_val=mysql_real_escape_string($_POST['field7_value']); $row8_val=mysql_real_escape_string($_POST['field8_value']); $row9_val=mysql_real_escape_string($_POST['field9_value']); $row10_val=mysql_real_escape_string($_POST['field10_value']); mysql_connect($host,$username,$password); mysql_select_db($database) or die( "Unable to select database"); /* $query = "UPDATE `data_user` SET `id`=1, `user1`='user1value', `user2`=$row2_user, `user3`=$row3_user, `user4`=$row4_user, `user5`=$row5_user, `user6`=$row6_user, `user7`='user7value', `user8`=$row8_user, `user9`=$row9_user, `user10`=$row10_user WHERE 1"; */ $query_users = "UPDATE `data_user` SET `id`=1, `user1`='$row1_user', `user2`='$row2_user', `user3`='$row3_user', `user4`='$row4_user', `user5`='$row5_user', `user6`='$row6_user', `user7`='$row7_user', `user8`='$row8_user', `user9`='$row9_user', `user10`='$row10_user' WHERE 1"; $query_values = "UPDATE `data_count` SET `id`=1, `value1`=$row1_val, `value2`=$row2_val, `value3`=$row3_val, `value4`=$row4_val, `value5`=$row5_val, `value6`=$row6_val, `value7`=$row7_val, `value8`=$row8_val, `value9`=$row9_val, `value10`=$row10_val WHERE 1"; $query_modified = "UPDATE `modified` SET `id`=1,`time`=UTC_TIMESTAMP() WHERE 1"; @mysql_query($query_users) or die( "An error had occured while updating the users database: " .mysql_error (). ":" .mysql_errno () ); @mysql_query($query_values) or die( "An error had occured while updating the users database: " .mysql_error (). ":" .mysql_errno () ); @mysql_query($query_modified) or die( "An error had occured while updating the modified timestamp: " .mysql_error (). ":" .mysql_errno () ); mysql_close(); header("location:member_ranks.php"); ?>

I wanted to put them in a loop so I didn't have to write it out each time, poorly written code, but it works.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #6
Almost perfect Smile

The last thing you need to do is put ticks ' around all of the values on the right hand of the equals sign in the queries. If you don't you can still open your self up.

Reply

RE: Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #7
DAHM just spent the last 3 hours making a tutorial on Login system
looked over the site for one already made but didnt know .Sad
<?php echo "Very inactive at this current moment in time"; ?>
[Image: Z8KDe.png]

Reply

RE: Complete Secure PHP Login Class (MySQL Connection Retrieve and Input Data to Display) #8
The title says login class... but I don't see any classes... =(

Anyhow... quick tip... use nonces... and assume that a user will attempt to access every file... files the user is not intended to access should have some sort of sanity check where it looks for a session nonce... and if it doesn't exist exits and redirects...

Reply







Users browsing this thread: