Jump to content

Login Script


the sr5

Recommended Posts

Ok once again found that my old scripts are no longer working... can anyone take a look at these and let me know what they think.... reason i have all my old scripts are because they were all backed up from my old host and i just reopened my site again with a new host... here are the 3 files that i normally use as my login script

 

functions.inc.php

<?
function connect() {
@mysql_connect("localhost", "username", "password");
}

function login($username, $passwd) {
// check username and password with db 
// if yes, return true 
// else return false 

// check if username is unique 
$result = mysql_query("select * from mysql_database.user where username='$username' and passwd = password('$passwd')") or die(mysql_error());

if (!mysql_num_rows($result)) {
	return 0;
} else {
	return 1;
}
}
function login2($username, $passwd) {
// check username and password with db 
// if yes, return true 
// else return false 

// check if username is unique 
$result = mysql_query("select * from mysql_database.user where username='$username' and passwd = password('$passwd')") or die(mysql_error());

if (!mysql_num_rows($result)) {
	return 0;
} else {
	return 1;
}
}

function check_valid_user() {
// see if somebody is logged in and notify them if not  
global $valid_user;
if (session_is_registered("valid_user")) {
	echo "Logged in as $valid_user."; 
	echo "<br>"; 
} else { 
	// they are not logged in 
	echo "Problem:"; 
	echo "You are not logged in.<br>";  
} 
}

?>

 

do_login2.php:

<?
require 'functions.inc.php';
connect();
session_start();

if ($username && $passwd) {

if (login($username, $passwd)) { 
	session_register("valid_user");
	$valid_user = $username;
	$login = Post;
	header("Location: index.php");
	exit();
} else {

if (login2($username, $passwd)) { 
	session_register("valid_user");
	$valid_user = $username;
	$login = Post;
	header("Location: index.php");
	exit();
} else {
		$error = "Incorrect Login";
	header("Location: index.php?error=$error");
	exit(); 
} 
} 
}
?> 

 

login.php:

		<FORM METHOD="POST" ACTION="do_login2.php">
	<font size="1" face="verdana" color="000000"><IMG SRC="images/arrow.gif"><IMG SRC="images/arrow.gif"> Login
	<table border=0 width="100%">
	<tr>
	<td align=left><div class="txt4">UserID:</div><center><INPUT TYPE="text" NAME="username"  SIZE=16 class=txt2></center> </td>
	</tr><tr>
	<td align=left><div class="txt4">Password:</div><center><INPUT TYPE="password" NAME="passwd"  SIZE=16 class=txt2></center></td>
	</tr>
	</table>
	<center><INPUT TYPE="image" src="images/lbutton.gif"></center>
	</FORM>

 

If anyone could help, that would be great... it just doesn't seem that anyone of my old scripts seem to work... :( do i need to head out here in the next week and purchase a new php for dummies?? All these scripts were written back in the day, they are about 3-4 years old :( im still extremely rusty but still understand for the most part what needs to be done, but as i can see i dont see the error in these three files!

Link to comment
https://forums.phpfreaks.com/topic/102456-login-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.