I'm looking for an example of a login system that has multiple fields
(2 to be exact) + password. e.g username, company name and password,
the user, company and password are checked against a mysql database. I
have it working with just the username field but I'm confused on how
to go about adding another field. I'm pretty new to PHP so don't beat
me up too much for this example code, I borrowed and hacked it
together in a very short period of time.
Code:
<?php
include 'db.php';
//Checks if there is a login cookie
if(isset($_COOK IE['ID_user']))
//if there is, it logs you in and directs you to the members page
//shopname is used to select the correct database
{
$shopname = $_COOKIE['ID_fitsheetsho p'];
$username = $_COOKIE['ID_fitsheetuse r'];
$pass = $_COOKIE['Key_fitsheet'];
$checkuser = mysql_query("SE LECT * FROM users WHERE username =
'$username'")or die(mysql_error ());
$checkshop = mysql_query("SE LECT * FROM users WHERE shopname =
'$shopname'")or die(mysql_error ());
while($info = mysql_fetch_arr ay($checkuser))
{
if ($pass != $info['password'])
{
die('something is wrong');
}
else
{
header("Locatio n: members.php");
}
}
while($info = mysql_fetch_arr ay($checkshop))
{
if ($pass != $info['password'])
{
die('something is wrong');
}
else
{
header("Locatio n: members.php");
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['shopname'] | !$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quo tes_gpc()) {
$_POST['username'] = addslashes($_PO ST['username']);
$_POST['shopname'] = addslashes($_PO ST['shopname']);
}
$checkuser = mysql_query("SE LECT * FROM users WHERE username = '".
$_POST['username']."'")or die(mysql_error ());
$checkshop = mysql_query("SE LECT * FROM users WHERE shopname = '".
$_POST['shopname']."'")or die(mysql_error ());
//Gives error if user dosen't exist
$check2 = mysql_num_rows( $checkuser);
if ($check2 == 0) {
die('Something is wrong');
}
$check3 = mysql_num_rows( $checkshop);
if ($check3 == 0) {
die('Something is wrong');
}
while($info = mysql_fetch_arr ay($checkuser))
while($info = mysql_fetch_arr ay($checkshop))
{
$_POST['pass'] = stripslashes($_ POST['pass']);
$info['password'] = stripslashes($i nfo['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Something is wrong');
}
else
{
// if login is ok then we add a cookie
$_POST['shopname'] = stripslashes($_ POST['shopname']);
$_POST['username'] = stripslashes($_ POST['username']);
$hour = time() + 3600;
setcookie(ID_sh op, $_POST['shopname'], $hour);
setcookie(ID_us er, $_POST['username'], $hour);
setcookie(Key_s hop, $_POST['pass'], $hour);
//then redirect them to the members area
header("Locatio n: members.php");
}
}
}
else {
// if they are not logged in
//code removed for privacy
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>L ogin</h1></td></tr>
<tr><td>Shop Name:</td><td>
<input type="text" name="shopname" size="60" maxlength="60">
<tr><td>Usernam e:</td><td>
<input type="text" name="username" size="2" maxlength="60">
</td></tr>
<tr><td>Passwor d:</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>
//code removed
<?php
}
?>
Each company will have its own database, once the user logs in I was
going to check their cookie for the company name and use that to
select the correct database. Does anyone have any better ideas?
Thanks for your time. 2 1928
Bump
On Apr 20, 1:14 pm, dylanhug...@gma il.com wrote:
I'm looking for an example of a login system that has multiple fields
(2 to be exact) + password. e.g username, company name and password,
the user, company and password are checked against a mysql database. I
have it working with just the username field but I'm confused on how
to go about adding another field. I'm pretty new to PHP so don't beat
me up too much for this example code, I borrowed and hacked it
together in a very short period of time.
Code:
<?php
include 'db.php';
//Checks if there is a login cookie
if(isset($_COOK IE['ID_user']))
//if there is, it logs you in and directs you to the members page
//shopname is used to select the correct database
{
$shopname = $_COOKIE['ID_fitsheetsho p'];
$username = $_COOKIE['ID_fitsheetuse r'];
$pass = $_COOKIE['Key_fitsheet'];
$checkuser = mysql_query("SE LECT * FROM users WHERE username =
'$username'")or die(mysql_error ());
$checkshop = mysql_query("SE LECT * FROM users WHERE shopname =
'$shopname'")or die(mysql_error ());
while($info = mysql_fetch_arr ay($checkuser))
{
if ($pass != $info['password'])
{
die('something is wrong');
}
else
{
header("Locatio n: members.php");
}
}
while($info = mysql_fetch_arr ay($checkshop))
{
if ($pass != $info['password'])
{
die('something is wrong');
}
else
{
header("Locatio n: members.php");
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['shopname'] | !$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quo tes_gpc()) {
$_POST['username'] = addslashes($_PO ST['username']);
$_POST['shopname'] = addslashes($_PO ST['shopname']);
}
$checkuser = mysql_query("SE LECT * FROM users WHERE username = '".
$_POST['username']."'")or die(mysql_error ());
$checkshop = mysql_query("SE LECT * FROM users WHERE shopname = '".
$_POST['shopname']."'")or die(mysql_error ());
//Gives error if user dosen't exist
$check2 = mysql_num_rows( $checkuser);
if ($check2 == 0) {
die('Something is wrong');
}
$check3 = mysql_num_rows( $checkshop);
if ($check3 == 0) {
die('Something is wrong');
}
while($info = mysql_fetch_arr ay($checkuser))
while($info = mysql_fetch_arr ay($checkshop))
{
$_POST['pass'] = stripslashes($_ POST['pass']);
$info['password'] = stripslashes($i nfo['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Something is wrong');
}
else
{
// if login is ok then we add a cookie
$_POST['shopname'] = stripslashes($_ POST['shopname']);
$_POST['username'] = stripslashes($_ POST['username']);
$hour = time() + 3600;
setcookie(ID_sh op, $_POST['shopname'], $hour);
setcookie(ID_us er, $_POST['username'], $hour);
setcookie(Key_s hop, $_POST['pass'], $hour);
//then redirect them to the members area
header("Locatio n: members.php");
}
}
}
else {
// if they are not logged in
//code removed for privacy
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>L ogin</h1></td></tr>
<tr><td>Shop Name:</td><td>
<input type="text" name="shopname" size="60" maxlength="60">
<tr><td>Usernam e:</td><td>
<input type="text" name="username" size="2" maxlength="60">
</td></tr>
<tr><td>Passwor d:</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>
//code removed
<?php
}
?>
Each company will have its own database, once the user logs in I was
going to check their cookie for the company name and use that to
select the correct database. Does anyone have any better ideas?
Thanks for your time.
dy*********@gma il.com wrote:
I'm looking for an example of a login system that has multiple fields
(2 to be exact) + password. e.g username, company name and password,
the user, company and password are checked against a mysql database. I
have it working with just the username field but I'm confused on how
to go about adding another field. I'm pretty new to PHP so don't beat
me up too much for this example code, I borrowed and hacked it
together in a very short period of time.
Code:
<?php
include 'db.php';
//Checks if there is a login cookie
if(isset($_COOK IE['ID_user']))
//if there is, it logs you in and directs you to the members page
//shopname is used to select the correct database
{
$shopname = $_COOKIE['ID_fitsheetsho p'];
$username = $_COOKIE['ID_fitsheetuse r'];
$pass = $_COOKIE['Key_fitsheet'];
$checkuser = mysql_query("SE LECT * FROM users WHERE username =
'$username'")or die(mysql_error ());
$checkshop = mysql_query("SE LECT * FROM users WHERE shopname =
'$shopname'")or die(mysql_error ());
while($info = mysql_fetch_arr ay($checkuser))
{
if ($pass != $info['password'])
{
die('something is wrong');
}
else
{
header("Locatio n: members.php");
}
}
while($info = mysql_fetch_arr ay($checkshop))
{
if ($pass != $info['password'])
{
die('something is wrong');
}
else
{
header("Locatio n: members.php");
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted
// makes sure they filled it in
if(!$_POST['shopname'] | !$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quo tes_gpc()) {
$_POST['username'] = addslashes($_PO ST['username']);
$_POST['shopname'] = addslashes($_PO ST['shopname']);
}
$checkuser = mysql_query("SE LECT * FROM users WHERE username = '".
$_POST['username']."'")or die(mysql_error ());
$checkshop = mysql_query("SE LECT * FROM users WHERE shopname = '".
$_POST['shopname']."'")or die(mysql_error ());
//Gives error if user dosen't exist
$check2 = mysql_num_rows( $checkuser);
if ($check2 == 0) {
die('Something is wrong');
}
$check3 = mysql_num_rows( $checkshop);
if ($check3 == 0) {
die('Something is wrong');
}
while($info = mysql_fetch_arr ay($checkuser))
while($info = mysql_fetch_arr ay($checkshop))
{
$_POST['pass'] = stripslashes($_ POST['pass']);
$info['password'] = stripslashes($i nfo['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('Something is wrong');
}
else
{
// if login is ok then we add a cookie
$_POST['shopname'] = stripslashes($_ POST['shopname']);
$_POST['username'] = stripslashes($_ POST['username']);
$hour = time() + 3600;
setcookie(ID_sh op, $_POST['shopname'], $hour);
setcookie(ID_us er, $_POST['username'], $hour);
setcookie(Key_s hop, $_POST['pass'], $hour);
//then redirect them to the members area
header("Locatio n: members.php");
}
}
}
else {
// if they are not logged in
//code removed for privacy
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>L ogin</h1></td></tr>
<tr><td>Shop Name:</td><td>
<input type="text" name="shopname" size="60" maxlength="60">
<tr><td>Usernam e:</td><td>
<input type="text" name="username" size="2" maxlength="60">
</td></tr>
<tr><td>Passwor d:</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>
//code removed
<?php
}
?>
Each company will have its own database, once the user logs in I was
going to check their cookie for the company name and use that to
select the correct database. Does anyone have any better ideas?
Thanks for your time.
I don't know of any examples, but it's not too hard. But you need to
put everything in one SQL query, i.e. (Not checked for syntax)
$result = mysql_query("SE LECT * FROM users WHERE username = " .
"'$username ' AND shopname='$shop name' AND `password` = '$pass'");
if (mysql_rows($re sult) !< 1)
echo "User not found";
elseif (mysql_rows($re sult) 1)
echo "This should not occur!");
else
// valid login here
The way you have it, you could have user 'abc' at shop 'acme shop' and
still be able to access shop 'widgets, inc.'.
Also, I wouldn't have a different table for every shop. It gets too
hard to manage. Rather, in your table have a column for the shop id and
filter on that.
For instance:
User table:
userid
pwd
shopid
Shop table:
shopid
shop Name
Data table:
shopid
(other information)
Of course, if you did it this way you'd have to adjust your SQL code
slightly - but it's much better than separate tables for each shop.
For more info on the DB design, try comp.database.m ysql (or whatever
database you're using if not MySQL).
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== === This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dskillingstad |
last post by:
I've been struggling with this problem for some time and have tried
multiple solutions with no luck.
Let me start with, I'm a novice at Access and I'm not looking for
someones help to design my database,just help in getting me pointed in
the right direction.
I have a database with 8 tables, which from what I have read, cannot be
linked on a single form, and be updatable. I have created a query
which includes all 8 tables, and then...
|
by: Rob |
last post by:
I have an ASP.NET application that uses forms-based
authentication. A user wishes to be able to run multiple
sessions of this application simultaneously from the
user's client machine.
The web.config file is configured as such:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All"
name="myApplication"/>
</authentication>
|
by: TJS |
last post by:
what are folks doing to get around limitation of one server form per page ?
|
by: Conformix Sales |
last post by:
Any thought about how can I stop a user from logging into the application
multiple times. I am using forms authentication.
|
by: Graham |
last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and wizards.
But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication.
Background
I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
| |
by: Gleep |
last post by:
I've searched google intensely on this topic and it seems noone really knows how to approch this.
The goal I don't want clients to give out their usernames and passwords to friends, since the site
relies on subscrption fees.
Sessions ID's are matched between the browser and the server. So a users can login with same
username and password and those sessions are tracked individually.
Some suggest create table fields with the session ID...
|
by: Jai |
last post by:
Hi,
I have a problem related to Login System.
I am developing 3 websites for some institution.Now they want that if
anybody had sign up for there site1.com(say), than he or she should be
able to sign in for site2.com and site3.com.
hence, if user has sign up for the membership of site1.com than he/she
should automicallly become the member of site2.com and site3.com.
|
by: Joseph Geretz |
last post by:
I have the following class which I am serializing and passing back and forth
between my Web Service application and the client.
public class Token : SoapHeader
{
public string SID;
public string UID;
public string PWD;
}
|
by: Samir Chouaieb |
last post by:
Hello,
I am trying to find a solution to a login mechanism for different
domains on different servers with PHP5.
I have one main domain with the user data and several other domains that
need a login to show data.
I want the user to login only once when he visits any of my domains.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |