php4 > php5 errors

Hi All,

I had to upgrade my server (from 4) to php 5 and mysql 5 last night due to errors.
When i go to the login page or the admin page I just get a blank page and Bad username or password.

I’m running

PHP Version 5.1.6
mysql-5.0.77
Apache/2.2.3 (Red Hat)

Thanks for your help

DB.PHP

function verifylogin($username,$password){
        $sql = "select id from adm where username='$username' and password='$password'";
        $result = mysql_query($sql);
        $numrows = mysql_num_rows($result);
        if ($numrows!=0) {
                $resrow = mysql_fetch_row($result);
                $id = $resrow[0];
                return $id;
        }
        return "";
}
session_name("adm_radio");
session_start();

$logoutAction = false;
if (isset($action)) {
  if ($action="logout") {
    $logoutAction = true;
  }
}

if ($logoutAction) {
  session_unset();
  session_destroy();
}
else {
  if (isset($_SESSION['sPassword']) && isset($_SESSION['sUsername'])) {
    #$password = $_SESSION['sPassword'];
    #$username = $_SESSION['sUsername'];

    if (isset($newpass)) {
      $_SESSION['sPassword'] = $newpass;
    }    
  }
  else {
    if (verifylogin($username,$password) != "") {
      if (isset($password) && isset($username)) {
        $_SESSION['sPassword'] = $password;
        $_SESSION['sUsername'] = $username;
      }      
    }
  }
}

ADMIN PAGE

// LOGIN FORM BEGIN
if (!$username || !$password){
	echo "<table border='1' cellpadding='0' cellspacing='0' width='100%' style='border-collapse: collapse; border-style: double; border-width: 3' bordercolor='#FFFFFF'><tr><td style='padding:5' bgcolor='#FFFFFF'>";
	echo "<table border='0' cellpadding='0' cellspacing='0' width='100%' style='padding-left: 16'><form name='form1' method='post' action='".$PHP_SELF."'>
  <tr>
    <td width='20%'>Username: </td>
    <td width='80%'><input type='text' name='username' maxlength='50' value='' size='20'></td>
  </tr>
  <tr>
    <td width='20%'>Password: </td>
    <td width='80%'><input type='password' name='password' value='' size='20'></td>
  </tr>
  <tr>
    <td width='20%'></td>
    <td width='80%'><input type='submit' value='Login' name='submit'></td>
  </tr></form>
</table>";
echo "</td></tr></table>";
echo "<table border='1' cellpadding='0' cellspacing='0' style='border-collapse: collapse; border-style: double; border-width: 3' bordercolor='#FFFFFF' width='100%'>
  <tr>
    <td style='padding: 10' width='40%' bgcolor='#FFFFFF'></td>
	<td style='padding: 10' width='30%' bgcolor='#FFFFFF' align='right'></td>
	<td style='padding: 10' width='30%' bgcolor='#FFFFFF' align='right'></td>
  </tr>
</table>";
exit;
}
## LOGIN FORM END

if (!$validlogin){
	echo "Bad username or password";
	exit;
}

if ($username && $password){
        $validlogin = verifylogin($username,$password);
        if(!$validlogin){
		echo "Bad username or password";
		exit;
}

Two things, first, the function verifylogin() should return true or false. Not “”.

Also, the code below is completely unnecessary.

if (!$validlogin){
    echo "Bad username or password";
    exit;
} 

It will execute every time you first browse to the page. This is because the var $validlogin has not been defined yet. It is defined in the next block of code where you run $validlogin = verifylogin($username,$password);

  1. Consider adding error_reporting(E_ALL) to the top of your pages. That will give you a starting point at least.
  2. Create a <?php echo phpinfo(); ?> page and check your settings. I’m sort of guessing your code might be relying on majic quotes and register globals which are probably turned off by default.
  3. And if you are going to take the time to upgrade then consider jumping to 5.3. I don’t really see the point of going to 5.1.

I think you’re right about that. And they should be turned off.

doca, where in your code do you set $username and $password?

drjamescook :slight_smile: Works fine, thanks.