GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Dumb question: making a login box (https://gfy.com/showthread.php?t=437376)

Dailydiapers 02-26-2005 05:11 PM

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 :helpme

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?

ssp 02-26-2005 05:16 PM

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.

Fake Nick 02-26-2005 05:17 PM

http://www.gofuckyourself.com/showthread.php?t=437375

Dailydiapers 02-26-2005 06:53 PM

PHP is one of those dumbfounded area for me, looking to include it (log-in box) in a straight HTML design.

calmlikeabomb 02-26-2005 07:07 PM

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>

If this form is submitted check for user in database set cookies and redirect.
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.

Protect pages with something like this:
Code:

<?php
if (!isset($_COOKIE['user_id'])) {
        header ("Location:  http://www.domain.com/login.php");
        }
?>

You'll also need a form to register your users to the database.


Dumbass :winkwink:

ssp 02-26-2005 07:10 PM

Quote:

Originally Posted by Dailydiapers
PHP is one of those dumbfounded area for me, looking to include it (log-in box) in a straight HTML design.

Creating a login box wont be difficult. But you need some kind of dynamics to process whats submitted. Either Perl, PHP, ASP.

stevo 02-26-2005 07:13 PM

Can you have PHP read a .htpasswd file? Or does it have to read from its own database?


All times are GMT -7. The time now is 07:14 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123