![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Oct 2003
Location: USA
Posts: 1,079
|
Dumb question: making a login box
Okay, forgive the dumb noob question, but i'm a self-taught webmaster and just don't know some things ya'll think are simple
![]() I'm redesigning one of my sites that's a combination of free and pay services. On the fre side I want to put a login box for the protected directory, rather than using the pop-up login box you get when you link directly to the protected directory. Can someone tell me how to write (or give me a template) the code for the login box? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Jan 2005
Location: United Kingdom
Posts: 7,990
|
Use PHP and lookup an online tutorial on how to do this. There are loads and loads around which help you make one step by step.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
So Fucking Banned
Join Date: Jul 2004
Location: go troll goo!
Posts: 7,708
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Oct 2003
Location: USA
Posts: 1,079
|
PHP is one of those dumbfounded area for me, looking to include it (log-in box) in a straight HTML design.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
|
Use php and sql
Your login form:
Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method=p.ost> Username: <input type="text" name="username" maxlength="20" /> Password:<input type="password" name="password" maxlength="20" /> <input type="submit" name="submit" value="Login"> </form> Code:
<?php // Create a function for escaping the data. function escape_data ($data) { global $dbc; // Need the connection. if (ini_get('magic_quotes_gpc')) { $data = stripslashes($data); } return mysql_real_escape_string($data, $dbc); } // End of function. if (isset($_POST['submit'])) { // Check if the form has been submitted. require_once ('../mysql_connect.php'); // Connect to the database. if (empty($_POST['username'])) { // Validate the username. $u = FALSE; echo '<p><font color="red" >You forgot to enter your username!</font></p>'; } else { $u = escape_data($_POST['username']); } if (empty($_POST['password'])) { // Validate the password. $p = FALSE; echo '<p><font color="red" >You forgot to enter your password!</font></p>'; } else { $p = escape_data($_POST['password']); } if ($u && $p) { // If everything's OK. // Query the database. $query = "SELECT customer_id, firstname FROM customers WHERE username='$u' AND password=PASSWORD('$p')"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); if ($row) { // A match was made. // Start the session, register the values & redirect. setcookie ('user_id', $row[0], time()+2419200, '/', '', 0); header ("Location: http://www.domain.com/index.php"); ob_end_flush(); // Delete the buffer. exit(); } else { // No match was made. echo '<p><font color="red" >The username and password entered do not match those on file.</font></p>'; } mysql_close(); // Close the database connection. } else { // If everything wasn't OK. echo '<p><font color="red" >Please try again.</font></p>'; } } // End of SUBMIT conditional. Code:
<?php if (!isset($_COOKIE['user_id'])) { header ("Location: http://www.domain.com/login.php"); } ?> Dumbass ![]()
__________________
subarus. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Confirmed User
Join Date: Jan 2005
Location: United Kingdom
Posts: 7,990
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Join Date: Aug 2002
Location: Orlando, Florida
Posts: 2,051
|
Can you have PHP read a .htpasswd file? Or does it have to read from its own database?
|
![]() |
![]() ![]() ![]() ![]() ![]() |