Blank login screen using PHP MYSQL APACHE

Discussion in 'Web Design and Development' started by samgwatts, Mar 26, 2008.

  1. samgwatts macrumors newbie

    Joined:
    Mar 26, 2008
    #1
    Hi, I'm pulling the last few strands of my hair out with this problem.
    I'm working on a MAC with APACHE PHP and MYSQL through the MAMP software. I'm developing a site http://universalmaritime.com and i have come across the white screen of death problem on the login page. (login is at the bottom of the slide show on the homepage)
    This is the code in dreamweaver at the top of the login page that is giving me the problem i think.

    <?php require_once('Connections/USERS.php'); ?>
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
    session_start();
    }

    $loginFormAction = $_SERVER['PHP_SELF'];
    if (isset($_GET['accesscheck'])) {
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }

    if (isset($_POST['username'])) {
    $loginUsername=$_POST['username'];
    $password=$_POST['password'];
    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = "admin_home.php";
    $MM_redirectLoginFailed = "error.php";
    $MM_redirecttoReferrer = true;
    mysql_select_db($database_USERS, $USERS);

    $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

    $LoginRS = mysql_query($LoginRS__query, $USERS) or die(mysql_error());
    $loginFoundUser = mysql_num_rows($LoginRS);
    if ($loginFoundUser) {
    $loginStrGroup = "";

    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;

    if (isset($_SESSION['PrevUrl']) && true) {
    $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
    }
    else {
    header("Location: ". $MM_redirectLoginFailed );
    }
    }
    ?>

    Does anybody have the faintest idea of what the problem may be cause i don't. I just want this very simple log in page to work. OR is there a way to create an admin page with one username and password where databases are not involved. PLEASE HELP ME!!!!

    THANKS ALOT:confused:
     
  2. Volante macrumors regular

    Joined:
    Feb 8, 2008
    #2
    A blank screen is probably due to MAMP not displaying php errors as default. You can change this by editing MAMP/conf/php5/php.ini in your applications folder.

    Search for display_errors in php.ini and change it to:
    display_errors = On

    Then restart your apache server.
     
  3. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #3
    Thanks for your quick reply,

    I have tried doing that but it won't give me permissions!!! even on my own machine!!! How do i get round this?

    Thanks
     
  4. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #4
    There are several solutions to this problem.

    The Terminal way:

    • Use sudo to become the root user
    • Edit the file with your favorite command-line editor

    The half-Terminal way:

    • Use sudo to become the root user
    • Use the open command to open TextEdit (or your favorite GUI editor)

    The non-Terminal way:

    • Make a copy of the file in a place you have write permissions (e.g. your Desktop)
    • Edit the file with your favorite editor
    • Overwrite the original with the edited copy - Finder will ask you for your password
     
  5. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #5
    Thanks for your reply wrldwzrd89,
    I managed to get into the PHP.ini file and changed errors to ON but i see no errors displayed in the browser of my login page. http://www.universalmaritime.com/admin_page.php. I have restarted the MAMP server. Where else could the errors for this blank screen problem be?

    Sorry for being a pain!
     
  6. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #6
    Check your logs - the error, if there was one, is probably in there.
     
  7. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #7
    My logs in the MAMP folder show as follows:

    For mysql errors:
    080326 13:58:33 [Warning] You have forced lower_case_table_names to 0 through a command-line option, even though your file system '/Applications/MAMP/db/mysql/' is case insensitive. This means that you can corrupt a MyISAM table by accessing it with different cases. You should consider changing lower_case_table_names to 1 or 2
    080326 13:58:33 [Warning] One can only use the --user switch if running as root
    080326 13:58:34 InnoDB: Started; log sequence number 0 43665
    080326 13:58:34 [Note] /Applications/MAMP/Library/libexec/mysqld: ready for connections.
    Version: '5.0.41' socket: '/Applications/MAMP/tmp/mysql/mysql.sock' port: 8889 Source distribution.

    My PHP errors :
    [21-Mar-2008 11:01:20] PHP Notice: Undefined variable: loginFormAction in /Users/Sambo/Web/Universal site/admin_page.php on line 226

    My apache errors:
    authentication ...
    [Wed Mar 26 13:58:34 2008] [notice] Digest: done
    [Wed Mar 26 13:58:34 2008] [notice] Apache/2.0.59 (Unix) PHP/4.4.7 DAV/2 configured -- resuming normal operations


    Are these any help to anyone??
     
  8. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #8
    Code:
    [21-Mar-2008 11:01:20] PHP Notice:  Undefined variable: loginFormAction in /Users/Sambo/Web/Universal site/admin_page.php on line 226
    That, right there, is the cause of your problem. You're trying to reference a variable called loginFormAction before it's been defined.
     
  9. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #9
    Well done for spotting the problem, so how do i go about sorting it out. If you can imagine i'm looking at my login page i created in dreamweaver and connected to the mysql database, what should be done to the username and password form i created.

    Thanks for you help
     
  10. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #10
    Remember this all works fine in my testing server but i get the blank screen when i post it up to the web.
     
  11. Volante macrumors regular

    Joined:
    Feb 8, 2008
    #11
    That's two different web enviroments then, with different settings.

    Again, it's the error handling. On the server you're uploading to, notices are resulting in errors that' kills the script. Also the blank page is on the server is probably result of display_erros being off, you probably have some sort of error_log on the server as well. Please check your php-settings on the server. This can be done by uploading a simple script:
    phpinfo.php
    <?php
    phpinfo();
    ?>

    You can fix the error by either:
    A. Fixing the notice in the phpscript.
    B. Changing settings in php.ini on the servers to:
    error_reporting = E_ALL & ~E_NOTICE
    C. Setting error_reporting in the phpscript:
    error_reporting(E_ALL ^ E_NOTICE);
     
  12. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #12
    Ok I think i Follow you.
    so would i upload the sript:
    phpinfo.php
    <?php
    phpinfo();
    ?>

    on the login page i created, which would give me php settings for the server when i upload the file to the web. right?

    I also need to contact my server admin to change error display to ON?

    basically your saying its not a problem my end but with my server administrator?

    Sam
     
  13. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #13
    The problem IS on your end. Changing these settings would make it easier for you to figure out what is going on on the web server end.
     
  14. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #14
    RIGHT, I have an error!!

    this is what it says:
    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Users/Sambo/Web/Universal site/admin_page.php:5) in /Users/Sambo/Web/Universal site/admin_page.php on line 9

    Is this any help?
     
  15. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #15
    I'm about to pick up my mac and throw through a window!!

    Hi All
    I REALLY hope someone can help me. They will be a God/Goddess if they can.

    My problem:
    I am developing a website and my client wants a login page which has just one username and password so members of his company can login using the same user name and password and download stuff from the private section.
    I'm on a Mac running Apache, Mysql, PHP through MAMP. I have created a database in MAMP of a username and password and have created the login form in dreamweaver. A mysql connection has been made to the database and i have attached the "log in user" server behavior which gives me the following in the Actions box of the form i made <?php echo $loginFormAction; ?>

    When i test it on my testing server its fine and works perfectly, when i test it on the web, all i get is a blank screen - nothing!

    I then enabled errors in my PHP.ini files and got some code.

    I now get the following code in my testing server and still nothing on the web.

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Users/Sambo/Web/Universal site/admin_page.php:2) in /Users/Sambo/Web/Universal site/admin_page.php on line 6
    session_start();

    I have tried putting the session_start() at the top of the page but i still get a blank page when i upload.

    The code on the page in dreamweaver is as follows:


    PHP:
    <?php require_once('Connections/userslogin.php'); ?>
    <?php
    // *** Validate request to login to this site.
    if (!isset($_SESSION)) {
       
    session_start();
    }

    $loginFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_GET['accesscheck'])) {
      
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
    }

    if (isset(
    $_POST['username'])) {
      
    $loginUsername=$_POST['username'];
      
    $password=$_POST['password'];
      
    $MM_fldUserAuthorization "";
      
    $MM_redirectLoginSuccess "admin_home.php";
      
    $MM_redirectLoginFailed "error.php";
      
    $MM_redirecttoReferrer false;
      
    mysql_select_db($database_userslogin$userslogin);
      
      
    $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username='%s' AND password='%s'",
        
    get_magic_quotes_gpc() ? $loginUsername addslashes($loginUsername), get_magic_quotes_gpc() ? $password addslashes($password)); 
       
      
    $LoginRS mysql_query($LoginRS__query$userslogin) or die(mysql_error());
      
    $loginFoundUser mysql_num_rows($LoginRS);
      if (
    $loginFoundUser) {
         
    $loginStrGroup "";
        
        
    //declare two session variables and assign them
        
    $_SESSION['MM_Username'] = $loginUsername;
        
    $_SESSION['MM_UserGroup'] = $loginStrGroup;          

        if (isset(
    $_SESSION['PrevUrl']) && false) {
          
    $MM_redirectLoginSuccess $_SESSION['PrevUrl'];    
        }
        
    header("Location: " $MM_redirectLoginSuccess );
      }
      else {
        
    header("Location: "$MM_redirectLoginFailed );
      }
    }
    ?>

    Please can someone help me with this problem. Its been giving me problems for days.

    Thanks alot!
    Sam
     
  16. ruckus macrumors regular

    ruckus

    Joined:
    Oct 19, 2005
    #16
    This happens when you try to output text to the browser before the session_start() command. Be sure to also check your included file, userlogin.php.

    I know this one is tricky it took me awhile to figure out too. It was a long time ago so I am not sure how much help i can be.

    But maybe make sure your session_start() happens first before anything else happens?
     
  17. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #17
    Ok, I have moved the start_sessions() to the top which gets rid of the warning error. When i try and log in on the testing server i now get the following error on the login page

    Warning: Cannot modify header information - headers already sent by (output started at /Users/Sambo/Web/Universal site/admin_page.php:2) in /Users/Sambo/Web/Universal site/admin_page.php on line 38
    session_start();
     
  18. ruckus macrumors regular

    ruckus

    Joined:
    Oct 19, 2005
    #18
    I believe its the same problem happening all over your code. Take some time to go through and make sure the session isn't open after you have started outputting to the browser.
     
  19. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #19
    My userslogin.php (in my connections file) script is displaying some errors.
    They are as follows:

    PHP:
    <?php
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_userslogin "localhost";
    $database_userslogin "users";
    $username_userslogin "root";
    $password_userslogin "root";
    $userslogin mysql_pconnect($hostname_userslogin$username_userslogin$password_userslogin) or trigger_error(mysql_error(),E_USER_ERROR); 
    ?>
    Any Ideas??
     
  20. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #20
    Are you using UTF-8 text encoding? If so: you may try setting it to "UTF-8, no BOM" and not just UTF-8.

    Some servers go completely nuts if you don't (while others doesn't seem to mind). I struggled a while with this when we begun migrating stuff to our own server a while back...
     
  21. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
    #21
    Hi,
    Yes I' am using UTF-8_Unicode_ci. MAMP doesn't give me the option to use "no Bom"
     
  22. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #22
    That sounds like the mysql collation, which encoding do you use for your text files, ie. your php files? (Which text editor do you use, btw?)
     
  23. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008
  24. Mitthrawnuruodo Moderator emeritus

    Mitthrawnuruodo

    Joined:
    Mar 10, 2004
    Location:
    Bergen, Norway
    #24
    Yes, but which text editor do you use to write the code in?

    TextWrangler? BBEdit? DreamWeaver? TextMate? Smultron? ...?
     
  25. samgwatts thread starter macrumors newbie

    Joined:
    Mar 26, 2008

Share This Page