473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

login page code

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

Sep 28 '07 #1
5 2811
In our last episode,
<11*********************@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?
Sep 28 '07 #2
On 28 Sep., 09:00, Lars Eighner <use...@larseighner.comwrote:
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 :-))

Sep 28 '07 #3
On 28 sep, 09:00, Lars Eighner <use...@larseighner.comwrote:
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 !';
}
?>

Sep 28 '07 #4
On 28 sep, 11:17, panda31 <mm.spaw...@gmail.comwrote:
On 28 sep, 09:00, Lars Eighner <use...@larseighner.comwrote:
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.

Sep 28 '07 #5

"Lars Eighner" <us****@larseighner.comwrote in message
news:sl********************@debranded.larseighner. com...
In our last episode,
<11*********************@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
Sep 28 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RT | last post by:
I have followed the step by step instructions in the login manual Created login page Use LSC01 This works - login and get redirected to the proper page My problem is the cookie variables...
1
by: Wayne Smith | last post by:
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0 Operating System: Microsoft Windows 2000 Professional I am trying to protect a portion of a web site by allowing users to...
9
by: buran | last post by:
Dear ASP.NET Programmers, How can I post data to an ASP.NET login page and pass authentication? The login page uses forms authentication, users must supply usernames and password and have to...
4
by: 23s | last post by:
I had this problem in the past, after a server reformat it went away, and now after another server reformat it's back again - no clue what's doing it. Here's the flow: Website root is public, no...
2
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public...
7
by: FP | last post by:
I want to put some code at the top of my pages which will prompt the user for a name & password if the session variable IDUser is not set. How do I get the browser to display the login / password...
6
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in...
3
by: satishknight | last post by:
Hi, Can some one tell me how to change the validation sequence for the code pasted below, actually what I want it when any one enters the wrong login information (already registered users) then it...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
9
by: adweaver | last post by:
Hello All, I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs. The site was built in a folder...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.