473,396 Members | 2,147 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,396 software developers and data experts.

PHP connection problem, I can't get success with loging in though I think I use corect login and password...

Hi

need an advice, I'm beginner with PHP. I got little problem:

I use this solution as login to get administration of my pages:

<?php
// if authorization isn't done we request it
if (!IsSet($PHP_AUTH_USER))
{
Header("HTTP/1.0 401 Unauthorized");
Header("WWW-Authenticate: Basic realm=\"RS - Admin Center\"");
echo "Unauthorized access (a)";
exit;
}
// if user filled up the form we continue with checking data in
database
else
{
// connect to database
include "../conn.php";
// looking for the login and password records that are set in
authorizing form
// we off-course looking for active users only
$sql = mysql_query("SELECT * FROM autori
WHERE login LIKE '$PHP_AUTH_USER'
AND pass = '".md5($PHP_AUTH_PW)."'
AND stav = 'a'");
// if we won't find anyone with requested conditions we stop
if (mysql_num_rows($sql) == 0)
{
Header("HTTP/1.0 401 Unauthorized");
Header("WWW-Authenticate: Basic realm=\"RS - Admin Center\"");
echo "Unauthorized access (b)";
mysql_close($conn);
exit;
}
// we don't need the connection with database so we end
mysql_close($conn);
}
// continue with opening frames
?>

The problem is that I can not get success with login on my pages
though I use correct login and password. The dialog is opened three
times and then I get the message Unauthorized access (a). It seems
that the part after else command is never done. Why is it?

Thank you very much for your hints!

Have a nice day!

Apr 26 '07 #1
3 1475
On Apr 26, 10:07 pm, MIUSS <m...@seznam.czwrote:
Hi

need an advice, I'm beginner with PHP. I got little problem:

I use this solution as login to get administration of my pages:

<?php
// if authorization isn't done we request it
if (!IsSet($PHP_AUTH_USER))
{
Header("HTTP/1.0 401 Unauthorized");
Header("WWW-Authenticate: Basic realm=\"RS - Admin Center\"");
echo "Unauthorized access (a)";
exit;}

// if user filled up the form we continue with checking data in
database
else
{
// connect to database
include "../conn.php";
// looking for the login and password records that are set in
authorizing form
// we off-course looking for active users only
$sql = mysql_query("SELECT * FROM autori
WHERE login LIKE '$PHP_AUTH_USER'
AND pass = '".md5($PHP_AUTH_PW)."'
AND stav = 'a'");
// if we won't find anyone with requested conditions we stop
if (mysql_num_rows($sql) == 0)
{
Header("HTTP/1.0 401 Unauthorized");
Header("WWW-Authenticate: Basic realm=\"RS - Admin Center\"");
echo "Unauthorized access (b)";
mysql_close($conn);
exit;
}
// we don't need the connection with database so we end
mysql_close($conn);}

// continue with opening frames
?>

The problem is that I can not get success with login on my pages
though I use correct login and password. The dialog is opened three
times and then I get the message Unauthorized access (a). It seems
that the part after else command is never done. Why is it?

Thank you very much for your hints!

Have a nice day!
you are using an old script, use
$_SERVER['PHP_AUTH_PW']
$_SERVER['PHP_AUTH_USER']
and adjust your query to
....
WHERE login LIKE '".$_SERVER['PHP_AUTH_USER']."'
...
to avoid issue with quotes now, and it should be fine.

Apr 26 '07 #2

Hi!

I'm little confused, I tried more things but I still didn't get
success.

I think this should be corect:

$sql = mysql_query("SELECT * FROM autori
WHERE login LIKE \"".
$_SERVER['PHP_AUTH_USER']."\"
AND pass LIKE
\"".md5($_SERVER['PHP_AUTH_PW'])."\"
AND stav LIKE a\";");

But it isn't and it does not work:-(

Apr 27 '07 #3
On Apr 27, 7:13 pm, MIUSS <m...@seznam.czwrote:
Hi!

I'm little confused, I tried more things but I still didn't get
success.

I think this should be corect:

$sql = mysql_query("SELECT * FROM autori
WHERE login LIKE \"".
$_SERVER['PHP_AUTH_USER']."\"
AND pass LIKE
\"".md5($_SERVER['PHP_AUTH_PW'])."\"
AND stav LIKE a\";");

But it isn't and it does not work:-(
dont use LIKE, instead use = and your query should be better formed,
go check out how to authenticate with mysql, and look for the query
used, and follow the example,
$query = sprintf( "SELECT...... WHERE `login` = '%s' ......",
$_SERVER['PHP_AUTH_USER'] [,......] );
etc.... google for this rather than just trying stuff, else you will
get it wrong.

Apr 27 '07 #4

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

Similar topics

9
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
6
by: Keith Norris | last post by:
I am having a problem connecting to my SQL Server with the following ASP code: set cn = server.createobject("adodb.connection") cn.connectionstring = "Provider=sqloledb; data...
1
by: Zlatko Matić | last post by:
Hi! In MS Access/PostgreSQL combination I have login form. After user writes all neccessary inputs and push the button, a startup procedure creates DSN-less connection string, receates all linked...
10
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through...
4
by: rrober07 | last post by:
Hello, My Setup is I have a Web Server machine(Devweb01), Database SQL Machine(Devsql01), a Client Machine(local machine) I have configured the SQL machine as follows: 1) Added local Aspnet...
16
by: peshekeedweller | last post by:
Using asp.net 1.1. vb.net 2003. I am trying to connect to a remote sql server 2000 on a virtual machine running windows 2000 server. I can connect through the server explorer in visual studio,...
9
by: Gordon | last post by:
I want to add a feature to a project I'm working on where i have multiple users set up on my Postgres database with varying levels of access. At the bare minimum there will be a login user who...
8
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.