Profiel pagina / guestbook. HELP!

Status
Niet open voor verdere reacties.

jurre35

Gebruiker
Lid geworden
30 dec 2006
Berichten
147
Hallo allemaal,

al een tijdje ben ik samen met iemand bezig om een profiel pagina te maken voor rally coureurs.


tijdelijke link is:
http://www.rally-web.nl/Guestbook/guestbook.php

Tijdelijk ww is:
test123

De bedoeling is het volgende:

Wanneer mensen de pagina bezoeken kunnen ze allerlei info vinden over verschillende rally coureurs. Zoals, welke auto, welke co drivers, sinds wanneer etc.

Elke coureur die er wat aan heeft kan een profiel aanmaken op de pagina.

wanneer men de gegevens heeft ingevuld en verstuur verschijnen ze op de pagina erbij.
Ik heb de files in een bijlage gestopt.
Waar het op gaat is het PHP file.

Maar hij werkt niet meer zoals eerst. Ook heb ik het orginele bestand geplaatst die werkt nagenoeg wel.

Wat niet werkt is het volgende:
Admin kan inloggen maar heeft geen mogelijkheid om berichten te verwijderen.
Als men naar de pagina gaat verschijnen er geen berichten, dit zou wel moeten. Alleen wanneer je een nieuw profiel aanmaakt verschijnen de eerder geplaatste berichten.

Kan iemand mij op weg helpen met wat fixjes??

Ik kan de php hier neer zetten, weet alleen niet of dit handig is?
 
Zou handiger zijn om te zien wat je aan code hebt, en aan databasetabellen/ velden.
 
Sorry, had de PHP code moeten plaatsen als bijlage.

Maar bij deze een rar file met daarin de files die ik gebruik

Ik hoop dat je mij kunt helpen!

Dankje!

groeten
jurre
 

Bijlagen

verwijderen van berichten en veranderingen tmp bestand

Hallo mensen,

fijn pasen nog!

ik ben een tijdje nu bezig om een profiel pagina voor rally coureurs.
de pagina is nu in een begin fase. hij werkt alleen kan ik geen berichten verwijderen.
In de php staat in regel 122 het script waarmee je kunt inloggen en vervolgens files kunt verwijderen. je mag rustig een kijkje nemen op hoe hij er nu uit ziet.
http://www.rally-web.nl/Guestbook/guestbook.php
ww: test123

Zou iemand mij kunnen helpen??

PHP:
<?php
    # You must set this correctly to a
    # location where you are allowed to
    # create a file! 
    $guestbook = 'guestbook.dat';
    # Choose your own password
    $adminPassword = 'test123';
        # Hide harmless warning messages that confuse users.
        # If you have problems and you don't know why,
        # comment this line out for a while to get more
        # information from PHP
        error_reporting (E_ALL ^ (E_NOTICE | E_WARNING));
 
    # No changes required below here
 
    $admin = 0;
    if ($adminPassword == 'CHANGEME') {
        die("You need to change \$adminPassword first.");
    }
 
    # Undo magic quotes - useless for flat files,
    # and inadequate and therefore dangerous for databases. See:
    # http://www.boutell.com/newfaq/creating/magicquotes.html
    
    function stripslashes_nested($v)
    {
        if (is_array($v)) {
            return array_map('stripslashes_nested', $v);
        } else {
            return stripslashes($v);
        }
    }
 
    if (get_magic_quotes_gpc()) {
        $_GET = stripslashes_nested($_GET);
        $_POST = stripslashes_nested($_POST);
    }
?>
<html>
<head>
<title>Rally drivers profile page</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style3 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    font-weight: bold;
}
-->
</style>
</head>
<body>
<h1 align="center" class="style1">Rally drivers profile page</h1>
<div align="center">
<?php
    $password = "";
    if ($_POST['password'] == $adminPassword) {
        $admin = 1;
        $password = $adminPassword;
    } else if (strlen($_POST['password'])) {
        echo("<h2>Login Failed (Bad Password)</h2>\n");
    }
?>  
<table width="600" border="1" cellpadding="3" cellspacing="3">
<tr>
 
        <th>
            <span class="style1">Name driver</span>
        </th>
        <th>
            <span class="style1">Since</span>
        </th>
        <th>
            <span class="style1">Country</span>
        </th>
        <th>
            <span class="style1">Co drivers</span>
        </th>
        <th>
            <span class="style1">Latest rally car</span>
        </th>
        
<?php
    if ($admin) {
        echo "<th>Controls</th>";
    }
?>
</tr>
<?php
    if ($_POST['submit']) {
        $file = fopen($guestbook, "a");
        if (!$file) {
            die("Can't write to guestbook file");
        }
        $date = date('F j, Y, g:i a');
        $id = rand();
        
        $driverName = $_POST['driverName'];
        $since = $_POST['since'];
        $country = $_POST['country'];
        $coDrivers = $_POST['coDrivers']; 
        $latestRallyCar = $_POST['latestRallyCar']; 
        
        $driverName = clean($driverName, 40);
        $since = clean($since, 40);
        $country = clean($country, 40);
        $coDrivers = clean($coDrivers, 40);
        $latestRallyCar = clean($latestRallyCar, 40);
        
        fwrite($file, 
            "$date\t$driverName\t$since\t$country\t$coDrivers\t$latestRallyCar\t$id\n");
        fclose($file);  
    }
    $file = fopen($guestbook, 'r');
    $tfile = null;
    $delete = 0;
    $deleteId = '';
    if ($admin && $_POST['delete']) {
        $delete = 1;
        $deleteId = $_POST['id'];
        $tfile = @fopen("$guestbook.tmp", 'w');
        if (!$tfile) {
            die("Can't create temporary file for delete operation");
        }
    }
    if ($file) {
        while (!feof($file)) {
            $line = fgets($file);
            $line = trim($line);
            list ($date, $driverName, $since, $country, $coDrivers, $latestRallyCar, $id) = 
                split("\t", $line, 7);
            if (!strlen($date)) {
                break;
            }
            if (!strlen($id)) {
                // Support my old version
                $id = $date;
            }   
            if ($delete) {
                if ($id == $deleteId) {
                    continue;
                } else {
                    fwrite($tfile, 
                        "$date\t$driverName\t$since\t$country\t$coDrivers\t$latestRallyCar\t$id\n");
                }
            }
            echo "<tr>";
            echo "<td>  $driverName     </td>";
            echo "<td>  $since          </td>";
            echo "<td>  $country        </td>"; 
            echo "<td>  $coDrivers      </td>";
            echo "<td>  $latestRallyCar </td>";
            
            if ($admin) {
                echo "<td>";
                echo "<form action=\"guestbook.php\" " .
                    "method=\"POST\">";
                passwordField();
                hiddenField('id', $id);
                echo "<input type=\"submit\" " .
                    "value=\"Delete\" " .
                    "name=\"delete\">";
                echo "</form>";
                echo "</td>";
            }
            echo "</tr>\n";
        }
        fclose($file);
        if ($delete) {
            fclose($tfile);
            unlink($guestbook);
            rename("$guestbook.tmp", $guestbook);
        }   
    }
    function clean($name, $max) {
        # Turn tabs and CRs into spaces so they can't 
        # fake other fields or extra entries
        $name = ereg_replace("[[:space:]]", ' ', $name);
        # Escape < > and and & so they 
        # can't mess withour HTML markup
        $name = ereg_replace('&', '&amp;', $name);
        $name = ereg_replace('<', '&lt;', $name);
        $name = ereg_replace('>', '&gt;', $name);
        # Don't allow excessively long entries
        $name = substr($name, 0, $max);
        # Undo PHP's "magic quotes" feature, which has
        # inserted a \ in front of any " characters.
        # We undo this because we're using a file, not a
        # database, so we don't want " escaped. Those
        # using databases should do the opposite:
        # call addslashes if get_magic_quotes_gpc()
        # returns false.
        return $name;
    }
    function passwordField() {
        global $admin;
        global $password;
        if (!$admin) {
            return;
        }
        hiddenField('password', $password);
    }
    function hiddenField($name, $value) {
        echo "<input type=\"hidden\" " .
            "name=\"$name\" value=\"$value\">";
    }
?>
</table>
<?php
    if (!$admin) {
?>
<form action="guestbook.php" method="POST">
<span class="style3">Admin Login</span>
<br>
<input type="password" name="password">
<input type="submit" name="login" value="Log In">
</form>
<?php
    }
?>
<form action="guestbook.php" method="POST">
<table width="600" border="0" cellpadding="5" cellspacing="5">
<tr>
<th>Name driver</th><td><input id="driverName" name="driverName" maxlength="40"></td>
</tr>
<tr>
<th>Since</th><td><input id="since" name="since" maxlength="40"></td>
</tr>
<tr>
<th>Country</th><td><input id="country" name="country" maxlength="40"></td>
</tr>
<tr>
<th>Co drivers</th><td><input id="coDrivers" name="coDrivers" maxlength="40"></td>
</tr>
<tr>
<th>Latest rally car</th><td><input id="latestRallyCar" name="latestRallyCar" maxlength="40"></td>
</tr>
<tr>
<th colspan="2">
<input type="submit" name="submit" value="Voeg profiel toe / Add profile">
</th>
</tr>
</table>
<?php
    passwordField();
?>
</form>
</div>
</body>
</html>
 
Zou toch elke zelfrespecterende developer moeten weten
$is variable dus ga die niet als bestandsnaam gebruiken om je van alle lolleheid te beschermentoch fout te snel willen zijn sorry daarvoor
wat hetbeurt er in uw geval de variabel bestaat niet dus zal deze leeg zijn bijgevolg krijg je mogelijks op je server een warreboel van bestanden zonder naam of die effectief bestaan zal zelf niet niet uitproberen maar php kennende zal het opgeslaan zijn onder ander namen maar sowat (velen kijken er snel over maar het is een zeer grove fout waar de developer bij mijn oordeel niet langer zou mogen programmeren)
 
Laatst bewerkt:
Zou toch elke zelfrespecterende developer moeten weten
$is variable dus ga die niet als bestandsnaam gebruiken om je van alle lolleheid te beschermen
wat hetbeurt er in uw geval de variabel bestaat niet dus zal deze leeg zijn bijgevolg krijg je mogelijks op je server een warreboel van bestanden zonder naam of die effectief bestaan zal zelf niet niet uitproberen maar php kennende zal het opgeslaan zijn onder ander namen maar sowat (velen kijken er snel over maar het is een zeer grove fout waar de developer bij mijn oordeel niet langer zou mogen programmeren)
Je hebt regel 5 ook gezien?
 
Ik heb twee berichten over hetzelfde van je samengevoegd; volgende keer graag gewoon alles in één topic houden :)
 
Zou toch elke zelfrespecterende developer moeten weten
$is variable dus ga die niet als bestandsnaam gebruiken om je van alle lolleheid te beschermen
wat hetbeurt er in uw geval de variabel bestaat niet dus zal deze leeg zijn bijgevolg krijg je mogelijks op je server een warreboel van bestanden zonder naam of die effectief bestaan zal zelf niet niet uitproberen maar php kennende zal het opgeslaan zijn onder ander namen maar sowat (velen kijken er snel over maar het is een zeer grove fout waar de developer bij mijn oordeel niet langer zou mogen programmeren)

hallo kenikavanbis, bedankt voor je bericht! waardeer zeker je hulp.
Ik ben niet echt een devlp te noemen, ik ben niet echt op het gebied van scripten en php. wel werk ik veel aan website.
Zou jij misschien kunnen vertellen wat ik aan mijn script moet veranderen om een veilige en goed werkende profiel pagina te krijgen?

bedankt!
 
Lijn 122 173 vermeld
PHP:
       $tfile = @fopen("$guestbook.tmp", 'w');
dus variabel met naam
$guestbook.tmp = null;dit is een fout van mij er komt wel degelijk "guestbook.dat.tmp"
dus wat op regel vijf ook staat maakt niet uit.


merk op dat het een mooi gescheven is en je geen meerder talen ondersteund of niet snel andere talen kan ondersteunen want dan ga je snel een coppytje pakken en das nu net wat nadien niet zou mogen gebeuren maar sowat
 
Laatst bewerkt:
Door je vreemde taalgebruik begrijp ik niet helemaal wat je bedoelt, maar ik zal toch even reageren:

php zal variabelen tussen dubbele quotes altijd parsen. In je reply van 12:03 viel je de topicstarter aan in verband met een mogelijk veiligheidslek door het gebruik van een variabele voor de bestandsnaam. Echter is de variabele $guestbook in dit geval een vaste waarde die in regel 5 al wordt opgegeven en later niet wordt aangepast. Kortom, die aanval was niet nodig.
 
dan kan ik enkel aanraden de @ weg te halen zodat er meer errors komen maar zal er dan toch terug moeten staan nadien .


'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
 
Door je vreemde taalgebruik begrijp ik niet helemaal wat je bedoelt, maar ik zal toch even reageren:

php zal variabelen tussen dubbele quotes altijd parsen. In je reply van 12:03 viel je de topicstarter aan in verband met een mogelijk veiligheidslek door het gebruik van een variabele voor de bestandsnaam. Echter is de variabele $guestbook in dit geval een vaste waarde die in regel 5 al wordt opgegeven en later niet wordt aangepast. Kortom, die aanval was niet nodig.

kenikavanbis inderdaad was jou verhaal mij ook niet echt duidelijk.
heel erg bedankt voor je bericht maar wordt er eerlijk gezegt niet heel veel wijzer van.

kenikavanbis en flitsflitsflits zouden jullie beide de php script willen aanpassen en willen posten? die script kan ik dan uploaden naar de site en checken of hij goed werkt.

aan de hand van jullie post kunnen we bekijken of er nog fouten in zitten en samen deze proberen aan te passen.

bedankt!!!

groeten
jurre
 
dan kan ik enkel aanraden de @ weg te halen zodat er meer errors komen maar zal er dan toch terug moeten staan nadien .


'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

kenikavanbis, bedankt voor je bericht.

zou jij misschien heel iets duidelijker willen zijn zodat ik het begrijp? of zou je zo vriendelijk willen zijn om de script die ik eerder poste aan te passen en die te willen posten?

thanks!!
 
dit wordt het maar let op

PHP:
Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php  on line 163

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 166

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 167

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 168

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 163

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 166

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 167

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 168

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 163

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 166

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 167

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 168

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 163

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 166

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 167

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 168

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 163

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 166

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 167

Deprecated: Function ereg_replace() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 168

Deprecated: Function split() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 120

Deprecated: Function split() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 120

Deprecated: Function split() is deprecated in E:\_A_servers\xampp\htdocs\guestbooktest.php on line 120

PHP:
<?php
    # You must set this correctly to a
    # location where you are allowed to
    # create a file! 
    $guestbook = 'guestbook.dat';
    # Choose your own password
    $adminPassword = 'test123';
        # Hide harmless warning messages that confuse users.
        # If you have problems and you don't know why,
        # comment this line out for a while to get more
        # information from PHP
        error_reporting (E_ALL ^ (E_NOTICE | E_WARNING));//!!!security!!!
     # No changes required below here
     $admin = 0;
    if ($adminPassword == 'CHANGEME') {
        die("You need to change \$adminPassword first.");
    }
    # Undo magic quotes - useless for flat files,
    # and inadequate and therefore dangerous for databases. See:
    # http://www.boutell.com/newfaq/creating/magicquotes.html
    function stripslashes_nested($v){
        if (is_array($v)) {
            return array_map('stripslashes_nested', $v);
        } else {
            return stripslashes($v);
        }
    }
    if (get_magic_quotes_gpc()){
        $_GET = stripslashes_nested($_GET);
        $_POST = stripslashes_nested($_POST);
    }
?>
<html>
<head>
<title>Rally drivers profile page</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style3 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    font-weight: bold;
}
-->
</style>
</head>
<body>
<h1 align="center" class="style1">Rally drivers profile page</h1>
<div align="center">
<?php
    $password = "";
    if ($_POST['password'] == $adminPassword) {
        $admin = 1;
        $password = $adminPassword;
    } else if (strlen($_POST['password'])) {
        echo("<h2>Login Failed (Bad Password)</h2>\n");
    }
?>  
<table width="600" border="1" cellpadding="3" cellspacing="3">
<tr>
        <th>
            <span class="style1">Name driver</span>
        </th>
        <th>
            <span class="style1">Since</span>
        </th>
        <th>
            <span class="style1">Country</span>
        </th>
        <th>
            <span class="style1">Co drivers</span>
        </th>
        <th>
            <span class="style1">Latest rally car</span>
        </th>      
<?php
    if ($admin) {
        echo "<th>Controls</th>";
    }
?>
</tr>
<?php
    if ($_POST['submit']) {
        $file = fopen($guestbook, "a");
        if (!$file) {
            die("Can't write to guestbook file");
        }
        $date = date('F j, Y, g:i a');
        $id = rand();
        $driverName = $_POST['driverName'];
        $since = $_POST['since'];
        $country = $_POST['country'];
        $coDrivers = $_POST['coDrivers']; 
        $latestRallyCar = $_POST['latestRallyCar']; 
        $driverName = clean($driverName, 40);
        $since = clean($since, 40);
        $country = clean($country, 40);
        $coDrivers = clean($coDrivers, 40);
        $latestRallyCar = clean($latestRallyCar, 40);
        fwrite($file, "$date\t$driverName\t$since\t$country\t$coDrivers\t$latestRallyCar\t$id\n");
        fclose($file);  
    }
    $file = fopen($guestbook, 'r');
    $tfile = null;
    $delete = 0;
    $deleteId = '';
    if ($admin && $_POST['delete']) {
        $delete = 1;
        $deleteId = $_POST['id'];
        $tfile = @fopen($guestbook.".tmp", 'w');
        if (!$tfile) {
            die("Can't create temporary file for delete operation");
        }
    }
    if ($file) {
        while (!feof($file)) {
            $line = fgets($file);
            $line = trim($line);
            list ($date, $driverName, $since, $country, $coDrivers, $latestRallyCar, $id) = 
                split("\t", $line, 7);
            if (!strlen($date)) {
                break;
            }
            if (!strlen($id)) {
                // Support my old version
                $id = $date;
            }   
            if ($delete) {
                if ($id == $deleteId) {
                    continue;
                } else {
                    fwrite($tfile, "$date\t$driverName\t$since\t$country\t$coDrivers\t$latestRallyCar\t$id\n");
                }
            }
            echo "<tr>";
            echo "<td>  $driverName     </td>";
            echo "<td>  $since          </td>";
            echo "<td>  $country        </td>"; 
            echo "<td>  $coDrivers      </td>";
            echo "<td>  $latestRallyCar </td>";
            
            if ($admin) {
                echo "<td>";
                echo "<form action=\"guestbook.php\" " . "method=\"POST\">";
                passwordField();
                hiddenField('id', $id);
                echo "<input type=\"submit\" value=\"Delete\" name=\"delete\">";
                echo "</form>";
                echo "</td>";
            }
            echo "</tr>\n";
        }
        fclose($file);
        if ($delete) {
            fclose($tfile);
            unlink($guestbook);
            rename($guestbook.".tmp", $guestbook);
        }   
    }
    function clean($name, $max) {
        # Turn tabs and CRs into spaces so they can't 
        # fake other fields or extra entries
        $name = ereg_replace("[[:space:]]", ' ', $name);
        # Escape < > and and & so they 
        # can't mess withour HTML markup
        $name = ereg_replace('&', '&amp;', $name);
        $name = ereg_replace('<', '&lt;', $name);
        $name = ereg_replace('>', '&gt;', $name);
        # Don't allow excessively long entries
        $name = substr($name, 0, $max);
        # Undo PHP's "magic quotes" feature, which has
        # inserted a \ in front of any " characters.
        # We undo this because we're using a file, not a
        # database, so we don't want " escaped. Those
        # using databases should do the opposite:
        # call addslashes if get_magic_quotes_gpc()
        # returns false.
        return $name;
    }
    function passwordField() {
        global $admin;
        global $password;
        if (!$admin) {
            return;
        }
        hiddenField('password', $password);
    }
    function hiddenField($name, $value) {
        echo '<input type="hidden" name="'.$name.'" value="$value">';
    }
?>
</table>
<?php
    if (!$admin) {
		?>
		<form action="<?php print$_SERVER["PHP_SELF"] ?>" method="POST">
		<span class="style3">Admin Login</span>
		<br>
		<input type="password" name="password">
		<input type="submit" name="login" value="Log In">
		</form>
		<?php
    }
?>
<form action="<?php print$_SERVER["PHP_SELF"] ?>" method="POST">
<table width="600" border="0" cellpadding="5" cellspacing="5">
<tr>
<th>Name driver</th><td><input id="driverName" name="driverName" maxlength="40"></td>
</tr>
<tr>
<th>Since</th><td><input id="since" name="since" maxlength="40"></td>
</tr>
<tr>
<th>Country</th><td><input id="country" name="country" maxlength="40"></td>
</tr>
<tr>
<th>Co drivers</th><td><input id="coDrivers" name="coDrivers" maxlength="40"></td>
</tr>
<tr>
<th>Latest rally car</th><td><input id="latestRallyCar" name="latestRallyCar" maxlength="40"></td>
</tr>
<tr>
<th colspan="2">
<input type="submit" name="submit" value="Voeg profiel toe / Add profile">
</th>
</tr>
</table>
<?php
    passwordField();
?>
</form>
</div>
</body>
</html>
 
kenikavanbis, sorry man hij werkt niet.
als ik inlog en ik klik op delete krijg ik het volgende:
"Login Failed (Bad Password)"

zit er ergens nog een probleem in?
 
belangerijkste verandering was op 144 PHP_SELF

bij mij deed ie het maar hij vroeg wel het paswoord te wijzigen ?!? als ik dit deed deed hij het ook niet maar als ik weigerde deed he het wel

maar het verwijderen gebeurt niet maar ik ben er van overtuigt dat je dat wel vindt
PHP:
<?php
    # You must set this correctly to a
    # location where you are allowed to
    # create a file! 
    $guestbook = 'guestbook.dat';
    # Choose your own password
    $adminPassword = 'test123';
        # Hide harmless warning messages that confuse users.
        # If you have problems and you don't know why,
        # comment this line out for a while to get more
        # information from PHP
        error_reporting (E_ALL ^ (E_NOTICE | E_WARNING));//!!!security!!!
     # No changes required below here
     $admin = 0;
    if ($adminPassword == 'CHANGEME') {
        die("You need to change \$adminPassword first.");
    }
    # Undo magic quotes - useless for flat files,
    # and inadequate and therefore dangerous for databases. See:
    # http://www.boutell.com/newfaq/creating/magicquotes.html
    function stripslashes_nested($v){
        if (is_array($v)) {
            return array_map('stripslashes_nested', $v);
        } else {
            return stripslashes($v);
        }
    }
    if (get_magic_quotes_gpc()){
        $_GET = stripslashes_nested($_GET);
        $_POST = stripslashes_nested($_POST);
    }
?>
<html>
<head>
<title>Rally drivers profile page</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style3 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    font-weight: bold;
}
-->
</style>
</head>
<body>
<h1 align="center" class="style1">Rally drivers profile page</h1>
<div align="center">
<?php
    $password = "";
    if ($_POST['password'] == $adminPassword) {
        $admin = 1;
        $password = $adminPassword;
    } else if (strlen($_POST['password'])) {
        echo("<h2>Login Failed (Bad Password)</h2>\n");
    }
?>  
<table width="600" border="1" cellpadding="3" cellspacing="3">
<tr>
        <th>
            <span class="style1">Name driver</span>
        </th>
        <th>
            <span class="style1">Since</span>
        </th>
        <th>
            <span class="style1">Country</span>
        </th>
        <th>
            <span class="style1">Co drivers</span>
        </th>
        <th>
            <span class="style1">Latest rally car</span>
        </th>      
<?php
    if ($admin) {
        echo "<th>Controls</th>";
    }
?>
</tr>
<?php
    if ($_POST['submit']) {
        $file = fopen($guestbook, "a");
        if (!$file) {
            die("Can't write to guestbook file");
        }
        $date = date('F j, Y, g:i a');
        $id = rand();
        $driverName = $_POST['driverName'];
        $since = $_POST['since'];
        $country = $_POST['country'];
        $coDrivers = $_POST['coDrivers']; 
        $latestRallyCar = $_POST['latestRallyCar']; 
        $driverName = clean($driverName, 40);
        $since = clean($since, 40);
        $country = clean($country, 40);
        $coDrivers = clean($coDrivers, 40);
        $latestRallyCar = clean($latestRallyCar, 40);
        fwrite($file, "$date\t$driverName\t$since\t$country\t$coDrivers\t$latestRallyCar\t$id\n");
        fclose($file);  
    }
    $file = fopen($guestbook, 'r');
    $tfile = null;
    $delete = 0;
    $deleteId = '';
    if ($admin && $_POST['delete']) {
        $delete = 1;
        $deleteId = $_POST['id'];
        $tfile = @fopen($guestbook.".tmp", 'w');
        if (!$tfile) {
            die("Can't create temporary file for delete operation");
        }
    }
    if ($file) {
        while (!feof($file)) {
            $line = fgets($file);
            $line = trim($line);
            list ($date, $driverName, $since, $country, $coDrivers, $latestRallyCar, $id) = 
                split("\t", $line, 7);
            if (!strlen($date)) {
                break;
            }
            if (!strlen($id)) {
                // Support my old version
                $id = $date;
            }   
            if ($delete) {
                if ($id == $deleteId) {
                    continue;
                } else {
                    fwrite($tfile, "$date\t$driverName\t$since\t$country\t$coDrivers\t$latestRallyCar\t$id\n");
                }
            }
            echo "<tr>";
            echo "<td>  $driverName     </td>";
            echo "<td>  $since          </td>";
            echo "<td>  $country        </td>"; 
            echo "<td>  $coDrivers      </td>";
            echo "<td>  $latestRallyCar </td>";
            
            if ($admin) {
                echo "<td>";
                echo '<form action="'.$_SERVER["PHP_SELF"].'"method=\"POST\">';
                passwordField();
                hiddenField('id', $id);
                echo "<input type=\"submit\" value=\"Delete\" name=\"delete\">";
                echo "</form>";
                echo "</td>";
            }
            echo "</tr>\n";
        }
        fclose($file);
        if ($delete) {
            fclose($tfile);
            unlink($guestbook);
            rename($guestbook.".tmp", $guestbook);
        }   
    }
    function clean($name, $max) {
        # Turn tabs and CRs into spaces so they can't 
        # fake other fields or extra entries
        $name = ereg_replace("[[:space:]]", ' ', $name);
        # Escape < > and and & so they 
        # can't mess withour HTML markup
        $name = ereg_replace('&', '&amp;', $name);
        $name = ereg_replace('<', '&lt;', $name);
        $name = ereg_replace('>', '&gt;', $name);
        # Don't allow excessively long entries
        $name = substr($name, 0, $max);
        # Undo PHP's "magic quotes" feature, which has
        # inserted a \ in front of any " characters.
        # We undo this because we're using a file, not a
        # database, so we don't want " escaped. Those
        # using databases should do the opposite:
        # call addslashes if get_magic_quotes_gpc()
        # returns false.
        return $name;
    }
    function passwordField() {
        global $admin;
        global $password;
        if (!$admin) {
            return;
        }
        hiddenField('password', $password);
    }
    function hiddenField($name, $value) {
        echo '<input type="hidden" name="'.$name.'" value="$value">';
    }
?>
</table>
<?php
    if (!$admin) {
		?>
		<form action="<?php print$_SERVER["PHP_SELF"] ?>" method="POST">
		<span class="style3">Admin Login</span>
		<br>
		<input type="password" name="password">
		<input type="submit" name="login" value="Log In">
		</form>
		<?php
    }
?>
<form action="<?php print$_SERVER["PHP_SELF"] ?>" method="POST">
<table width="600" border="0" cellpadding="5" cellspacing="5">
<tr>
<th>Name driver</th><td><input id="driverName" name="driverName" maxlength="40"></td>
</tr>
<tr>
<th>Since</th><td><input id="since" name="since" maxlength="40"></td>
</tr>
<tr>
<th>Country</th><td><input id="country" name="country" maxlength="40"></td>
</tr>
<tr>
<th>Co drivers</th><td><input id="coDrivers" name="coDrivers" maxlength="40"></td>
</tr>
<tr>
<th>Latest rally car</th><td><input id="latestRallyCar" name="latestRallyCar" maxlength="40"></td>
</tr>
<tr>
<th colspan="2">
<input type="submit" name="submit" value="Voeg profiel toe / Add profile">
</th>
</tr>
</table>
<?php
    passwordField();
?>
</form>
</div>
</body>
</html>
 
bedankt voor je bericht,

ik heb echt geen idee waar het aan ligt hoor.
heb al zitten kijken maar kan de fout niet vinden.

hij verwijderd de berichten niet.

heb alle rechten in die map goed ingesteld, toch weigert hij daadwerkelijk om de berichten
uit de .dat te halen.

iemand ideeen??
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan