Something for my site

Status
Not open for further replies.

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
The way you worded that can be taken many different ways.

At one point I helped a member on here, and made a very simple php password script..


PHP:
<?php

	###################
	## Connect To DB ##
	###################

$username = ""; // MySQL Username
$password = ""; // MySQL Password
$database = ""; // MySQL Database Name

$connection = mysql_connect("localhost", $username, $password) or die(mysql_error());
$dbs = mysql_select_db($database) or die(mysql_error());

	###########################
	## If Form Was Submitted ##
	###########################

if ($_POST['action'] == "login")
	{

$username = $_POST['username'];
$password = $_POST['password'];
$results = mysql_query("SELECT * FROM `members` WHERE `username` = '$username' AND `password` = '$password'");
$row = mysql_fetch_array($results);


	##################################################  #####################
	## If Row Existed With Username and Pass equal to what was submitted ##
	##################################################  #####################

	if ($row['username'])
		{
	$cookie_name = "auth";
	$cookie_value = "ok";
	$cookie_expire = "0";
	$cookie_domain = "yoursite.com";
	
	setcookie($cookie_name, $cookie_value, $cookie_expire, "/" , $cookie_domain, 0);
	header("Location: /secretpage.php");
		} else {

	##############################
	## Else, Show Error Message ##
	##############################
	echo "Error Logging You in. Please Click <a href=\"login.php\">Here To Try Again";

		}
	################################################
	## Else, Show Form Because It Wasnt Submitted ##
	################################################

	} else {

?>

<form action="login.php" method="POST">
<input type="text" name="username" maxlength="16">

<input type="password" name="password" maxlength="16">

<input type="submit" value="Login!">
<input type="hidden" name="action" value="login">
</form>
<?php
	}
?>

I'm going to edit this and fix it quick, so hold on. :)

Edit: Fixed up, I believe. In order to use this, you need a database set up that contains a table named "members" to hold member accounts. The table needs to have the 2 columns username and password. Make a row in that table containing a username and password. When a user logs in successfully, he will be redirected to "secretpage.php", you can change what you want it to do though, easily. If you have any problems with it, just post back and I'll try to help you with them. I'm not sure if you know any php or anything, so I don't know.

I'm not sure if that is what you are looking for, but it should start you off with it. Google something like PHP Login Script if you need somethign different.
 
Last edited:

Daemon

New Member
Messages
64
Reaction score
0
Points
0
Dude Click on my site Hi, I have a website that i want to have a login on it do any of you no how to make a login for my site my site link is http://crazyboycentral.x10hosting.com .
I want A login on it like where i can login and do stuff But i know there is more codeing then that to do and I dont know exactly what to do So please help me I know theres more to it then that.
 

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
I already posted in your thread.. Why post again in here?
 
Status
Not open for further replies.
Top