In de knoei met login check

Gestart doorRiick10 reacties30 weergaven

11 berichten · pagina 1 van 1

Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi,
Ik heb nu me login systeem bijna af.
Ik heb enkel nog een probleem met de pagina (checklogin.php) die mijn pagina checkt.
de error die ik krijg is:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/zabyeay50/domains/challas.nl/public_html/checklogin.php on line 27


en de code die ik als checklogin.php gebruik is:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/ob_start"]ob_start[/URL][COLOR= #007700]();[/COLOR]
[COLOR= #0000BB]$host[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Host name [/COLOR]
[COLOR= #0000BB]$username[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"zabyeay50_game"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Mysql username [/COLOR]
[COLOR= #0000BB]$password[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"veN4l5uF"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Mysql password [/COLOR]
[COLOR= #0000BB]$db_name[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"zabyeay50_game"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Database name [/COLOR]
[COLOR= #0000BB]$tbl_name[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"scores"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// Table name

// Connect to server and select databse.[/COLOR]
[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"$host"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"$username"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]"$password"[/COLOR][COLOR= #007700])[/COLOR]or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"cannot connect"[/COLOR][COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"$db_name"[/COLOR][COLOR= #007700])[/COLOR]or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"cannot select DB"[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]// Define $myusername and $mypassword [/COLOR]
[COLOR= #0000BB]$myusername[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]myusername[/COLOR][COLOR= #007700]];[/COLOR] 
[COLOR= #0000BB]$mypassword[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]mypassword[/COLOR][COLOR= #007700]];[/COLOR]

[COLOR= #FF8000]// To protect MySQL injection (more detail about MySQL injection)[/COLOR]
[COLOR= #0000BB]$myusername[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$myusername[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$mypassword[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$mypassword[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$myusername[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$myusername[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$mypassword[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$mypassword[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]=[/COLOR][COLOR= #DD0000]"SELECT * FROM $tbl_name WHERE username=$myusername and password=$mypassword"[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$result[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]// Mysql_num_row is counting table row[/COLOR]
[COLOR= #0000BB]$count[/COLOR][COLOR= #007700]=[/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #FF8000]// If result matched $myusername and $mypassword, table row must be 1 row[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR][COLOR= #007700]==[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]){[/COLOR]
[COLOR= #FF8000]// Register $myusername, $mypassword and redirect to file "login_success.php"[/COLOR]
[URL="http://www.php.net/session_register"]session_register[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"myusername"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/session_register"]session_register[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"mypassword"[/COLOR][COLOR= #007700]);[/COLOR] 
[URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"location:login_success.php"[/COLOR][COLOR= #007700]);
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Wrong Username or Password"[/COLOR][COLOR= #007700];
}[/COLOR]

[URL="http://www.php.net/ob_end_flush"]ob_end_flush[/URL][COLOR= #007700]();[/COLOR]
?>
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Gooi dit script weg.........

onveilig, oude functies, missende foutafhandeling.

Leer PHP en schrijf dit opnieuw. 90% van de code is en al inefficient en fout/oud.
Dit zou in 2001 nog wel eens vlekkeloos werken, maar in 2012 zou ik je er niet meer aan wagen.

Terug naar de tekentafel.
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dat weet ik, ik heb het ook niet zelf geschreven.
Ik zocht enkel een php inlog/register systeem dat simpel is.
Weet jij misschien 1 die slimmer is?
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Multisess is een mooi begin. Zie het scriptstopic.
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
is dat een systeem oid?
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
kijk nou maar..........

Alles wat PHP is is een systeem.
0
Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Riick schreef:
is dat een systeem oid?
Ja. Die gebruik ik ook. Door Aarclay zelf gemzakt.
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Oke bedankt, maar waar vind ik deze?
Ik zal nu wel even googlen.

toevoeging op 10 april 2012, 23:22:35:
fail, sorry niet goed gelezen!
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik raad je idd multisess ook aan, als je de sessies er uit wilt is het maar een klrine moeite.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Sanderc schreef:
Ik raad je idd multisess ook aan, als je de sessies er uit wilt is het maar een klrine moeite.
En de belangrijkste functionaliteit haal je er dan ook uit. Zoiets als een auto zonder wielen, of een fiets zonder stuur.

Of doel je op het sessie-overzicht? wink
0
Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ook lekker handig om je database wachtwoord te posten. emo
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