Forum Moderators: coopster

Message Too Old, No Replies

mWm's Project - The blog

first php+mysql atempt

         

mwm_PT

12:29 am on Jul 16, 2007 (gmt 0)

10+ Year Member



Hi there. This is my first post. I googled for my doubt but I couldn't find an answer. Although I did find this forum.

So, three days ago, I learned how to program in PHP, how to use a MySQL database and how to mix both. All this from 3dbuzz website's video lessons.

After that, I started to make a blog from zero. After 4 hours of straight work I couldn't believe what I had already achieved! The next day I started to implement new features like login and logout and post remove etc., as I mention in each post I've been creating with all the news.

You can check it at <snip>
It's running on my machine with WAMP but that's ok.

Now, the big "problem" I have is not much as a problem, it's more like a "warning". When someone registers and then tries to login, after a failed login it echoes the error [created by me], but if the login is correct [both username and password], it echoes '"username" logged' but also echoes an error ["Warning"] from mysql that I quote here:

"Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0"

Can't clean this warning or even fully understand it. Could some one give a hand? Thanks.

[edited by: dreamcatcher at 6:24 am (utc) on July 16, 2007]
[edit reason] no urls as per T.O.S [webmasterworld.com].Thanks [/edit]

Habtom

10:14 am on Jul 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to post part of the code here which is creating the bug, otherwise it would be much of speculation.

darrenG

11:06 am on Jul 16, 2007 (gmt 0)

10+ Year Member



Have you tried making the changes suggested in the warning, in the php.ini file? It wont fix the 'problem' but it should make the warning go away..

mwm_PT

3:35 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



here goes the login.php

<?php
require($_SERVER["DOCUMENT_ROOT"] . "/config/db_config.php");
$connection = @mysql_connect($db_host, $db_user, $db_password) or die("Error connecting");
mysql_select_db($db_name, $connection);

session_start();

$username = $_POST["username"];
if(session_is_registered("username"))
echo '<center><p style="font-family:verdana;font-size:10pt;color:green">
<b>'.$_SESSION["username"].'</b> logged</p></center>';
//echo $username."<br>";
$username_len = strlen($username);
$password = $_POST["password"];
//echo $password."<br>";
$password_len = strlen($password);
$password_encrypt = md5($password);
//echo $password_encrypt."<br>";

$query = "SELECT * FROM userlist WHERE username = '$username' and password = '$password_encrypt'";
$result = @mysql_query($query, $connection);

$rows = @mysql_num_rows($result);

if ($username_len > 0 && $password_len > 0)
{
//echo $rows;
if ($rows == 1)
{
session_register("username");
session_register("password");
}
else
{
echo '<center><p style="font-family:verdana;font-size:10pt;color:red">
Wrong username or password</p></center>';
}
//ob_end_flush();
}
?>

<html>
<head>
<title>Login</title>
</head>
<body >
<div align="center">
<table border="0" width="0%" cellspacing="0" cellpadding="10">
<tr>
<td valign="middle" bgcolor="#EEEEEE">
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="POST">
<font face="arial" size="2">
<b>Username:</b> <input type="text" name="username"><br>
<b>Password:</b> <input type="password" name="password"><br>
<input type="submit" value="Login">
</font>
</form>
</td>
</tr>
</table>
</div>

</body>
</html>

[edited by: mwm_PT at 3:36 pm (utc) on July 16, 2007]

darrenG

3:42 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



Before PHP 4.3.0, if you are using $_SESSION and you have disabled register_globals, don't use session_register(), session_is_registered() or session_unregister(). Disabling register_globals is recommended for both security and performance reasons.

[php.net...]

What version of php are you running and have you disabled register_globals?

<edit>

instead of those functions listed above, try such examples as:

if(isset($_SESSION["username"]))
echo '<center><p style="font-family:verd....

[edited by: darrenG at 3:44 pm (utc) on July 16, 2007]

mwm_PT

5:51 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



I'm using PHP 5.2.3.
I changed that but it's giving me the same warning. I must use session_register()... how can i disable register_globals?

EDIT:

Just changed this and worked:

$_SESSION['username'] = $username;
$_SESSION['password'] = $password;

instead of:

session_register("username");
session_register("password");

Thanks guys.

[edited by: mwm_PT at 6:02 pm (utc) on July 16, 2007]