PHP Script verbeteren,

Gestart doorJurre4 reacties15 weergaven

5 berichten · pagina 1 van 1

Jurre

Lid · Topicstarter

Berichten
1.950
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo

Ik heb een ledensysteem wat omgebouwt tot een licenty systeem, Maar zouden jullie tips, om de snelheid en de veiligheid te verbeteren kunnen geven?

[COLOR= #0000BB]<?php[/COLOR]

[COLOR= #FF8000]//this is here for security reasons[/COLOR]
[URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$key[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$val[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$key[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR]htmlspecialchars[COLOR= #007700]([/COLOR][COLOR= #0000BB]$val[/COLOR][COLOR= #007700],[/COLOR] ENT_QUOTES[COLOR= #007700])));[/COLOR]
    $[COLOR= #0000BB]$key[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR]htmlspecialchars[COLOR= #007700]([/COLOR][COLOR= #0000BB]$val[/COLOR][COLOR= #007700],[/COLOR] ENT_QUOTES[COLOR= #007700])));
}[/COLOR]
[URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$key[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$val[/COLOR][COLOR= #007700]) {[/COLOR]
    [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]$key[/COLOR][COLOR= #007700]] =[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR]htmlspecialchars[COLOR= #007700]([/COLOR][COLOR= #0000BB]$val[/COLOR][COLOR= #007700],[/COLOR] ENT_QUOTES[COLOR= #007700])));[/COLOR]
    $[COLOR= #0000BB]$key[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/stripslashes"]stripslashes[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR]htmlspecialchars[COLOR= #007700]([/COLOR][COLOR= #0000BB]$val[/COLOR][COLOR= #007700],[/COLOR] ENT_QUOTES[COLOR= #007700])));
}[/COLOR]

[COLOR= #0000BB]$sqlhost[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//mysql host (usually localhost)[/COLOR]
[COLOR= #0000BB]$sqluser[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"naam_van_je_mysql_account"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//mysql username[/COLOR]
[COLOR= #0000BB]$sqlpass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"wachtwoord"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//mysql password[/COLOR]
[COLOR= #0000BB]$sqldb[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"database_naam"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//mysql database name[/COLOR]

[COLOR= #0000BB]$connect[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sqlhost[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$sqluser[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$sqlpass[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"0"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//connect to the server or give a server error[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$sqldb[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//connect to the database[/COLOR]

[COLOR= #0000BB]$act[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"act"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//get the action that the game or user is doing

//register
/*
http://yoururl.com/game.php?act=reg&user=username&pass=password
*/[/COLOR]
[COLOR= #007700]function[/COLOR] register[COLOR= #007700]() {[/COLOR]
    [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"user"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//username that the game provides[/COLOR]
    [COLOR= #0000BB]$pass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//password that the game provides[/COLOR]
    [COLOR= #0000BB]$regcheck[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username=$user"[/COLOR][COLOR= #007700]));[/COLOR] [COLOR= #FF8000]//mysql query checking if the user exists[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$regcheck[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"1"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game that the username is taken[/COLOR]
    [COLOR= #007700]}[/COLOR]
    [COLOR= #0000BB]$register[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"INSERT INTO users (`username`,`password`,`score`,`room`,`x`,`y`) VALUES ($user,$pass,0,1,50,50)"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//since the username was not taken we will insert values into the mysql table (change the room number, x, and y to what you want)[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$register[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"2"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game that the registration was successful[/COLOR]
    [COLOR= #007700]}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"0"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game there was an error with the server[/COLOR]
    [COLOR= #007700]}
}[/COLOR]

[COLOR= #FF8000]//login
/*
http://yoururl.com/game.php?act=log&user=username&pass=password
*/[/COLOR]
[COLOR= #007700]function[/COLOR] login[COLOR= #007700]() {[/COLOR]
    [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"user"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//username that the game provides[/COLOR]
    [COLOR= #0000BB]$pass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//password that the game provides[/COLOR]
    [COLOR= #0000BB]$login[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username=$user and password=$pass and online=0"[/COLOR][COLOR= #007700]));[/COLOR] [COLOR= #FF8000]//mysql query checking: if the username exists, if the passwords match, and if the user is already online[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$login[/COLOR][COLOR= #007700]) {[/COLOR] [COLOR= #FF8000]//username exists, password is correct, and user is not online[/COLOR]
        [COLOR= #0000BB]$online[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE users SET online = 1 WHERE username=$user and password=$pass"[/COLOR][COLOR= #007700]);[/COLOR]
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$online[/COLOR][COLOR= #007700]) {[/COLOR]
            [COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username=$user and password=$pass"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game that we are now logged in and send over the players score, room, x, and y[/COLOR]
            [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$stats[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
                  [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"score = $stats[score]; global.proom = $stats[room]; global.px = $stats[x]; global.py = $stats[y];"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//the variables that are being sent[/COLOR]
             [COLOR= #007700]}
        }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
            [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"0"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game there was an error with the server[/COLOR]
        [COLOR= #007700]}
    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [COLOR= #FF8000]//tell the game one of these errors:
        //user is already online
        //username doesnt exist
        //password does not match the one with the username[/COLOR]
        [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"3"[/COLOR][COLOR= #007700]);
    }
}[/COLOR]

[COLOR= #FF8000]//save
/*
http://yoururl.com/game.php?act=sav&user=username&pass=password&score=400&room=2&x=20&y=40
*/[/COLOR]
[COLOR= #007700]function[/COLOR] save[COLOR= #007700]() {[/COLOR]
    [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"user"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//username that the game provides[/COLOR]
    [COLOR= #0000BB]$pass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//password that the game provides[/COLOR]
    [COLOR= #0000BB]$score[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"score"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//score that the game provides[/COLOR]
    [COLOR= #0000BB]$room[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"room"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//room that the game provides[/COLOR]
    [COLOR= #0000BB]$x[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"x"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//x that the game provides[/COLOR]
    [COLOR= #0000BB]$y[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"y"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//y that the game provides[/COLOR]
    [COLOR= #0000BB]$savuser[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE users SET score=$score,room=$room,x=$x,y=$y WHERE username=$user and password=$pass and online=1"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//mysql query that takes all of the values sent by the game and puts them into the table[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$savuser[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"4"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game that the save was a success[/COLOR]
    [COLOR= #007700]}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"0"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game there was an error with the server[/COLOR]
    [COLOR= #007700]}
}[/COLOR]

[COLOR= #FF8000]//logout
/*
http://yoururl.com/game.php?act=out&user=username&pass=password
*/[/COLOR]
[COLOR= #007700]function[/COLOR] logout[COLOR= #007700]() {[/COLOR]
    [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"user"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//username that the game provides[/COLOR]
    [COLOR= #0000BB]$pass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"pass"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//password that the game provides[/COLOR]
    [COLOR= #0000BB]$logout[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"UPDATE users SET online = 0 WHERE username=$user and password=$pass"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//mysql query that updates whether the user is online[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$logout[/COLOR][COLOR= #007700]) {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"5"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game that the logout was a success[/COLOR]
    [COLOR= #007700]}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"0"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//tell the game there was an error with the server[/COLOR]
    [COLOR= #007700]}
}[/COLOR]

[COLOR= #FF8000]//signature
/*
http://yoururl.com/game.php?act=sig&user=username
*/[/COLOR]
[COLOR= #007700]function[/COLOR] sig[COLOR= #007700]() {[/COLOR]
    [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Content-type: image/png"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//this lines tells the browers that the PHP file is a PNG image[/COLOR]
    [COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"user"[/COLOR][COLOR= #007700]];[/COLOR] [COLOR= #FF8000]//username to display on the signature[/COLOR]
    [COLOR= #0000BB]$img[/COLOR] [COLOR= #007700]=[/COLOR] imagecreate[COLOR= #007700]([/COLOR][COLOR= #0000BB]150[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]28[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//makes an image that is 150 pixels wide by 28 high pixels[/COLOR]
    [COLOR= #0000BB]$black[/COLOR] [COLOR= #007700]=[/COLOR] imagecolorallocate[COLOR= #007700]([/COLOR][COLOR= #0000BB]$img[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//makes the background color black[/COLOR]
    [COLOR= #0000BB]$white[/COLOR] [COLOR= #007700]=[/COLOR] imagecolorallocate[COLOR= #007700]([/COLOR][COLOR= #0000BB]$img[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]255[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]255[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]255[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//the color white (used for text)
    //if you want to change the text or backgroud color then re-enter the RGB values[/COLOR]
    imagestring[COLOR= #007700]([/COLOR][COLOR= #0000BB]$img[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]0[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Name of your game"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$white[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//draws the text "Name of your game" (the first number is the size of the text, the second is the x position of the text, the third is the y position of the text)[/COLOR]
    [COLOR= #0000BB]$statsq[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username=$user"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"ERROR"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//mysql query to get * (meaning anyting) from the table where the username is $user[/COLOR]
    [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$stats[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$statsq[/COLOR][COLOR= #007700])) {[/COLOR]
          imagestring[COLOR= #007700]([/COLOR][COLOR= #0000BB]$img[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]10[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Username: $stats[username]"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$white[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//draws the players username[/COLOR]
        imagestring[COLOR= #007700]([/COLOR][COLOR= #0000BB]$img[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]20[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]"Score: $stats[score]"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$white[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//draws the players score[/COLOR]
    [COLOR= #007700]}[/COLOR]
    imagepng[COLOR= #007700]([/COLOR][COLOR= #0000BB]$img[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//draws the whole image as a PNG[/COLOR]
    imagedestroy[COLOR= #007700]([/COLOR][COLOR= #0000BB]$img[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//destroys the whole image[/COLOR]
[COLOR= #007700]}[/COLOR]

[COLOR= #FF8000]//scores
/*
http://yoururl.com/game.php
*/[/COLOR]
[COLOR= #007700]function[/COLOR] scores[COLOR= #007700]() {[/COLOR]
    [COLOR= #0000BB]$scoresq[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users ORDER BY score DESC LIMIT 5"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"ERROR"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//mysql query that gets * from the table, displays them in descending order, and limits the amount to show to 5[/COLOR]
     [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"<table><tr><td align=center><b>Name</b></td><td align=center><b>Score</b></td></tr>"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//makes the start of the table[/COLOR]
     [URL="http://www.php.net/while"]while[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$scores[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$scoresq[/COLOR][COLOR= #007700])) {[/COLOR]
          [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"<tr><td align=center style=font-color: white;>"[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$scores[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"username"[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]"</td>
        <td align=center style=font-color: white;>"[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$scores[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"score"[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]"</td></tr>"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//makes the username and score show[/COLOR]
     [COLOR= #007700]}[/COLOR]
     [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]"</table>"[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]//makes the end of the table[/COLOR]
[COLOR= #007700]}[/COLOR]

[COLOR= #FF8000]//what is the game or user doing?[/COLOR]
[URL="http://www.php.net/switch"]switch[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$act[/COLOR][COLOR= #007700]) {
    case[/COLOR] [COLOR= #DD0000]"reg"[/COLOR][COLOR= #007700]:[/COLOR] register[COLOR= #007700]();[/COLOR] [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//if the game is registering[/COLOR]
    [COLOR= #007700]case[/COLOR] [COLOR= #DD0000]"log"[/COLOR][COLOR= #007700]:[/COLOR] login[COLOR= #007700]();[/COLOR] [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//if the game is logging in[/COLOR]
    [COLOR= #007700]case[/COLOR] [COLOR= #DD0000]"sav"[/COLOR][COLOR= #007700]:[/COLOR] save[COLOR= #007700]();[/COLOR] [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//if the game is saving[/COLOR]
    [COLOR= #007700]case[/COLOR] [COLOR= #DD0000]"out"[/COLOR][COLOR= #007700]:[/COLOR] logout[COLOR= #007700]();[/COLOR] [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//if the game is logging out[/COLOR]
    [COLOR= #007700]case[/COLOR] [COLOR= #DD0000]"sig"[/COLOR][COLOR= #007700]:[/COLOR] sig[COLOR= #007700]();[/COLOR] [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//displays a signature[/COLOR]
    [COLOR= #007700]default:[/COLOR] scores[COLOR= #007700]();[/COLOR] [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//this is the default page (displays scores)[/COLOR]
[COLOR= #007700]}[/COLOR]
?>
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Sowieso never ever wachtwoorden in een url verzenden.
0
Berichten
676
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rik schreef:
Sowieso never ever wachtwoorden in een url verzenden.
Ja das domste wat je kan doen
0
Jurre

Lid · Topicstarter

Berichten
1.950
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
wordt niet gebruikt voor wachtwoorden, maar wordt gebruikt voor een online serial syteem,
0
Berichten
970
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zeer onveilig, via alleen http helemaal.
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