| | |
very simple login script (checking 2 variables before writing cookie)
Thread Solved |
Hi all,
I have just put together a simple log in script from various tutorials on the web and at the moment it is only checking the username entered by the user against what is in my database.
I cant find any infromation about any kind of AND function or any other check the password as well as the username so thats what i need help with
here is what i have already:
Thanks guyyys
Max
I have just put together a simple log in script from various tutorials on the web and at the moment it is only checking the username entered by the user against what is in my database.
I cant find any infromation about any kind of AND function or any other check the password as well as the username so thats what i need help with
here is what i have already:
PHP Syntax (Toggle Plain Text)
<?php // Connects to your Database mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error());; $uname = $_POST['uname']; $pword = $_POST['pword']; //gets username and password from uname and pword fields on previous page $result = mysql_query("SELECT * FROM logins WHERE uname='$uname'"); if($row = mysql_fetch_array($result)) { setcookie("loggedin", "$uname", time()+3600); echo "logged in as: "; echo $row['uname']; echo "<br />and cookie written."; echo "<br />"; echo 'click <a href="cookie.php">here</a> to view cookie information.<br/><a href="login.php">Back to login page.</a>'; } else { echo "wrong login information"; } ?>
Thanks guyyys

Max
| IPCopy |
The only google chrome extension that lets you copy your IP to the clipboard with one click.
https://chrome.google.com/extensions...ogchjmmgjjfola
The only google chrome extension that lets you copy your IP to the clipboard with one click.
https://chrome.google.com/extensions...ogchjmmgjjfola
make sure sanatize your inputs to protect against sql injection.
as for the login, just change your query to:
also, a better way to do a login script is to see the number of results returned from the query.
ex.
as for the login, just change your query to:
PHP Syntax (Toggle Plain Text)
SELECT * FROM logins WHERE uname='$uname' AND password='$pword'
also, a better way to do a login script is to see the number of results returned from the query.
ex.
PHP Syntax (Toggle Plain Text)
//run query here if (mysql_num_rows($result) == 1) { //then log the person in } else { //they have invalid credentials }
Last edited by kkeith29; Jun 26th, 2008 at 10:50 pm.
you can change your query like this to validate a username with its password.
(let us say pword is your password table in db...)
replace this:
with something like this:
(let us say pword is your password table in db...)
replace this:
php Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM logins WHERE uname='$uname'");
with something like this:
php Syntax (Toggle Plain Text)
$result = mysql_query("SELECT * FROM logins WHERE uname='$uname' and pword='$pword'");
PHP,Javascript and AJAX tutorials.
I am currently accepting CodeIgniter,JQuery,WordPress ,PSD->XHTML jobs.Contact Me.
I am currently accepting CodeIgniter,JQuery,WordPress ,PSD->XHTML jobs.Contact Me.
Ahh! keith is faster than me
PHP,Javascript and AJAX tutorials.
I am currently accepting CodeIgniter,JQuery,WordPress ,PSD->XHTML jobs.Contact Me.
I am currently accepting CodeIgniter,JQuery,WordPress ,PSD->XHTML jobs.Contact Me.
ha xD Thanks guys
i swear i tried that 
oh wells thanks for the help guys. and ill def. include the protection against mysql injection
now just to find out what it actually is.....
Thanks again.
i swear i tried that 
oh wells thanks for the help guys. and ill def. include the protection against mysql injection
now just to find out what it actually is.....

Thanks again.
| IPCopy |
The only google chrome extension that lets you copy your IP to the clipboard with one click.
https://chrome.google.com/extensions...ogchjmmgjjfola
The only google chrome extension that lets you copy your IP to the clipboard with one click.
https://chrome.google.com/extensions...ogchjmmgjjfola
•
•
Join Date: May 2007
Posts: 14
Reputation:
Solved Threads: 0
May I ask related question in here?
I was just reading around, found this thread and remembered that I always wanted to know if it's possible to query database only once, at first visit, to confirm login/pwd is correct.
Basicaly, is there a way to let user browse protected area without checking the database on every page view? (saving id in cookies is not a way
)
I was just reading around, found this thread and remembered that I always wanted to know if it's possible to query database only once, at first visit, to confirm login/pwd is correct.
Basicaly, is there a way to let user browse protected area without checking the database on every page view? (saving id in cookies is not a way
) Try to store the ipaddress of the user and date into a new table then have a timeline for how many days/months etc. on how the id will be saved in that ipadd by subtracting current date from the stored date login...Just my idea...
PHP,Javascript and AJAX tutorials.
I am currently accepting CodeIgniter,JQuery,WordPress ,PSD->XHTML jobs.Contact Me.
I am currently accepting CodeIgniter,JQuery,WordPress ,PSD->XHTML jobs.Contact Me.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Creation of Dynamic Menu for Web pages
- Next Thread: help please, displaying content problem
Views: 2649 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for PHP
access ajax apache api archive array arrays auto beginner binary box buttons cakephp check checkbox class cms code database date development directory display download dropdown dynamic echo email error file files form forms function functions header href htaccess html image images include insert ip java javascript joomla jquery limit link list login loop mail mlm mod_rewrite multiple mysql order parse paypal pdf php problem query radio redirect regex remote rewrite script search select server session shopping soap sort source sql storage string structure syntax system table tutorial update upload url user validate validation validator variable video web website wordpress xml






