Jump to content

PHP login


Wirral

Recommended Posts

Hi I am trying to make a php login for a website using MS access database.

 

I don't want the users to register I want to give them pre set passwords and usernames here is my code so far can some one tell me were I am going wrong and If i am linking it to the database properly thanks.

 

<php

// Connects to your Database

mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error());

mysql_select_db("login") or die(mysql_error());

 

if(isset($_COOKIE['ID_my_site']))

{

$username = $_COOKIE['ID_my_site'];

$pass = $_COOKIE['Key_my_site'];

$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());

while

($info = mysql_fetch_array( $check ))

{

if ($pass != $info['password'])

{

}

else

{

header("Location: members.php");

 

}

}

}

 

if (isset($_POST['submit'])) { // if form has been submitted

 

// makes sure they filled it in

if(!$_POST['username'] | !$_POST['pass']) {

die('You did not fill in a required field.');

}

 

if (!get_magic_quotes_gpc()) {

$_POST['email'] = addslashes($_POST['email']);

}

$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

 

$_POST['pass'] = stripslashes($_POST['pass']);

$info['password'] = stripslashes($info['password']);

$_POST['pass'] = md5($_POST['pass']);

 

//gives error if the password is wrong

if ($_POST['pass'] != $info['password']) {

die('Incorrect password, please try again.');

}

else

{

 

// if login is ok then we add a cookie

$_POST['username'] = stripslashes($_POST['username']);

$hour = time() + 3600;

setcookie(ID_my_site, $_POST['username'], $hour);

setcookie(Key_my_site, $_POST['pass'], $hour);

 

//then redirect them to the members area

header("Location: members.php");

}

}

}

else

{

 

// if they are not logged in

?>

<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">

<table border="0">

<tr><td colspan=2><h3>Login</h3></td></tr>

<tr><td>Username:</td><td>

<input type="text" name="username" maxlength="40">

</td></tr>

<tr><td>Password:</td><td>

<input type="password" name="pass" maxlength="50">

</td></tr>

<tr><td colspan="2" align="right">

<input type="submit" name="submit" value="Login">

</td></tr>

</table>

</form>

<?php

}

 

Thanks

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

http://uk2.php.net/odbc_connect

 

further down on that page is a comment leading to http://www.phpfreaks.com/tutorials/61/0.php

 

hope this helps,

 

---

Link above is invalid (the comment on php.net will need to be updated OR this webserver will need to redirect to the new link. from the old link)

the new link is: http://www.phpfreaks.com/forums/index.php/topic,186679.0.html

Link to comment
https://forums.phpfreaks.com/topic/97698-php-login/#findComment-499929
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.