Results 1 to 3 of 3

Thread: Server will not execute this code?

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Server will not execute this code?

    I made a login script for my a cms and it worked perfectly while on my server, but when it was transfered to my clients server, it quit working. All the code is exactly the same as the code on mine, but on the clients server the login page will not execute the section of code that should process the login. The page simply reloads itself with the same content displayed.

    Here is the page code:
    PHP Code:
    <?php 
        session_start
    (); 
        require(
    'config.php'); 
        if ( isset(
    $_SESSION['username']) && isset($_SESSION['password']) && isset($_SESSION['ip']) ) {
            
    $redirect '<meta http-equiv="refresh" content="2;URL=index.php" />';
            
    $message 'You are already logged in as <i>'.$_SESSION['username'].'</i>, redirecting you to the home page...';
        } else { 
    $redirect ''$message ''; }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <?php echo $redirect ?>
    <title><?php echo(''.$siteName.''); ?></title>
    <link rel="stylesheet" href="main-style.css" type="text/css" />
    </head>

    <body>
    <div id="frame">
        <div id="border">
            <div id="content">
            
                <div id="banner"></div>
                
                <div id="status">
                    <div id="icon"><img src="images/user.png" alt="" /></div>
                    <div id="user"><span class="user"><?php echo $_SESSION['username']; ?>:</span> <a href="logout.php">Logout</a></div>
                    <div id="date"><?php echo(''.date('l F j, Y').''); ?></div>
                </div>
        
            <!-- Left Area -->
        
                <div id="left">
                    <div class="s_title">Login To View</div>
                    <div id="nav">
                        
                    </div>
                </div>
                
            <!-- /Left Area -->
                
                <div id="main">
                    <div class="spacer">
                <?php 
                
    if ( isset($_SESSION['username']) && isset($_SESSION['password']) && isset($_SESSION['ip']) ) {
                    
    $redirect '<meta http-equiv="refresh" content="2;URL=index.php" />';
                    echo(
    'You are already logged in as <i>'.$_SESSION['username'].'</i>, redirecting you to the home page...');
                } else {
                    
    // If form not sent
                    
    if (!isset($login_go)) { 
                
    ?>
                        <div class="title">Please Login</div>
                            <form method="post" action="<?php echo $_SERVER['PHP_SELF'?>">
                                <table width="220" align="center">
                                    <tr>
                                        <td>Username:</td>
                                        <td><input type="text" name="username" /></td>
                                    </tr>
                                    <tr>
                                        <td>Password:</td>
                                        <td><input type="password" name="password" /></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" align="center"><input type="submit" name="login_go" value="Login" /></td>
                                    </tr>
                                </table>
                            </form>
                <?php
                    
    }
                    
    // If form was sent
                    
    if (isset($login_go)) {
                        
    $username mysql_real_escape_string($_POST['username']);
                        
    $password md5($_POST['password']);
                            echo(
    "User: $username Pass: $password");
                            
    $check mysql_query("SELECT username, password FROM `admins` WHERE username = '$username'"
                                or die (
    "Error Checking User Information! \n<br />\n" .mysql_error());
                            
    $u mysql_fetch_array($check);
                            
    $chk mysql_num_rows($check);
                        
    // If username bad
                        
    if ($chk 1) { echo('<meta http-equiv="refresh" content="2;URL=login.php" /> <span style="color:#FF0000">Invalid username!</span>'); }
                        if (
    $password !== $u['password']) { 
                            echo(
    '<meta http-equiv="refresh" content="2;URL=login.php" /> <span style="color:#FF0000">Incorrect Password!</span>');
                        }
                        else if (
    $chk >= && $password == $u['password']) {
                            
    $_SESSION['username'] = $username;
                            
    $_SESSION['password'] = $password;
                            
    $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
                                echo(
    '<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="message">Welcome '.$_SESSION['username'].', you are now logged in and being redirected to the main page...</div>');
                        }
                    }
                }
                
    ?>
                    </div>
                </div>
            
                <div id="footer">
                    <div id="copyright"><?php copyright($siteName); ?></div>
                </div>
            
            </div>
        </div>
    </div>
    </body>
    </html>
    It seems that the page never executes this block of code:
    PHP Code:
    if (isset($login_go)) {
                        
    $username mysql_real_escape_string($_POST['username']);
                        
    $password md5($_POST['password']);
                            echo(
    "User: $username Pass: $password");
                            
    $check mysql_query("SELECT username, password FROM `admins` WHERE username = '$username'"
                                or die (
    "Error Checking User Information! \n<br />\n" .mysql_error());
                            
    $u mysql_fetch_array($check);
                            
    $chk mysql_num_rows($check);
                        
    // If username bad
                        
    if ($chk 1) { echo('<meta http-equiv="refresh" content="2;URL=login.php" /> <span style="color:#FF0000">Invalid username!</span>'); }
                        if (
    $password !== $u['password']) { 
                            echo(
    '<meta http-equiv="refresh" content="2;URL=login.php" /> <span style="color:#FF0000">Incorrect Password!</span>');
                        }
                        else if (
    $chk >= && $password == $u['password']) {
                            
    $_SESSION['username'] = $username;
                            
    $_SESSION['password'] = $password;
                            
    $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
                                echo(
    '<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="message">Welcome '.$_SESSION['username'].', you are now logged in and being redirected to the main page...</div>');
                        }
                    } 
    Is there any reason for this? Maybe the server doesn't like something in the code?

    Thanks in advance
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Try this:

    Code:
    isset($_POST['login_go'])
    That is the only thing I can think of as there is no reference to the variable login_go except for the name of the submit button; which, if register_globals() is not set on the hosting server's ini file, will cause the script to fail.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Try this:

    Code:
    isset($_POST['login_go'])
    That is the only thing I can think of as there is no reference to the variable login_go except for the name of the submit button; which, if register_globals() is not set on the hosting server's ini file, will cause the script to fail.

    Hope this helps.
    I did that and it did make a difference, but there is still a problem. Now it simply takes the content off of the page instead of running the php. I think that register_globals() is not set. Is there a way that I can get it turned on or would I have to talk to the host about that?

    Thanks
    Thanks DD, you saved me countless times

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
  •