I have created a blog and have added a login box which prompts the user for login and id before posting- The username and password have been stored in the database, however when i enter the username and pasword it does not seem to compare the values entered with anything. It jus keeps giving the prompt box to enter details. But if i click cancel, then it tels me the incorrect credentials ave been entered i have tried many ways to solve this problem but cant seem to see where i am gng wrong- the code is below, and some of the code was already provided, Function to authenticate was given -
And this code is called when the user tries to enter a new posting option from the index page, so before the addentry page displays, the user must login- if any more code is required, let me know-
Thanks in advance- This is my first ever php program and it was all going ok untill this. thanks
[PHP] // Function to authenticate
function authenticated($ username, $password) {
// Connect to Database Server
$Hostname = "2006";
$Username = "anon";
$Password = "anonpasswo rd";
//open the connection
$conn = mysql_connect($ Hostname,$Usern ame, $Password);
// Choose database
mysql_select_db ("anon", $conn);
// Build SQL query to:
// find row in database with
// matching $username and $password
// Execute query
$query = mysql_query( "SELECT * FROM blog_user WHERE name == '".$username ."' AND password == '".$password."' ;", $conn);
// IF number of rows is equal to one
// return true
if ($query == 1)
{
return true;
}
// ELSE return false
else
{
return false;
}
}
// Assign username and password from $_SERVER global array
$username = $_SERVER["PHP_AUTH_U SER"];
$password = $_SERVER["PHP_AUTH_P W"];
// Decide whether to show blog entry form, or deny access
if (!authenticated ($username, $password)) {
// Credentials either:
// not sent (1st time script is called)
// credentials do not match database
// Display HTTP Authentication Challenge
header("WWW-Authenticate: Basic Realm=\"Blog Station\"");
header("HTTP/1.1 401 Unauthorised");
// Print a message about incorrect credentials
echo " Incorrect credentials provided, please try again";
echo ("<a href = \"index.php\ "> Re-Enter");
exit;
}
else {
// Correct credentials provided, print the blog entry form
//using the echo as a check
echo " Authorised";
}[/PHP]
5 3769 Motoma 3,237
Recognized Expert Specialist
Your MySQL query should use '=' rather than '=='
Where is the code that is getting the username and password? Shouldn't these be taken from a login form? I doubt the $_SERVER[] superglobal will have the correct value.
thanks for replying,
The = does not fix the problem, it still does the same thing -
Sorry i dont quite understand what you mean by where the code is for username and password. The username and password have been entrered into the table blog_user, i inserted one valid user into the database.
as for the $_SERVER[] superglobal it was given to us like that, what would be the alternative way of implementing it ?
anyone, able to help please?
From your reply to motoma I deduct that you are using code that you got from somewhere else. And you have no clue as how to implement and use it.
Anyway it is not going to work as you showed it. And what you showed is only part of a bigger script.
So you either display that script or you start to develop a login routine yourself. We can help you with the latter,
Ronald :cool:
From your reply to motoma I deduct that you are using code that you got from somewhere else. And you have no clue as how to implement and use it.
Anyway it is not going to work as you showed it. And what you showed is only part of a bigger script.
So you either display that script or you start to develop a login routine yourself. We can help you with the latter,
Ronald :cool:
Just to clarify i did not copy the code from someone esle or take someone elses code, yes it was given to us by our lecturers, as most people taking the class have little or no knowledge of php and we are only required to write some of the code- Anwyay thanks for your help. I will ask someone esle.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Lorenzo |
last post by:
I had to transfer an ASP Web Application (developed by another person) to a
different web server. It seems to work but not completely.
I have some problems with authentication: it is based on a username and a
password stored in a SQL Server's table. These data are requested via basic
authentication (not a IIS level but I think it is used to create the
authentication window in which put username and password). The problem is
that it...
|
by: tchangmian |
last post by:
I want to limit user login by writing ASP program. In details, if a
user had logged in wrongly for more than three times, then the user
will not be abled to log in to the system anymore even thought he key
in correctly the username and password in the 4th time. That's means
he cant login forever until the administrator edit his status in the
database
Can i refer to any ASP sample coding for this application?
|
by: Siobhan |
last post by:
Hi
What is the recommended way to store a user's database credentials across
the pages of a web application so that each time the database is accessed the
system doesn't have to ask them for their username and password again
We have previously stored these in a session variable (encrypted) and
retrieved from their - but are worried about the impact on performance if the
number of users increases.
Had thought about cookies but worried...
|
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 users). If
user is from intranet, web server should recognize it and application should
create additional options in controls regarding groups the user belongs to.
If user is from extranet it should be logged in as anonymous and a link to
login page...
|
by: Dam6 |
last post by:
Okay...
Using vb .net within DW MX2004, connecting to an access database:
Background: I have created a simple login.aspx page that is supposed to
re-direct to default.aspx using FormsAuthentication.RedirectFromLoginPage.
The data is correct from testing the dataset etc and the page also informs
me that I have entered an incorrect user / password.
Problem:
When I go to http://localhost/Modify/Login.aspx and enter the username and
| |
by: Alan Silver |
last post by:
Hello,
Sorry this is a bit wordy, but it's a pretty simple question...
I have a web site, http://domain/ which is a public site, part of which
(http://domain/a/) is protected by forms authentication.
I would like to configure it so that anyone not logged in, trying to
access the protected part will not be redirected to the login page, but
|
by: Preben Zacho |
last post by:
Hi there
The scenario I got is this: I have created a Windows application in VS and I
want to deploy it to another machine running Windows Vista. Since I have no
control over this other machine, I've set it up to run SQL Authentication
and I have added a new user called "MyUser" and applied a password. This
user/password is used in my connection string whick looks like this:
Server=.\SQLEXPRESS;Database=MyDB;User...
|
by: nth |
last post by:
I wan to filter the database show out information by using the user login name. Means that when that user login by entering their names n password, if correct then it will go to the other page by showing that user result only, not other user result. Can somebody help me pls?.
Following is the login page code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/conResult.asp" -->
<%
Dim Recordset1__MMColParam...
|
by: pek |
last post by:
I have read a lot of tutorials on how to create a login mechanism (a
lot of which I found really useful). None of them however explain how
do you check if the user is or is not in fact logged in.
What is your implementation? What do you believe is a good practice
and what is not? Do you provide both sessions and cookies for temporal
and long-term logins..?
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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...
| | |