|
[PHP] A simple loginscript
|
|||
| Author | Message | ||
|
04-09-2006, 10:56 PM
(This post was last modified: 04-12-2006 09:34 PM by Ferali.)
Post: #1
|
|||
|
|||
|
[PHP] A simple loginscript
Hey there everyone.
I thought it would be a good idea to show you how to create a (very) simple loginscript. I know i had huge problems doing this, so ill make it simple for you guys ![]() Dont think i have to explain anything before the tutorial, so "lets rock!" ![]() First of, we want to make an loginform, this is made by some simple HTML code, something like this: Code: <form action="login.php" method="POST" name="login">Now, lets break it down, so you know im not messing around with you ![]() Code: <form action="login.php" method="POST" name="login">I guess you all know the form-tag. This code is very simple, it will just tell the brower to send all the information inside the form to login.php (action="login.php") with the post-method (method="POST"). There is two methods you can use, these are POST and GET. I'll use POST, since GET will send the information along with the URL (ex. http://www.your-url.com/login.php?userna...=yourpass) - which is'nt very safe. POST will send all the information hidden, so, i'll use that. You do as you want The name isnt anything we'll go further into now. Code: Username<input type="text" name="username"><br>This will just make 2 boxes to write your username and password in, and two buttons (one to send the data and one to reset all inputboxes). The name of the username-box and the password-box is important. This will be used later. Right, moving on. Now we need to have a login.php: PHP Code: <?phpBeautiful! *not* Okay, lets break this down aswell! PHP Code: ...This is just to simplify a little, its CAN work without it, but simplifying is good, so.. ![]() Anyway, what is does is that it makes a variable called username / password, and then it gets the POST variable called username / password (This is where the names from the forms comes in. If we had called "password" for "pass", then $_POST["password"] would be $_POST["pass"]. Simple!) and just puts its value in it. PHP Code: if ($username == testuser) {Yes, i know. This is a one-user-only-loginform. Sry about that, but hey, If you read Virtuals post called "[ PHP ] Sessions & Cookies" (Why is it called Sessions & Cookies? Its about MySQL, Right?) you will know everything about MySQL. Then you can use a multi-user-login! Anyway, What it will do is to check if $username is testuser, and $password is testpass, and if it isnt - it dies. Of course you'll have to change these the testuser and testpass to whatever you want. PHP Code: {setcookie("MyCookie", $username); } Cookies! My favorite! This will save a cookie on the computer called MyCookie, and with the value of $username - which now is testuser ![]() You can define the time for it to expire aswell, with setcookie(Name, Value, Time); If you dont set the time for it to expire, it will just expire when the brower is closed. After that, we have a simple link to the memberspage. That is our next step! Not much code is really needed in this page. Just something to check if the cookie exist, and a way to log out. So, here we go! PHP Code: // Check if logged inThere you go. This one is very simple, it just checks if the cookie exist, well, actually - a translation would be "if DeepCookie dousent exist. Kill the load and say Login First". You get it ^^, Last thing, we need a logoutpage. In the memberspage, just write in: Code: <a href="logout.php">logout here</a>And put this in the logout.php: PHP Code: <?That just modifies the cookie so it will expire 1000 seconds ago ![]() There! You have your loginscript! I just made this a little quick, so post whatever non-working code you might find. Take care everyone! /Deep. As the humanity slowly falls. |
|||
|
04-10-2006, 11:13 AM
Post: #2
|
|||
|
|||
|
RE: [PHP] A simple loginscript
Nicely explained
![]() Current Favo Signature :: Clicky Current C4D Signature ::<3 My Full Signature Tutorial :: Clicky |
|||
|
04-10-2006, 01:32 PM
Post: #3
|
|||
|
|||
|
RE: [PHP] A simple loginscript
Nice job
![]() ![]() |
|||
|
04-18-2006, 07:46 PM
Post: #4
|
|||
|
|||
|
RE: [PHP] A simple loginscript
Tnx t have looking for a loginscript for a realy long time, Now i only need to install Dreamweaver
The one, The only Lillen2k
|
|||
|
04-18-2006, 07:58 PM
Post: #5
|
|||
|
|||
|
RE: [PHP] A simple loginscript
Very nice, but maybe write an extension including addslashes and stripslahes etc. to make it more secure
I'm the only one around here that can ban people, what else do you need to know?
|
|||
|
04-18-2006, 08:04 PM
Post: #6
|
|||
|
|||
|
RE: [PHP] A simple loginscript
login script on my site is very similar. Also using cookies. But, on next CMS i ll program i would rather use php sessions. Any experiences with them?
shogun, proud member of GFX-Depot since Apr 2006. |
|||
|
04-18-2006, 08:08 PM
Post: #7
|
|||
|
|||
|
RE: [PHP] A simple loginscript
much easier and safer
![]() I've got a tutorial in a PHP book I've got here, I could write a little one if you want I'm the only one around here that can ban people, what else do you need to know?
|
|||
|
04-18-2006, 08:15 PM
Post: #8
|
|||
|
|||
RE: [PHP] A simple loginscript
Xiao Wrote:much easier and safer i would appreciate that tut. thx shogun, proud member of GFX-Depot since Apr 2006. |
|||
|
04-18-2006, 09:04 PM
Post: #9
|
|||
|
|||
Xiao Wrote:much easier and safer that woud be nice
The one, The only Lillen2k
|
|||
|
04-19-2006, 04:49 PM
Post: #10
|
|||
|
|||
|
RE: [PHP] A simple loginscript
nice man, might use it
|
|||
« Next Oldest | Next Newest »
|














![[Image: virtual_gfxdepot_banner_2.jpg]](http://www.monsters-egn.com/signatures/virtual_gfxdepot_banner_2.jpg)

![[Image: simple9gn.jpg]](http://img60.imageshack.us/img60/6892/simple9gn.jpg)
![[Image: av-25.gif]](http://www.gfxplode.com/forums/uploads/av-25.gif)
View a Printable Version
Send this Thread to a Friend
Subscribe to this thread