login page code

This is a discussion on login page code within the PHP Language forums, part of the PHP Programming Forums category; can you tell me how to write the code for username and password in php...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-28-2007
yadev
 
Posts: n/a
Default login page code

can you tell me how to write the code for username and password in php

Reply With Quote
  #2 (permalink)  
Old 09-28-2007
Lars Eighner
 
Posts: n/a
Default Re: login page code

In our last episode,
<1190961794.635559.72450@w3g2000hsg.googlegroups.c om>,
the lovely and talented yadev
broadcast on comp.lang.php:

> can you tell me how to write the code for username and password in php


$username
$password

--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
Countdown: 480 days to go.
What do you do when you're debranded?
Reply With Quote
  #3 (permalink)  
Old 09-28-2007
Lammi
 
Posts: n/a
Default Re: login page code

On 28 Sep., 09:00, Lars Eighner <use...@larseighner.com> wrote:
> In our last episode,
> <1190961794.635559.72...@w3g2000hsg.googlegroups.c om>,
> the lovely and talented yadev
> broadcast on comp.lang.php:
>
> > can you tell me how to write the code for username and password in php

>
> $username
> $password
>
> --
> Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
> Countdown: 480 days to go.
> What do you do when you're debranded?


great code! but there's a little fault, you forgot the ; at the end of
each line :-))

Reply With Quote
  #4 (permalink)  
Old 09-28-2007
panda31
 
Posts: n/a
Default Re: login page code

On 28 sep, 09:00, Lars Eighner <use...@larseighner.com> wrote:
> In our last episode,
> <1190961794.635559.72...@w3g2000hsg.googlegroups.c om>,
> the lovely and talented yadev
> broadcast on comp.lang.php:
>
> > can you tell me how to write the code for username and password in php

>
> $username
> $password
>
> --
> Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
> Countdown: 480 days to go.
> What do you do when you're debranded?


Yes... We can see it this way.

In fact, you may have all answers in a PHP manual.
However, you may give us some details of the way connexting users on
your site. I suppose you use a MySQL db.
So, you get variables values from a form and store them is $username
and $password. Then, you check the inputs by escaping special HTML,
SQL and PHP characters/tags to avoid XSS injections.
Then, you run your SQL request. Be aware that you have to manage the
user auth. during his navigation on your website!

An example with session

<?php
mysql_connect('host','****','****') // where *** are host, user id &
pwd for connexion
mysql_select_db('you_data_base')

// We start the session
session_start();
$loginOK = false; // Boolean for connexion validation

// We run the treatment only if values of form have been recorded
if ( isset($_POST) && (!empty($_POST['login'])) && (!
empty($_POST['password'])) ) {

extract($_POST);

// We search password for given login ...
$req = mysql_query("SELECT nickname, name, firstname, password FROM
user_table WHERE nickname = '".addslashes($login)."'") //escaping
$login value

// ... we check if user exists ...
if (mysql_num_rows($req) > 0) {
$data = mysql_fetch_assoc($req)

// ... and password validity.
// You can add a md5 hash with a letter added to improve security
$password_md5 = md5($password).'a'
if ($password_md5 == $data['password']) {
$loginOK = true;
header('Location:http://yoursite.com/index.php');
}
}
}

Enjoy.
// Si le login a été validé on met les données en sessions
if ($loginOK) {
$_SESSION['speudonyme'] = $data['speudonyme'];
$_SESSION['nom'] = $data['nom'];
$_SESSION['prenom'] = $data['prenom'];
}


else {
echo 'Une erreur est survenue, veuillez réessayer de rentrer votre mot
de passe et pseudonyme !';
}
?>

Reply With Quote
  #5 (permalink)  
Old 09-28-2007
panda31
 
Posts: n/a
Default Re: login page code

On 28 sep, 11:17, panda31 <mm.spaw...@gmail.com> wrote:
> On 28 sep, 09:00, Lars Eighner <use...@larseighner.com> wrote:
>
> > In our last episode,
> > <1190961794.635559.72...@w3g2000hsg.googlegroups.c om>,
> > the lovely and talented yadev
> > broadcast on comp.lang.php:

>
> > > can you tell me how to write the code for username and password in php

>
> > $username
> > $password

>
> > --
> > Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
> > Countdown: 480 days to go.
> > What do you do when you're debranded?

>
> Yes... We can see it this way.
>
> In fact, you may have all answers in a PHP manual.
> However, you may give us some details of the way connexting users on
> your site. I suppose you use a MySQL db.
> So, you get variables values from a form and store them is $username
> and $password. Then, you check the inputs by escaping special HTML,
> SQL and PHP characters/tags to avoid XSS injections.
> Then, you run your SQL request. Be aware that you have to manage the
> user auth. during his navigation on your website!
>
> An example with session
>
> <?php
> mysql_connect('host','****','****') // where *** are host, user id &
> pwd for connexion
> mysql_select_db('you_data_base')
>
> // We start the session
> session_start();
> $loginOK = false; // Boolean for connexion validation
>
> // We run the treatment only if values of form have been recorded
> if ( isset($_POST) && (!empty($_POST['login'])) && (!
> empty($_POST['password'])) ) {
>
> extract($_POST);
>
> // We search password for given login ...
> $req = mysql_query("SELECT nickname, name, firstname, password FROM
> //escaping $login value
> user_table WHERE nickname = '".addslashes($login)."'")
>
> // ... we check if user exists ...
> if (mysql_num_rows($req) > 0) {
> $data = mysql_fetch_assoc($req)
>
> // ... and password validity.
> // You can add a md5 hash with a letter added to improve security
> $password_md5 = md5($password).'a'
> if ($password_md5 == $data['password']) {
> $loginOK = true;
> header('Location:http://yoursite.com/index.php');
>
> }
> }
> }
>
> if ($loginOK) {
> $_SESSION['nickname'] = $data['nickname'];
> $_SESSION['name'] = $data['name'];
> $_SESSION['firstname'] = $data['firstname'];
>
> }
>
> else {
> echo 'Error happened!';}
>
> ?>


oups... little error. look above please.

Reply With Quote
  #6 (permalink)  
Old 09-28-2007
Shelly
 
Posts: n/a
Default Re: login page code


"Lars Eighner" <usenet@larseighner.com> wrote in message
news:slrnffp9j3.14ai.usenet@debranded.larseighner. com...
> In our last episode,
> <1190961794.635559.72450@w3g2000hsg.googlegroups.c om>,
> the lovely and talented yadev
> broadcast on comp.lang.php:
>
>> can you tell me how to write the code for username and password in php

>
> $username
> $password
>
> --
> Lars Eighner <http://larseighner.com/>
> <http://myspace.com/larseighner>
> Countdown: 480 days to go.
> What do you do when you're debranded?


ROTFLMAO


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:04 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0