Results 1 to 3 of 3

Thread: URL/Login Problems

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

    Question URL/Login Problems

    Well, I have been going around and around trying to make my login script (which has worked in the past) work. I finally got it down to one problem with some help from others. The problem now is that when I login on this page: http://resonant-media.com/client_work/cms/cms/login.php, my login script does not read the sessions, but if I login here: http://www.resonant-media.com/client_work/cms/cms/login.php, my login script reads the sessions.

    I also set up a page to make sure the sessions are set. If I login on the page with www. in front of the url, I can see the variables set from my session reader only if I put www. in front of the url. It also does the same thing when I do not put in www., just in the opposite way (login without www. and read without www.).

    I have never had this problem before and can't think of any reason for it. Anyone have any ideas?

    Here is my login page code:
    (login.inc.php)
    PHP Code:
    <?php 

    ########## If Login Hit ##########
    if ($_POST['login']) {
        
    $user mysql_real_escape_string($_POST['user']);
        
    $pass md5($_POST['pass']);
        
        
    // Get User Data
        
    $check mysql_query("SELECT * FROM `admins` WHERE user = '$user'") or die ("Error Checking Username! \n<br />\n" .mysql_error());
        
    $u mysql_fetch_array($check);
        
    $chk mysql_num_rows($check);
        
    //
        
        // Check Fields
        
    if (!$user || !$pass) { echo('<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'" /> <div class="error">Please fill in all fields!</div>'); }
        
    //
        
        // Check User
        
    else if ($chk 1) { echo('<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'" /> <div class="error">Invalid username!</div>'); }
        
    //
        
        
        // Check Password
        
    else if ($u['pass'] !== $pass) { echo('<meta http-equiv="refresh" content="2;URL='.$_SERVER['PHP_SELF'].'" /> <div class="error">Invalid password!</div>'); }
        
    //
        
        // If Everything Checks Out
        
    else {
            
    $_SESSION['user'] = $user;
            
    $_SESSION['pass'] = $pass;
            
    $_SESSION['site'] = $siteName;
            
            echo(
    '<meta http-equiv="refresh" content="2;URL=index.php" /> <div class="message">Welcome '.$_SESSION['user'].', you are now logged in!</div>'); 
        }
    }    
        
    ########## If Login Not Hit ##########
    if (!$_POST['login']) { ?>

        <div class="message">Admin Login</div> <br /><br />
        
            <!-- Login Form -->
                    <form method="post" action="<?php echo $_SERVER['PHP_SELF'?>">
                        <table width="250" align="center">
                            <tr>
                                <td>Username:</td>
                                <td><input type="text" name="user" /></td>
                            </tr>
                            <tr>
                                <td>Password:</td>
                                <td><input type="password" name="pass" /></td>
                            </tr>
                            <tr>
                                <td></td>
                                <td><input type="submit" name="login" value="Login" /></td>
                            </tr>
                        </table>
                    </form>
            <!-- /Login Form -->
            
    <? }

    ?>
    That page is called within this page:
    (login.php)
    PHP Code:
    <?php @session_start(); require('config.php'); chkBan(); chkLogin(); ?>
    <!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" />
    <title><?php echo $m['title'?> | Admin Panel</title>
    <link rel="stylesheet" href="main-style.css" type="text/css" />
    </head>

    <body>
    <div id="frame">
        <div id="border">
            
            <div id="top">
                <div class="t_txt"><?php echo $siteName ?></div>
            </div>
            
            <div id="left">
                <div class="s_title">Navigation</div>
    <?php require('includes/nav.inc.php'); ?>
            </div>
            
            <div id="main">
                <div class="spacer"><?php require('login.inc.php'); ?></div>
            </div>
            
            <div id="footer">
                <div id="footer_txt"><?php echo $m['copyright'?></div>
            </div>
        
        </div>
    </div>
    </body>
    </html>
    And here is the chkLogin() function:
    PHP Code:
    function chkLogin($loginRedirect){if(!isset($_SESSION['user'])){header("Location:$loginRedirect");}} 
    Any ideas, thanks
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    That's just how sessions work. "www" is kinda considered as a sub-domain.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It is a subdomain.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •