Autor Beitrag
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 23.02.05 19:10 
Ich würde gerne ein kleines Spiel mit einer Online-Highscore versehen. Problem ist, dass ich keine Ahnung habe, wie ich mein Delphi "online bringe". Ich brauche da also ein bissel Starthilfe. Außerdem habe ich von PHP keinen Plan (aber da hätte ich jemanden, der diesen Teil übernehmen könnte).
Also: Wie sende ich ein paar kleine Daten (Name und Punktzahl) an ein PHP-Skript, und wie muss dieses Skript im groben aussehen, um diese Daten zu empfangen, zu sortieren und zu speichern? Und wie macht man dann daraus ne fertige HTML-Seite?
Hat jemand Anregungen, Tipps, Links, oder sogar was Code (sowohl PHP als auch Delphi)?
Danke!

_________________
We are, we were and will not be.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Do 24.02.05 14:44 
die daten kannst du mit der IdHTTP komponente verschicken welche die Daten per POST an eine php-seite übergibt.Suche bei Google PHP POST GET
in der php-seite musst du dann halt noch die übertragenen daten überprüfen.
ich würde dir empfehlen die daten zu verschlüsseln sonst ist dein system schneller geknackt als du auf 3 zählen kannst.
dann gibts nur noch highscores ala 9999999 ;-)
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 24.02.05 15:52 
dann müsste er auch sämtliche speicheradressen verschlüsseln um sowas komplett auszuschließen, oder halt so oft ändern, dass man sie nicht findet, aber es gibt immer
wege ...
ScorpionKing
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: Do 24.02.05 16:00 
ich hatte da mal eine komponente geschrieben, die mit einem php-skript "kommuniziert" hat!
weiß aber nicht mehr wo ich die habe, ich suche mal! :D

_________________
Aus dem Urlaub zurück!
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Do 24.02.05 16:12 
Ein simples PHP Script könnte zb. so aussehen:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
<?php
/*
MySQL-Table for User Score
CREATE TABLE `user_score` (
`ID` INT(10) DEFAULT '0' NOT NULL AUTO_INCREMENT PRIMARY KEY,
`NAME` VARCHAR(15) NOT NULL,
`SCORE` INT(10) NOT NULL,
`DATE` DATETIME NOT NULL
);

*/

$DBHOST = "localhost"; //DatenbankHost
$DBNAME = "DB123";  //DatenbankName
$DBUSER = "anonymus";  //DatenbankUser
$DBPASS = "geheim";  //DatenbankPasswort

$tbl_user_score = "user_score";  //MySQL TabellenName

$conn_id = mysql_connect($DBHOST, $DBUSER, $DBPASS); //MySQL-Verbindung herstellen
mysql_select_db($DB123, $conn_id);  //Datanbank auswählen

if((isset($_GET['data'])) || (!empty($_GET['data']))) { //wenn highscores.php?data=Alex#2323 gegeben ist dann...
  $post_vars = explode('#', $data); //Daten auslesen
  $name = $post_vars[0]; // In Array eintragen
  $score = $post_vars[1];
  mysql_query("INSERT INTO ".tbl_user_score." (NAME,SCORE,DATE) VALUES ('$name','$score','".strftime('%Y-%m-%d %H:%M:%S')."')"); //MySQL Query senden um in der DB zu speichern
}else { //wenn nicht highscores.php?data=Alex#2323 sondern nur highscores.php dann...
   $sql = "SELECT NAME, SCORE, DATE FROM ".table_user_score." ORDER BY SCORE DESC"; // aus der DB lesen
   $res = mysql_query($sql); // MySQL Query senden
   echo "<html><head><title>Highscores</title></head><body>" //Kopf der Tabelle (HTML teil)
       ."<table width='100%' border='0' cellspacing='3' cellpadding='3'>"
       ."<tr><td><b>Name</b></td>"
       ."<td><b>Score</b></td><td><b>Datum</b></td></tr>";
   while($Daten = mysql_fetch_row($res)){  // DAten auflisten/ausgeben
     echo "<tr>
             <td>".$Daten[0]."</td>
             <td>".$Daten[1]."</td>
             <td>".$Daten[3]."</td>
           </tr>";
   }
   echo "</table></body></html>";// Ende der/des Tabelle/HTML Teils
 }
//MySQL Verbindung schließen
if(is_resource($conn_id)) {
  mysql_close($conn_id);
} else {}
?>



hoffe ich habe keine fehler drinne :/ habs grad schnell ausm kopf geschrieben. das ganze geht natürlich auch mit *.txt dateien.

mfg matze

_________________
si tacuisses, philosophus mansisses.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Do 24.02.05 17:28 
ich würde das nicht über get lösen weil dann jedes kind die werte direkt in die adressleiste schreiben kann.
bei POST kannst du auch noch andere werte übergeben, z.b. eine errechnete prüfsumme über den highscore wert.
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Do 24.02.05 17:40 
retnyg hat folgendes geschrieben:
ich würde das nicht über get lösen weil dann jedes kind die werte direkt in die adressleiste schreiben kann.
bei POST kannst du auch noch andere werte übergeben, z.b. eine errechnete prüfsumme über den highscore wert.


Ich sagte ja "Es ist nur ein Simples Beispiel". ;)

mfg matze

//Edit: Das Beispiel lässt sich auch sehr leicht editieren, damit es mit POST geht :) und es soll ja nur in etwa eine struktur zeigen.

_________________
si tacuisses, philosophus mansisses.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 24.02.05 18:02 
aber ich glaube hier können nicht viele was damit anfangen, wer kann den schon php ? :wink:
ich glaube gausi wollte fertigen code haben, weil er bestimmt keine lust hat sich mit php rumzuschlagen (hätte ich auch net), dann braucht er auch noch die kommunikation (gabs da net ne indy komponente ?)
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Do 24.02.05 18:05 
hab Gausi schon gesagt, dass ich ihm das coden kann wenn er will und er hatte oben auch gesagt er hat einen der php kann :)

mfg matze.de

P.S.: Außerdem is PHP doch so schön einfach :]

_________________
si tacuisses, philosophus mansisses.
Gausi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 24.02.05 19:49 
Ok, danke erstmal für die Bemühungen. So langsam glaube ich, dass sich das doch realisieren lässt. 'Mein' PHP Experte (nicht matze.de, der andere) hat mal für erste Gehversuche ein Mini-Skript gebaut, und ich ahb n kleines Test-Prog geschrieben, und die Verbindung Delphi<->PHP scheint schonmal zu klappen. Jetzt muss nur noch die Datenbank her, und das richtige Skript, und das richitge Prog, und schon bin ich fertig mit den Nerven. :lol:

_________________
We are, we were and will not be.
NuCHiLL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 37

WXP
D7E
BeitragVerfasst: Fr 04.03.05 18:23 
@matze.de:
könntest du mir nen gefallen tun und den source oben funktionsfähig machen?
ich hock seit ner Stunde rum und krieg überhaupt nix gebacken. Wäre echt nett! :wink:

_________________
-I am what I am and I do what I can-
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Sa 05.03.05 09:46 
NuCHiLL hat folgendes geschrieben:
@matze.de:
könntest du mir nen gefallen tun und den source oben funktionsfähig machen?
ich hock seit ner Stunde rum und krieg überhaupt nix gebacken. Wäre echt nett! :wink:


Oben der Source is im grunde Funktionsfähig, aber er soll eigentlich nur ne denkhilfe sein.

mfg matze

_________________
si tacuisses, philosophus mansisses.
Gausi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 05.03.05 11:29 
So gets jetzt bei mir, hat der "TobiGott" geschrieben:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
// Highscore_add.php
<?PHP
require_once("config.inc.php");

if(isset($_POST['name'])){
    $tbl_highscore = $_POST['stufe'];
    mysql_query("INSERT INTO $tbl_highscore (name, gemeinde, score) VALUES ('$_POST[name]', '$_POST[gemeinde]','$_POST[score]')");
} //ende if
mysql_close();
?>

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
 //ShowHighscores.php
<?PHP
require_once("../highscore/config.inc.php");
if(isset($_GET['s'])){
    $bl_highscore  = "highscore_";
    $tbl_highscore .= $_GET['s'];  // ich habe bei mir verschiedene Tabellen für veschiedene Schwierigkeitstufen
}
else{
  $tbl_highscore  = "highscore_1";
  }
$sql = "SELECT name, gemeinde, score FROM ".$tbl_highscore." ORDER BY score DESC"; // aus der DB lesen
$res = mysql_query($sql);
echo "<table width='500' border='0' cellspacing='3' cellpadding='3'align='center'>"
."<tr><td width='40'><b>Platz</b></td><td width='150'><b>Name</b></td><td width='150'><b>Gemeinde</b></td><td width='60'><b>Score</b></td></tr>";
$i = 1;
while($daten = mysql_fetch_row($res)){  // Daten auflisten/ausgeben
  echo "<tr><td width='40'>".$i."</td><td width='150'>".$daten[0]."</td><td width='150'>".$daten[1]."</td><td width='60'>".$daten[2]."</td></tr>";
  $i++;
}
echo "</table>";// Ende der Tabelle
mysql_close();
?>

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
 //config.php
<?php

//Datenbank Zugangsdaten

$mysql['hostname'] = "Die";    // z.B. mysqlhost.de
$mysql['username'] = "Zugangsdaten";// MySQL Datenbank Benutzername
$mysql['password'] = "poste ich ";  // MySQL Datenbank Passwort
$mysql['database'] = "hier nicht";  // Name der MySQL Datenbank

//Datenbank verbindung herstellen

@mysql_pconnect($mysql['hostname'], $mysql['username'], $mysql['password']) or die ("<p>Es konnte keine Verbindung zu der Datenbank erstellt werden. Bitte versuchen Sie es später nochmal.");
@mysql_select_db($mysql['database']);
?>

Übergabe der Daten mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
t:=TStringlist.Create;
t.Add('stufe=highscore_'+ inttostr(Auswahl));
t.Add('name='+NameEDIT.Text);
t.Add('gemeinde='+GemeindeEDIT.Text);
if Punkte<1 then Punkte:=1;
t.Add('score='+inttostr(Punkte));
try
     form1.idhttp1.Post({Ich poste hier auch nicht die Adresse...},t);
except end;

Das war meine erste Online-Zusammenarbeit mit jemand anderem, und sie hat sehr gut geklappt, wenn man sich erstmal drauf geeinigt hatte, was man genau übergibt...

_________________
We are, we were and will not be.
NuCHiLL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 37

WXP
D7E
BeitragVerfasst: Sa 05.03.05 12:29 
thx...

_________________
-I am what I am and I do what I can-
zero_cool1986
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 95

MS DOS ;)
D6
BeitragVerfasst: Sa 31.10.09 08:01 
Hi,

Ich habe keine Ahnung von php und mysql,
kann mir zufällig jemand noch den Quellcode zum erstellen der Datenbank posten?

LG
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 31.10.09 09:26 
Das kann man zwar theoretisch auch per Quelltext erledigen, aber normalerweise nehme ich dafür phpMyAdmin und lege die Datenbank und die Struktur einfach manuell an.