General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 22nd, 2003, 12:33 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Question ben's member tutorial and login function

I have done this tutorial, Ben's membership tutorial, but i am having a problem. I don't understand why the following lines at the start of the index.php dont work.
PHP Code:
if(!$dtlsSecurity->IsLoggedIn() && !is_numeric(strpos($_SERVER["PHP_SELF"], "login.php")))
{
    
        if(
$_COOKIE['mem'] != '')
        {
            
header("location: login.php?strMethod=celogin");
        }


If a user as clicked the remember me checkbox, when he returns to the website they get cought in a loop as they are redirected to the CheckCookie function and then redirects the user back to the index.php page if cookie login is successful. How can i stop the login process from being cought in a loop?
__________________
regards,


Fulton

Reply With Quote
  #2  
Old September 22nd, 2003, 04:23 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
i have had this problem as well a few times. Check this for a misspelling:
Quote:
header("location: login.php?strMethod=celogin");


should be strMethod=checklogin. Hope this helps.
__________________
hey it's the CHARKING

Last edited by thecharking : September 22nd, 2003 at 04:30 AM.

Reply With Quote
  #3  
Old September 22nd, 2003, 04:53 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
It cant be
PHP Code:
 header("location: login.php?strMethod=checklogin"); 

As there is nothing to do for that in the login.php, but if you use
PHP Code:
 header("location: login.php?strMethod=check_login"); 

then you get an invalid login error.
So it has to be
PHP Code:
 header("location: login.php?strMethod=celogin"); 
for it to make any sense and check the cookie againt the database.

Reply With Quote
  #4  
Old September 22nd, 2003, 05:02 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
hmm...

this is my login script. Maybe it is different somehow?
PHP Code:
switch($strMethod)
{ case 
"check_login":
ProcessLogin();
break;
            
//here is case 'checklogin'
case "checklogin";
CheckCookie();
break;
                
default:
GetLogin();
break;
} } 


it refers to the function
PHP Code:
function CheckCookie()
{
$strQuery mysql_query("SELECT * FROM users WHERE session = '{$_COOKIE['mem']}'");
if(
$cookie mysql_num_rows($strQuery) > 0)
{
//cookie session = stored session, login
$result mysql_fetch_array($strQuery);
if(
$dtlsSecurity->StoreSession($result[0], $result[1], $result[3], "{$result[4]},{$result[5]}")) 
header("Location: index.php");
                
} else {
                
//cookie doesnt match any session
setcookie("mem","",time()-1);
header("Location: index.php");
        
} } 

I think we're talking about the same script... if your script is different, maybe it's not the same one, or maybe not the one that was in the support file? At any rate, I've got mine working this way.. although I am having problems with the remember me of the cookie, not the actual checking just it remembering. Oh well, lemme know how this is turning out.

Reply With Quote
  #5  
Old September 22nd, 2003, 05:08 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
OK i replace my code with your code and still get the same looping, below is what i have on my index.php page, what do u have

PHP Code:
include('class.security.php');
    
    
$dtlsSecurity = new Security;
    
    
$dtlsSecurity->ExtraFieldNames('firstname,lastname');
    
$dtlsSecurity->StoreSession_TableName('session');
    
$dtlsSecurity->Log_TableName('log');
    
$dtlsSecurity->FieldNames('sessionid''userid''username''auth');
    
    
$IsLoggedIn $dtlsSecurity->IsLoggedIn();
    
$details $dtlsSecurity->GetData();

