PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
xs2manish
Forum Commoner
Posts: 26 Joined: Mon Aug 22, 2005 10:46 pm
Post
by xs2manish » Mon Nov 14, 2005 3:17 am
twigletmac | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
i have piece of code for admmin login panel. It is working perfectly fine on my local machine. but it is not working on the clients server. but the same coding was working on another application. i used it and just changed the db name. erro msg displayed is "could not log you in"
this is displyed if as the session variable i not being initialised . but i could not figure out the reason for thisCode: Select all
<?php
session_start();
if(isset($user) && isset($pass))
{
$db=mysql_connect('localhost','root','');
if(!$db)
{
echo "Cannot connect to database";
exit;
}
$result=mysql_select_db('reiki', $db);
if(!$result)
{
echo "Cannot Select database";
exit;
}
$query="select user from auth where user='$user' and pass=password('$pass')";
#$query="insert into auth values('$user',password('$pass'))";
$result = mysql_query($query, $db) or die('Query failed. '.mysql_error());
if(mysql_num_rows($result) > 0)
{
session_register('valid_user');
$valid_user = $user;
}
}
if(isset($valid_user))
{
echo "Welcome to the Admin Panel";
echo '<br><a href="check_new_form.php">Check New Entries</a>';
}
else
{
if(isset($user))
{
echo "Could Not log you In";
}
else
{
echo "You are not logged In";
}
?>
<form action='admin_login.php' method='post'>
<BR><BR><BR><table align='middle' valign='top' cellpadding='2' cellspacing='1' style='border-collapse: collapse'>
<tr>
<td border-right-style: none; border-right-width: medium; border-bottom-style: none; border-bottom-width: medium colspan='2'>
<p align='center'><font face='lucida sans unicode'>Administrator Login</font></td>
</tr>
<tr>
<td border-right-style: none; border-right-width: medium; border-bottom-style: none; border-bottom-width: medium><font face='lucida sans unicode'>Username:</font></td>
<td border-left-style: none; border-left-width: medium; border-bottom-style: none; border-bottom-width: medium><input type='text' name='user' size=20></td>
</tr>
<tr>
<td border-right-style: none; border-right-width: medium; border-bottom-style: none; border-bottom-width: medium><font face='lucida sans unicode'>Password:</font></td><td border-left-style: none; border-left-width: medium; border-bottom-style: none; border-bottom-width: medium><input type='password' name='pass' size=20></td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' value='Log In'></td>
</tr>
</table>
</form>
<?php
}
?>
<p><a href="index.php">Home Page</a></p>
</body>
</html>
twigletmac | Please use Code: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
SuperFly
Forum Newbie
Posts: 19 Joined: Thu Nov 10, 2005 9:47 am
Contact:
Post
by SuperFly » Mon Nov 14, 2005 4:49 am
Hi xs2manish, you need to pick username adn password bewore you do select from db:
Code: Select all
$user = $_POST["user"];
$pass = $_POST["pass"];
and then you will have values for select part
I hope it helped
xs2manish
Forum Commoner
Posts: 26 Joined: Mon Aug 22, 2005 10:46 pm
Post
by xs2manish » Mon Nov 14, 2005 5:07 am
thanks for your time superfly
but the code is running perfect. without any changes.
it is just that the problem is on a particular server of the client.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Nov 14, 2005 6:35 am
The problem is most likely an out-of-date install of PHP on your local machine since functions like session_register() were deprecated some time ago and it looks like you have register_globals turned on as well. Which version are you running locally?
Mac
xs2manish
Forum Commoner
Posts: 26 Joined: Mon Aug 22, 2005 10:46 pm
Post
by xs2manish » Tue Nov 15, 2005 3:54 am
hi twigletmac
well the version is 5.0.5
actually the thing is working fine on one server and not on the other. i have also tried $_POST['user'], $_POST['pass'] and also removed the session part so that client could atleast check the functionality of the applicatin but it still did not help.
need some more advice
thanks in advance
php3ch0
Forum Contributor
Posts: 212 Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK
Post
by php3ch0 » Tue Nov 15, 2005 4:50 am
try
print session_id();
if there is a value itwill show that a session is running.
If not check that register_globals is ON
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Nov 15, 2005 6:23 am
register_globals has been turned off by default in PHP for some time now. The best thing that you can do is to rewrite your script to take this into account as it will make your code a lot more portable and future proof.
So... does this code make a difference?
Code: Select all
session_start();
if(isset($_POST['user']) && isset($_POST['pass'])) {
$user = $_POST['user'];
$pass = $_POST['pass'];
$db = mysql_connect('localhost','root','');
if(!$db) {
echo "Cannot connect to database";
exit;
}
$result = mysql_select_db('reiki', $db);
if(!$result) {
echo "Cannot Select database";
exit;
}
$query = "SELECT user FROM auth WHERE user='$user' AND pass=PASSWORD('$pass')";
#$query="insert into auth values('$user',password('$pass'))";
$result = mysql_query($query, $db) or die('Query failed. '.mysql_error());
if(mysql_num_rows($result) > 0) {
$_SESSION['valid_user'] = $user;
}
}
if(isset($_SESSION['valid_user'])) {
echo "Welcome to the Admin Panel";
echo '<br><a href="check_new_form.php">Check New Entries</a>';
} else {
if(isset($_POST['user'])) {
echo "Could Not log you In";
} else {
echo "You are not logged In";
}
Mac
xs2manish
Forum Commoner
Posts: 26 Joined: Mon Aug 22, 2005 10:46 pm
Post
by xs2manish » Tue Nov 15, 2005 7:45 am
thanks everyone for such prompt response. i will just my client this page and then he will check if this works. thanks a ton once again
xs2manish
Forum Commoner
Posts: 26 Joined: Mon Aug 22, 2005 10:46 pm
Post
by xs2manish » Wed Nov 16, 2005 12:44 pm
hi twigletmac
Thanks a lot as the things have started to work a bit. though not completly correct but we have moved ahead.
script is not fully functional and i did R&D and found that it is this query
Code: Select all
$query = "SELECT user FROM auth WHERE user='$user' AND pass=PASSWORD('$pass')";
which is creating problems. this is not working properly. SOme more info that i can give is the version of php and mysql on my clients server
PHP version 4.3.11
MySQL version 4.1.13-standard
thanks for your suggestions in advance
JAM
DevNet Resident
Posts: 2101 Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:
Post
by JAM » Wed Nov 16, 2005 12:56 pm
xs2manish wrote: script is not fully functional and i did R&D and found that it is this query
Code: Select all
$query = "SELECT user FROM auth WHERE user='$user' AND pass=PASSWORD('$pass')";
which is creating problems.
How is it creating problems. You should specify what happens (or not happens) when you run the code.
xs2manish
Forum Commoner
Posts: 26 Joined: Mon Aug 22, 2005 10:46 pm
Post
by xs2manish » Thu Nov 17, 2005 7:42 am
Hi Jam
when i am using
Code: Select all
select * from auth where user = '$user' ;
i was able to retrieve entries from db
and using this
Code: Select all
select * from auth where user = '$user' and pass=password('$pass');
i am not able to retrieve any thing from db.
though right now what i have done is created a new table for login adn then used
Code: Select all
select * from login where user = '$user' and pass = '$pass'
so that the client can atleast check the application
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Thu Nov 17, 2005 9:32 am
Maybe one of you is using MySQL 4/5 and the other MySQL 3? The PASSWORD() function was changed between MySQL 3 and 4.
Mac