SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    PHP Code:
    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
    PHP Code:
    // 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;


  2. #2
    SitePoint Member
    Join Date
    Feb 2010
    Location
    Arkansas, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two things, first, the function verifylogin() should return true or false. Not "".

    Also, the code below is completely unnecessary.

    PHP Code:
    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);

  3. #3
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    689
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,491
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ahundiak View Post
    I'm sort of guessing your code might be relying on majic quotes and register globals which are probably turned off by default.
    I think you're right about that. And they should be turned off.

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

  5. #5
    SitePoint Zealot doca's Avatar
    Join Date
    Dec 2004
    Location
    Vienna, AT
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    drjamescook Works fine, thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •