473,545 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Login, authentication: After entering username+psw nothing happens?

4 New Member
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
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");

else {
// Correct credentials provided, print the blog entry form
//using the echo as a check
echo " Authorised";
Feb 16 '07 #1
5 3765
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.
Feb 16 '07 #2
4 New Member
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 ?
Feb 16 '07 #3
4 New Member
anyone, able to help please?
Feb 18 '07 #4
4,258 Recognized Expert Specialist
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:
Feb 18 '07 #5
4 New Member
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.
Feb 19 '07 #6

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...
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...
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...
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...
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 /...
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,...
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...
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"...
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...
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...
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. ...
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...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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: 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...

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.