Database naar externe host?

Gestart doorRiick2 reacties28 weergaven

3 berichten · pagina 1 van 1

Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hoi,
Ik ben nu bezig met mijn inlog systeem voor mijn spel te installeren.
Nu zit ik een klein beetje vast met het database systeem.
Ik heb de onderstaande code:

$host = "localhost"; //put your host here

$user = "myuser"; //in general is root

$password = "mypassword"; //use your password here

$dbname = "mydatabase"; //your database


In mijn config, maar dan zit ik met dit probleem.

Ik heb di systeem in mijn unity3d spel, wat helemaal niks met mijn host zit verbonden.
Wat moet ik dan bij mijn host invullen? aangezien localhost geen database van het spel heeft.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
De host (het IP) die wél de database van het spel heeft.
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
dus voor mij is het

IP    46.21.172.139


welke ik bij site summary vond?

toevoeging op 10 april 2012, 16:34:44:
Nieuw probleem, met de volgende code.

Ik heb nu een compleet login script voor me unity game.
Alleen nu moet ik er voor zorgen dat hij scene 2 opent als hij correct is ingelogt.
Wie weet hoe ik dit kan doen?

private var formNick = ""; //this is the field where the player will put the name to login

private var formPassword = ""; //this is his password

var formText = ""; //this field is where the messages sent by PHP script will be in

 

var URL = "http://mywebsite/check_scores.php"; //change for your URL

var hash = "hashcode"; //change your secret code, and remember to change into the PHP file too

 

private var textrect = Rect (10, 150, 500, 500); //just make a GUI object rectangle

 

function OnGUI() {

    GUI.Label( Rect (10, 10, 80, 20), "Your nick:" ); //text with your nick

    GUI.Label( Rect (10, 30, 80, 20), "Your pass:" );

 

    formNick = GUI.TextField ( Rect (90, 10, 100, 20), formNick ); //here you will insert the new value to variable formNick

    formPassword = GUI.TextField ( Rect (90, 30, 100, 20), formPassword ); //same as above, but for password

 

    if ( GUI.Button ( Rect (10, 60, 100, 20) , "Try login" ) ){ //just a button

        Login();

    }

    GUI.TextArea( textrect, formText );

}

 

function Login() {

    var form = new WWWForm(); //here you create a new form connection

    form.AddField( "myform_hash", hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file

    form.AddField( "myform_nick", formNick );

    form.AddField( "myform_pass", formPassword );

    var w = WWW(URL, form); //here we create a var called w and we sync with our URL and the form

    yield w; //we wait for the form to check the PHP file, so our game dont just hang

    if (w.error != null) {

        print(w.error); //if there is an error, tell us

    } else {

        print("Test ok");

        formText = w.data; //here we return the data our PHP told us

        w.Dispose(); //clear our form in game

    }

 

    formNick = ""; //just clean our variables

    formPassword = "";

}


toevoeging op 10 april 2012, 16:35:29:
status check

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

[COLOR= #FF8000]// CONNECTIONS =========================================================[/COLOR]

[COLOR= #0000BB]$host[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"localhost"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//put your host here[/COLOR]

[COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"zabyeay50_game"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//in general is root[/COLOR]

[COLOR= #0000BB]$password[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"veN4l5uF"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//use your password here[/COLOR]

[COLOR= #0000BB]$dbname[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"zabyeay50_game"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]//your database[/COLOR]

[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$host[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$user[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$password[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Cant connect into database"[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$dbname[/COLOR][COLOR= #007700])[/COLOR]or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"Cant connect into database"[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #FF8000]// =============================================================================

// PROTECT AGAINST SQL INJECTION and CONVERT PASSWORD INTO MD5 formats[/COLOR]

[COLOR= #007700]function[/COLOR] anti_injection_login_senha[COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$formUse[/COLOR] [COLOR= #007700]=[/COLOR] true[COLOR= #007700])

{[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/(from|select|insert|delete|where|drop table|show tables|,||#|*|--|)/i"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$formUse[/COLOR] [COLOR= #007700]|| ![/COLOR][URL="http://www.php.net/get_magic_quotes_gpc"]get_magic_quotes_gpc[/URL][COLOR= #007700]())[/COLOR]

  [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/addslashes"]addslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

  [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/md5"]md5[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]));[/COLOR]

[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$sql[/COLOR][COLOR= #007700];

}[/COLOR]

[COLOR= #FF8000]// THIS ONE IS JUST FOR THE NICKNAME PROTECTION AGAINST SQL INJECTION[/COLOR]

[COLOR= #007700]function[/COLOR] anti_injection_login[COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$formUse[/COLOR] [COLOR= #007700]=[/COLOR] true[COLOR= #007700])

{[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/preg_replace"]preg_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/(from|select|insert|delete|where|drop table|show tables|,||#|*|--|)/i"[/COLOR][COLOR= #007700],[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/trim"]trim[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/strip_tags"]strip_tags[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$formUse[/COLOR] [COLOR= #007700]|| ![/COLOR][URL="http://www.php.net/get_magic_quotes_gpc"]get_magic_quotes_gpc[/URL][COLOR= #007700]())[/COLOR]

  [COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/addslashes"]addslashes[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sql[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/return"]return[/URL] [COLOR= #0000BB]$sql[/COLOR][COLOR= #007700];

}[/COLOR]

[COLOR= #FF8000]// =============================================================================[/COLOR]

[COLOR= #0000BB]$unityHash[/COLOR] [COLOR= #007700]=[/COLOR] anti_injection_login[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"myform_hash"[/COLOR][COLOR= #007700]]);[/COLOR]

[COLOR= #0000BB]$phpHash[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"dropje123"[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// same code in here as in your Unity game[/COLOR]

 

[COLOR= #0000BB]$nick[/COLOR] [COLOR= #007700]=[/COLOR] anti_injection_login[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"myform_nick"[/COLOR][COLOR= #007700]]);[/COLOR] [COLOR= #FF8000]//I use that function to protect against SQL injection[/COLOR]

[COLOR= #0000BB]$pass[/COLOR] [COLOR= #007700]=[/COLOR] anti_injection_login_senha[COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"myform_pass"[/COLOR][COLOR= #007700]]);[/COLOR]

[COLOR= #FF8000]/*

you can also use this:

$nick = $_POST["myform_nick"];

$pass = $_POST["myform_pass"];

*/[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][COLOR= #0000BB]$nick[/COLOR] [COLOR= #007700]|| ![/COLOR][COLOR= #0000BB]$pass[/COLOR][COLOR= #007700]) {[/COLOR]

    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Login or password cant be empty."[/COLOR][COLOR= #007700];

}[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]

    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$unityHash[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]$phpHash[/COLOR][COLOR= #007700]){[/COLOR]

        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"HASH code is diferent from your game, you infidel."[/COLOR][COLOR= #007700];

    }[/COLOR] [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]

        [COLOR= #0000BB]$SQL[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"SELECT * FROM scores WHERE name = "[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$nick[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]

        [COLOR= #0000BB]$result_id[/COLOR] [COLOR= #007700]= @[/COLOR][URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$SQL[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"DATABASE ERROR!"[/COLOR][COLOR= #007700]);[/COLOR]

        [COLOR= #0000BB]$total[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_id[/COLOR][COLOR= #007700]);[/COLOR]

        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$total[/COLOR][COLOR= #007700]) {[/COLOR]

            [COLOR= #0000BB]$datas[/COLOR] [COLOR= #007700]= @[/COLOR][URL="http://www.php.net/mysql_fetch_array"]mysql_fetch_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$result_id[/COLOR][COLOR= #007700]);[/COLOR]

            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/strcmp"]strcmp[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$pass[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$datas[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]"password"[/COLOR][COLOR= #007700]])) {[/COLOR]

                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"LOGADO - PASSWORD CORRECT"[/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]"Nick or password is wrong."[/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]"Data invalid - cant find name."[/COLOR][COLOR= #007700];

        }

    }

}[/COLOR]

[COLOR= #FF8000]// Close mySQL Connection[/COLOR]

[URL="http://www.php.net/mysql_close"]mysql_close[/URL][COLOR= #007700]();[/COLOR]

?>
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