PHP Login System with Admin Features

This forum was created to talk about the PHP Login System with admin features created by jpmaster77 on evolt's website


    [RESOLVED]Remember me "kind of" working

    Share

    outhowz42

    Number of posts : 7
    Registration date : 2009-02-24

    [RESOLVED]Remember me "kind of" working

    Post  outhowz42 on Tue Feb 24, 2009 11:07 am

    I am in the process of adapting this login system to my website. The remember me function only "kind of" works. For example, go to www.sportsloon.com and hit the login link on the top right.

    You can log in with these credentials (be sure to check remember me):
    Username: tester
    Password: tester

    Close the browser. Re-open the browser (IE7 or Firefox 3) and you are NOT logged in. However, if you hit the sportsloon link on the top left of the page (basically links you back home to www.sportsloon.com), then it shows you as being logged in. Why am I not logged in when I first open the browser? Why do I have to refresh the page? I can upload any files if you would like to have a look. I thought it was something with the session->referrer.

    I have made these changes to no avail.
    In the procLogin() function in process.php, in the login successful area, I changed header("Location: ".$session->referrer); to this:
    header("Location: ../index.php");

    In session.php I have also changed this line:
    $this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
    to this:
    $this->url = $_SESSION['url'] = $_SERVER['REQUEST_URI'];

    Neither fixed things. Any help is much appreciated. IM STUCK!!
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: [RESOLVED]Remember me "kind of" working

    Post  Fred-Eric on Tue Feb 24, 2009 12:25 pm

    I have do the test and I am still logged after closing the browser

    outhowz42

    Number of posts : 7
    Registration date : 2009-02-24

    Not tested correctly...

    Post  outhowz42 on Tue Feb 24, 2009 12:29 pm

    No, you must close ALL open internet windows. If testing with IE7, open, log in and check remember me. CLOSE ALL IE7 WINDOWS.

    Re-open, and you will not be logged in. Hit the sportsloon link in the top left and it will show you as logged in.

    If you do not close ALL IE7 browser windows, you will not see the problem. Try again please. I have tested this on 4 different computers and seen the same problem.
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: [RESOLVED]Remember me "kind of" working

    Post  Fred-Eric on Tue Feb 24, 2009 12:30 pm

    ok let me try that and I will be back in few minutes your can also contact via msn or aim
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: [RESOLVED]Remember me "kind of" working

    Post  Fred-Eric on Tue Feb 24, 2009 12:39 pm

    cheers it is working as expected

    first do this test clear all cookie and temp files.


    ok What I did is:

    closed all open windows
    the open ie7
    goto http://www.sportsloon.com/
    the I logged in as tester and tester as pass
    the I have close the window(all open windows ie7 and when I mean all I do close all)
    then open ie7
    type in http://www.sportsloon.com/
    then the page have been open as I am logged in

    your can check the cookie that also been created
    :

    Code:
    cookname
    tester
    www.sportsloon.com/
    1536
    3191292800
    29991325
    1745128336
    29988509
    *
    cookid
    5b4d87c2c4888e34f525a033fa1edfba
    www.sportsloon.com/
    1536
    3191292800
    29991325
    1745598336
    29988509
    *

    What I can say did you accept cookie from your site?

    outhowz42

    Number of posts : 7
    Registration date : 2009-02-24

    IT IS STILL INTERMITTENT!!!!

    Post  outhowz42 on Tue Feb 24, 2009 2:10 pm

    I cleared all private data, cleared all temp data.

    Open browser go to www.sportsloon.com, hit login, and log in as tester, tester.

    Close ALL browsers, re-open, go to sportsloon and I AM logged in. However, open and close the browser a few times and go to different sites, etc... eventually you will get to the point where you open the browser and are NOT logged in. You should remain logged in for 2 weeks.

    THIS IS REALLY ANNOYING. Just play with logging in and out a bunch of times, you can see the problem. Do you want me to use camtasia or something to record what I am seeing?

    Will echoing stuff to the screen help me here? How can I echo the cookie stuff?
    Mad

    outhowz42

    Number of posts : 7
    Registration date : 2009-02-24

    JUST NOTICED SOMETHING IMPORTANT

    Post  outhowz42 on Tue Feb 24, 2009 2:13 pm

    If I type the entire URL in when I open the browser again:

    http://www.sportsloon.com/

    The cookie works every time. GREAT!!

    However, if I open the browser and only type sportsloon.com, the cookie doesn't work right.

    (after the page renders and shows me as not logged in, the address in the bar is http://sportsloon.com/, where in the first scenario after the page renders and everything is correct the address in the bar is this: http://www.sportsloon.com/)

    Is there a workaround for this? THIS IS DEFINITELY THE PROBLEM AS IT IS REPEATABLE, TRY IT!

    Thanks for the help too!!!!

    outhowz42

    Number of posts : 7
    Registration date : 2009-02-24

    setcookie function in PHP

    Post  outhowz42 on Tue Feb 24, 2009 2:26 pm

    In the login system, the cookie is set like this:

    Code:
    if($subremember){
            setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
            setcookie("cookid",  $this->userid,  time()+COOKIE_EXPIRE, COOKIE_PATH);
          }

    Looking at documentation here: http://us3.php.net/setcookie, I believe changing the code to this will resolve my issue:

    Code:
    if($subremember){
            setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH, ".sportsloon.com", 1);
            setcookie("cookid",  $this->userid,  time()+COOKIE_EXPIRE, COOKIE_PATH, ".sportsloon.com", 1);
          }

    Quoting from the PHP site about the domain parameter:
    "The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. "

    If you look at my cookie contents you will see the www. I believe this is why it isn't working right. I will try the fix when I get home tonight and update the forum. Thanks.
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: [RESOLVED]Remember me "kind of" working

    Post  Fred-Eric on Tue Feb 24, 2009 2:47 pm

    outhowz42 wrote:
    Will echoing stuff to the screen help me here? How can I echo the cookie stuff?
    Mad

    <?php
    echo $cookie['cookname'];
    ?>
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: [RESOLVED]Remember me "kind of" working

    Post  Fred-Eric on Tue Feb 24, 2009 2:50 pm

    you should use .htaccess to always have www. in front of the domain name


    And it is also a good prctice for referencing and better SEO of your site.

    here is the .htaccess to achevive this:

    Code:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.).*)$ [OR,NC]
    RewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
    RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]

    So that way user who will type domain.com will be redirect to www.domain.com before even starting reading cookie.

    so this will resolve your problem

    outhowz42

    Number of posts : 7
    Registration date : 2009-02-24

    What to do with .htaccess

    Post  outhowz42 on Tue Feb 24, 2009 3:32 pm

    What should I do with that piece of code?

    Paste it in notepad, save the file as .htaccess and place it in the root directory of my website? I have never used .htaccess so I have no idea. Thanks.

    Wink
    avatar
    Fred-Eric

    Number of posts : 63
    Registration date : 2007-05-13

    Re: [RESOLVED]Remember me "kind of" working

    Post  Fred-Eric on Tue Feb 24, 2009 4:15 pm

    outhowz42 wrote:What should I do with that piece of code?

    Paste it in notepad, save the file as .htaccess and place it in the root directory of my website? I have never used .htaccess so I have no idea. Thanks.

    Wink

    that's right, just save as .htaccess and upload to root folder

    outhowz42

    Number of posts : 7
    Registration date : 2009-02-24

    Changed setcookie parameters and problem solved

    Post  outhowz42 on Wed Feb 25, 2009 12:17 pm

    Changed to

    Code:

    if($subremember){
            setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH, ".sportsloon.com");
            setcookie("cookid",  $this->userid,  time()+COOKIE_EXPIRE, COOKIE_PATH, ".sportsloon.com");
          }

    Problem solved!!! This thread can be closed or set to resolved.

    Sponsored content

    Re: [RESOLVED]Remember me "kind of" working

    Post  Sponsored content


      Current date/time is Mon Dec 11, 2017 7:00 pm