if(!
$dtlsSecurity->IsLoggedIn() && !is_numeric(strpos($_SERVER["PHP_SELF"], "login.php")))
{
    if(
$_COOKIE['mem'] != '')
    {
        
header("location: login.php?strMethod=checklogin");
    }


Reply With Quote
  #6  
Old September 22nd, 2003, 05:23 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
it looks the same, except I have this line:
PHP Code:
 $dtlsSecurity->ExtraFieldNames('firstname,lastname, location, age'); 

I don't know if location and age are needed, I didn't add them though

here is my entire login page, i'll zip it for you. along with this and the previous code, it should work I think...
Attached Files
File Type: zip login.zip (1.9 KB, 353 views)

Reply With Quote
  #7  
Old September 22nd, 2003, 05:37 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
No still not working, what dose you class.security.php look like?
can you send me your revised copy of this members script?

Reply With Quote
  #8  
Old September 22nd, 2003, 05:48 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
double hmm...

i have the support file still I believe. I can't decide which it is since there were many and for some reason I forgot to label them properly. I will include the one with the most info, although this may be for another tutorial about writing articles (although I think that was jsut a later lesson in the one by ben).
Attached Files
File Type: zip supportfile.zip (24.0 KB, 442 views)

Reply With Quote
  #9  
Old September 22nd, 2003, 06:29 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Hi again i used the code you supplied with you previous post and i still get the looping.
This is what the index.php looked like
PHP Code:
include('class.security.php');

    
$dtlsSecurity = new Security;
    
    
$dtlsSecurity->ExtraFieldNames('firstname,lastname');
    
$dtlsSecurity->StoreSession_TableName('session');
    
$dtlsSecurity->Log_TableName('log');
    
$dtlsSecurity->FieldNames('sessionid''userid''username''auth');
    
    
$IsLoggedIn $dtlsSecurity->IsLoggedIn();
    
$details $dtlsSecurity->GetData();

if(!
$dtlsSecurity->IsLoggedIn() && !is_numeric(strpos($_SERVER["PHP_SELF"], "login.php")))
{
if(
$_COOKIE['mem'] != '')
{
header("location: login.php?strMethod=celogin");
}
}

The beginning of login.php page including the CheckCookie function.

[
PHP]

    
ob_start();

    require_once(
'class.security.php');
    
$dtlsSecurity = new Security;

    
$dtlsSecurity->ExtraFieldNames('firstname,lastname');
    
$dtlsSecurity->StoreSession_TableName('session');
    
$dtlsSecurity->Log_TableName('log');
    
$dtlsSecurity->FieldNames('sessionid''userid''username''auth');

    
$struName $_POST["struName"];
    
$strPass $_POST["strPass"];
    
$strMethod $_POST["strMethod"];

    if(
$strMethod == "")
        
$strMethod $_GET["strMethod"];

    if(!
$dtlsSecurity->IsLoggedIn())
            {

                switch(
$strMethod)
                        {
                                case 
"check_login":
                                        
ProcessLogin();
                                        break;
                                case 
"celogin";
                                        
CheckCookie();
                                        break;
                                default:
                                        
GetLogin();
                                        break;
                        }
                        
            }
    else
            {
                    if(
$strMethod == "logout")
                        
ProcessLogout();
                    else
                        
ShowLogOut();
            }

    function 
CheckCookie()
        {

            

            
$strQuery mysql_query("SELECT * FROM users WHERE session = '{$_COOKIE['mem']}'");
            if(
$cookie mysql_num_rows($strQuery) > 0)
                {

                    
//cookie session = stored session, login
                    
$result mysql_fetch_array($strQuery);
                    if(
$dtlsSecurity->StoreSession($result[0], $result[1], $result[3], "{$result[4]},{$result[5]}")) 
                        
header("Location: index.php");

                
                }
            else
                {
                
                    
//cookie doesnt match any session
                    
setcookie("mem","",time()-1);
                    
header("Location: index.php");
                    
                
                }

        } 


Last edited by DDDooGGG : September 22nd, 2003 at 06:36 AM.

Reply With Quote
  #10  
Old September 22nd, 2003, 06:30 AM
DDDooGGG DDDooGGG is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Melbourne, Australia
Posts: 97 DDDooGGG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 33 sec
Reputation Power: 6
Smile

OK, i got it working all properly,

Reply With Quote
  #11  
Old September 22nd, 2003, 06:35 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
yay!

I'm so glad I could help (if I did at all). I am so new to php it's a great reward to be abl to ehlp, even when it's just premade scripts and such. Hope to see your site soon! I'm guessing it's still in pretty early development stages if you are jsut implementing logins...
thanks for being patient with my bad scripts or whatever I had wrong.

Reply With Quote
  #12  
Old October 7th, 2003, 09:51 PM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)