Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

PHP Login Page With SQL Support

PHP Login Page With SQL Support

RLS0812
RLS0812
Code Snippets · · 2 min read
2,727 4
This is not the best written longin page ever written, but should give you a good idea how to write your own. This code includes it's own anti injection code, and also uses it's own session IDs.

The SQL.PHP file has mechanisms for auto building tables, deleting elements from tables and outputting what you have in your tables.

Index.htmlLogin Page body { text-align:center; } ';}// End Of Declarationns if (!check("Sign_Up") and !check("Sign_In") and !check("Su_User_Name") and !check("Si_User_Name") and !isset($_COOKIE["ID"]) ){ echo "Welcome! Please sign in or sign up !
"; button("Sign_In","Sign In"); button("Sign_Up","Sign Up"); } if (check("Sign_In") ) {echo 'Please sign in here.

User Name: Password: Submit !
'; } if (check("Sign_Up") ) { echo 'Please do not use special characters.
Letters, numbers and _ allowed.
Lenght must be longer than 4 characters.

User Name: Game Name: Password: Submit !
'; } if (check("Su_User_Name") and check("Su_Game_Name") and check("Su_Password") ){ if (!verify($_POST["Su_User_Name"]) or !verify($_POST["Su_Game_Name"]) or !verify($_POST["Su_Password"]) or strlen($_POST["Su_User_Name"]) < 5 or strlen($_POST["Su_Game_Name"]) < 5 or strlen($_POST["Su_Password"]) < 5 ) { echo "<h3>Letters, numbers and _ only. Lenght must be greater than 4 characters.</h3>
"; button("x","<-- Back"); } else{ if (test("Login_Name",$_POST["Su_User_Name"]) ){ echo "User name taken.
"; button("x","<-- Back"); } elseif(test("Game_Name",$_POST["Su_Game_Name"]) ){ echo "Game name taken.
"; button("x","<-- Back"); } else{ $x = "1234567890abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXYZ"; $x2 = ''; for ($i = 0; $i < 21; $i++) { $x2 .= $x[rand(0, strlen($x) - 1)]; } mysqli_query($sql,"INSERT INTO ".$table." (Game_Name,Login_Name,Blarg,ID)VALUES('".$_POST["Su_Game_Name"]."','".$_POST["Su_User_Name"]."','" .$_POST["Su_Password"]."','".$x2."')"); echo "Account created !
"; $temp = mysqli_fetch_assoc(mysqli_query($sql,"SELECT * FROM ".$table." WHERE ID='".$x2."'") ); setcookie("ID",$temp["ID"], time()+3600); button("x","<-- Back"); } } } if (check("Si_User_Name") and check("Si_Password") ) { $tmp1 = strip($_POST["Si_User_Name"]); $tmp2 = strip($_POST["Si_Password"]); if (test("Login_Name",$tmp1) and test("Blarg",$tmp2) ){ echo "Logged in !
"; $temp = mysqli_fetch_assoc(mysqli_query($sql,"SELECT * FROM ".$table." WHERE Login_Name='".$tmp1."'") ); setcookie("ID",$temp["ID"], time()+3600); button("x","<-- Back"); } else{ echo "Bad name or password. Please try again.
"; button("x","<-- Back"); } } ?>

.
sql.php
. Login Page
'; }}if (isset($_COOKIE["ID"])){ $result = mysqli_query($sql,"SELECT ID FROM ".$table." WHERE ID='".strip($_COOKIE["ID"])."'"); if (mysqli_fetch_array($result)){ $temp = mysqli_fetch_assoc(mysqli_query($sql,"SELECT Game_Name FROM ".$table." WHERE ID='".strip($_COOKIE["ID"])."'") ); echo "Welcome " . $temp["Game_Name"] . " !
"; } else{ unset($_COOKIE["ID"]); back(); }} else{ back(); }// Table Handeling if ($update){if ( mysqli_query($sql, "SELECT 1 FROM ". $table . " ") ) { $get = mysqli_query($sql, "SHOW COLUMNS FROM " . $table); echo "<h2>Existing columns</h2>
"; while ($col = mysqli_fetch_row($get)) { echo "Existing column: " .$col[0] . "
";} echo"<h2>=====</h2>"; for ($x=0; $x!= count($add); $x++){ if(!mysqli_query($sql,"SELECT ". $add[$x] ." FROM ".$table . " ") ){ mysqli_query($sql,"ALTER TABLE ". $table ." ADD ".$add[$x] . " TEXT "); echo "Adding column: ". $add[$x] . "
"; }} for ($x=0; $x!= count($sub); $x++){ if(mysqli_query($sql,"SELECT ". $sub[$x] ." FROM ".$table . " ") ){ mysqli_query($sql,"ALTER TABLE " . $table . " DROP COLUMN " . $sub[$x] . " "); echo "Removing column: ". $sub[$x] . "
"; }} echo"<h2>=====</h2>"; $get = mysqli_query($sql, "SHOW COLUMNS FROM " . $table); echo "<h2>Modifyed columns</h2>
"; while ($col = mysqli_fetch_row($get)) { echo "Existing column: " .$col[0] . "
"; }}else{echo "Error: Table '" . $table . "' does not exist
";} } ?>

Discussion

Loading comments...