Werkt dit goed? Inlogsysteem./

Gestart doorWouterr3 reacties22 weergaven

4 berichten · pagina 1 van 1

Wouterr

Lid · Topicstarter

Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

Hey,

Ik ben bezig met een ledensysteem, en als je dus inlogt word er een random code in een cookie, session en de Database gezet (Bij de gebruiker).
Als hij uitlogt dan zet ik de cookie naar -3600 en destroy de session.
ik gebruik dit:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]function[/COLOR] is_loggedin[COLOR= #007700]()
{[/COLOR]
    [COLOR= #0000BB]$naam[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR]
    [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]);[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$naam[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]""[/COLOR] [COLOR= #007700]||[/COLOR] [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])
    {[/COLOR]
        [COLOR= #0000BB]$naam[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]gebruikersnaam[/COLOR][COLOR= #007700]]);[/COLOR]
        [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_COOKIE[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]code[/COLOR][COLOR= #007700]]);[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$naam[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]""[/COLOR] [COLOR= #007700]||[/COLOR] [COLOR= #0000BB]$code[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/return"]return[/URL] false[COLOR= #007700];
        }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$check[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden WHERE code = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]" AND naam = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$naam[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$check[/COLOR][COLOR= #007700]) >[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
            {[/COLOR]
                [URL="http://www.php.net/return"]return[/URL] true[COLOR= #007700];
            }[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
            [COLOR= #007700]{[/COLOR]
                [URL="http://www.php.net/return"]return[/URL] false[COLOR= #007700];
            }
        }
    }[/COLOR][URL="http://www.php.net/else"]else[/URL][COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$check[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden WHERE code = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$code[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]" AND naam = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$naam[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$check[/COLOR][COLOR= #007700]) >[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/return"]return[/URL] true[COLOR= #007700];
        }
    }
}[/COLOR]
?>


om te checken of hij ingelogt is.
Alleen als er dus iemand anders inlogt, is die gene direct uitgelogt.
Hoe kan ik zorgen dat het wel safe is, maar dan niet direct dat er max 1 ingelogt kan zijn?
Net zoals op one2xs ;p.

Alvast bedankt.
Wouter
0
Fass

Lid

Berichten
3.771
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wie bedoel je met die gene? De eerste of de tweede die inlogt?
0
Wouterr

Lid · Topicstarter

Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

Die als eerst inlogt, en dan bijvoorbeeld op je mobiel, dan word op je mobiel een andere random code in de database gezet, en word e dus op je PC uitgelogt.
Hoe kan ik zorgen dat dit bijde mogelijk is, maar tog dat het veilig is voor hackers?
En bijv geen wachtwoord in een session/cookie moet zetten.
0
Fass

Lid

Berichten
3.771
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bij het zetten van die cookie moet je dan eerst kijken of er al een code is, als die er al is zet je die in de cookie, anders genereer je een nieuwe.
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren