Toon posts:

[PHP] Kleine vraag over includen

Pagina: 1
Acties:
  • 126 views sinds 30-01-2008
  • Reageer

Verwijderd

Topicstarter
Hoi,

Ik heb een kleine vraag over includen.
Ik heb mijn index.php in de root staan.

Vervolgens roep ik statistics.php aan met:
code:
1
index.php?action=statistics/statistics

Het bestand statistics.php staat echter niet in de root maar in de map statistics, vandaar dat ik het zo aanroep.

Het bestand statistics.php include een .dat bestand dat in dezelfde map staat.

Alleen als ik nu de pagina wil bekijken, dan krijg ik dit:
code:
1
Warning: file("statistics.dat") - No such file or directory

Weet iemand hoe ik dit oplos? :?

Verwijderd

probeer eens in statics.php

statistics/statistics.dat aan te roepen inplaats van alleen statics.dat

Verwijderd

Topicstarter
Ja, dat dacht ik ook maar dan include ie helemaal niks.
Mijn include script is trouwens:
code:
1
2
3
4
5
6
7
8
9
10
11
<?php
if($action == "") {
include("$DOCUMENT_ROOT/news.php");
}
else {
if(file_exists("$action.php")) {
include("$DOCUMENT_ROOT/$action.php");
}
  
}
?>

Ik begin nu te twijfelen of het niet daar aan ligt, en dan vooral aan die $DOCUMENT_ROOT?

  • WouZz
  • Registratie: Mei 2000
  • Niet online

WouZz

Elvis is alive!

Je fout zit in statistics.php, niet in je index.php.. Probeer eens te includen met
PHP:
1
<?include(dirname(__FILE__).'/statistics.dat');?>

On track


Verwijderd

Topicstarter
Shit sorry, verkeerd woord gebruikt, hij include niet maar doet dit in statistics.php:
code:
1
$Bestand = "statistics/statistics.dat";

Maakt dat iets uit voor de oplossing die jij gaf net?

Verwijderd

Ik begin nu te twijfelen of het niet daar aan ligt, en dan vooral aan die $DOCUMENT_ROOT?
Dit kwam ik op php.net tegen:
... I had problems at home where I run Win2k, IIS 5 & PHP4.0.5. I was
surprised to find out that IIS doesn't set $DOCUMENT_ROOT! The following
workaround achieves pleasant results:
PHP:
1
<?  if ( strlen($DOCUMENT_ROOT) == 0)     $DOCUMENT_ROOT = 'F:/MyWebs/annwn';  require_once $DOCUMENT_ROOT . '/inc/TTextField.class.php4');?>

If $DOCUMENT_ROOT is not set I'll set it to the physical path to my site
on the server, otherwise (e.g. when published) I leave it alone.
[edit] typo, layout

Verwijderd

Waar het op neer komt is dat 'statistics.dat' op dezelfde manier opgevraagd moet worden als 'statistics.php', omdat hij letterlijk allemaal vaniut index.php wordt opgevraagd.

Verwijderd

Topicstarter
En nog ben ik er niet uit. :P

Verwijderd

Ik snap nu niet helemaal meer hoe je script nu in elkaar steekt, maar voor zover ik weet wordt 'statistics.php' opgevraagd door 'index.php' en 'statistics.dat' weer door 'statistics.php' toch? In dat geval zal het op de volgende manier in elkaar moeten zitten.
code:
1
2
3
4
5
index.php:
include("statistics/statistics.php");

statistics.php:
include("statistics/statistics.dat");

Als dit niet is wat je eerder hebt aangegeven formulier het dan ajb even opnieuw zodat we je allemaal kunnen helpen. En verder raad ik je aan om variabelen als '$DOCUMENT_ROOT' zo min mogelijk te gebruiken.

Verwijderd

Op woensdag 08 mei 2002 00:56 schreef int het volgende:
En verder raad ik je af om variabelen als '$DOCUMENT_ROOT' zomin mogelijk te gebruiken.
Hmmm.. dubbele ontkenning (?)

Ik neem aan dat je bedoeld dat je die zo min mogelijk moet gebruiken...

Verwijderd

Op woensdag 08 mei 2002 00:58 schreef delighteddennis het volgende:

[..]

Hmmm.. dubbele ontkenning (?)

Ik neem aan dat je bedoeld dat je die zo min mogelijk moet gebruiken...
Klopt :).

Verwijderd

Topicstarter
Hmm, ik gebruik $DOCUMENT_ROOT juist als een soort beveiliging, zodat niet al mijn bronnen kunnen worden gezien.

En nogmaals, in statistics.php wordt die .dat niet geinclude, maar staat ie er zo:
code:
1
$Bestand = "statistics/statistics.dat');";

Of maakt dat weinig uit voor de gegeven oplossingen verder?

Verwijderd

Op woensdag 08 mei 2002 01:03 schreef Waazaap het volgende:
code:
1
$Bestand = "statistics/statistics.dat');";

Of maakt dat weinig uit voor de gegeven oplossingen verder?
Zou op zich moeten werken mist je de string afsluit zonder de ');

Verwijderd

Je maakt van de variabele '$bestand' nu gewoon een string. Ik weet niet of je het weet, maar zo include je geen bestand. Als je de inhoud van dat bestand in een variabele wilt zetten moet je met functies als fopen() en fread() gaan werken.

Misschien zit ik je nu helemaal verkeerd te beoordelen, maar wordt de variabele '$bestand' nu nog verder verwerkt? Als dat het geval is lijkt het me verstandig deze code ook even te plaatsen.

  • Postman
  • Registratie: Februari 2000
  • Laatst online: 03-09 22:43
Op woensdag 08 mei 2002 01:03 schreef Waazaap het volgende:
Hmm, ik gebruik $DOCUMENT_ROOT juist als een soort beveiliging, zodat niet al mijn bronnen kunnen worden gezien.
Hmmm... deze snap ik niet helemaal?? Hoe kan een gebruiker nou de source van jouw PHP script achterhalen??

Anyway, als index.php in root 1 staat, je include iets in index.php vanuit een subdir (root 2), en in dat geïnclude bestand include je iets, dan begint PHP te kijken vanaf root 1 en niet root 2 (dit omdat alles in virtueel in index.php en dus root 1 staat).Snap je het nog? Ik ook niet meer :P

Verwijderd

Topicstarter
En hier dus statistics.php:
code:
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
<html>
<head>
<link href="../css/style.css" rel=StyleSheet type=text/css>
<title>Warlocks from Hell, an Unreal Tournament InstaGib clan</title>
</head>
<body bgcolor="#262223">
<?php

$Bestand = "statistics/statistics.dat');";

$JouwSite = "www.warlocksfromhell.com";

$TellerBestand = file($Bestand);

if(!eregi($JouwSite,$HTTP_REFERER) && $action != "view") {
$OpenBestand = fopen($Bestand,"w");
for($i = 0; $i < count($TellerBestand); $i++) {
list($datum,$teller) = explode("|",$TellerBestand[$i]);
if(date("d-m-Y") == $datum) { $teller++; $gevonden = true; }
fputs($OpenBestand,"$datum|$teller|\n");
}
if(!$gevonden) { fputs($OpenBestand,date("d-m-Y")."|1|\n"); }
fclose($OpenBestand);
}

if($action == "view") {
echo "<table width=\"100%\" style=\"BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: #000000 1px solid\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">";
echo "<tr><td width=\"80%\" background=\"../images/bar.gif\" style=\"BORDER-BOTTOM: #000000 1px solid\"><b>&nbsp;Statistics:</b></td></tr>";
echo "<tr><td bgcolor=\"#333333\">";
echo "<table width=\"50%\"><tr><td width=\"25%\"><font color=\"#ff9933\"><b>Date</b></font></td><td width=\"25%\"><font color=\"#ff9933\"><b>Visits</b></font></td></tr></table>";
for($i = 0; $i < count($TellerBestand); $i++) {
list($datum,$teller) = explode("|",$TellerBestand[$i]);
echo "<table width=\"50%\">";
echo "";
echo "<tr><td width=\"25%\">$datum</td>";
echo "<td width=\"25%\">$teller</td></tr>";
}
echo "</table>";
echo "</td></tr></table>";
}

?>
</body>
</html>

  • Postman
  • Registratie: Februari 2000
  • Laatst online: 03-09 22:43
PHP:
1
<?$Bestand = "statistics/statistics.dat');";?>

Dit klopt niet echt (zoals delighteddennis al zei): die '); moet weg.
PHP:
1
<?$Bestand = "statistics/statistics.dat";?>

Verwijderd

De oplossing is al gegeven door delighteddennis. Je moet dit veranderen:
code:
1
2
3
4
5
Fout:
$Bestand = "statistics/statistics.dat');";

Goed:
$Bestand = "statistics/statistics.dat";

  • Dennis
  • Registratie: Februari 2001
  • Laatst online: 08:34
Ik weet niet of dit helemaal relevant is, maar plaats het toch maar even. Je mag nooit includen met GET parameters.
code:
1
include("index.php?action=bla");

Kan dus niet, gebruik in plaats daarvan:
code:
1
2
$action=bla;
include("index.php");

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

ddc:
Je mag nooit includen met GET parameters.
code:
1
include ( "user:pass@http://includes.myserver.com/?get=includename" );

zou kunnen :+ :P

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 28-08 12:00

Janoz

Moderator Devschuur®

!litemod

Op woensdag 08 mei 2002 08:17 schreef ddc het volgende:
Ik weet niet of dit helemaal relevant is, maar plaats het toch maar even. Je mag nooit includen met GET parameters.
code:
1
include("index.php?action=bla");

Kan dus niet, gebruik in plaats daarvan:
code:
1
2
$action=bla;
include("index.php");
Waarom zeg je dat nou... Ik heb altijd dikke lol met http://www.fmf.nl/~janoz/source.php :+

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • droeftoeter
  • Registratie: Mei 2002
  • Laatst online: 19-06-2025
ingaande op waarom dat niet zal werken (ctrl-c/v uit php manual)


<?php

/* This example assumes that www.example.com is configured to parse .php *
* files and not .txt files. Also, 'Works' here means that the variables *
* $foo and $bar are available within the included file. */

// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';

// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';

$foo = 1;
$bar = 2;
include 'file.txt'; // Works.
include 'file.php'; // Works.

?>

  • Dennis
  • Registratie: Februari 2001
  • Laatst online: 08:34
drm:
code:
1
include ( "user:pass@http://includes.myserver.com/?get=includename" );

zou kunnen :+ :P
Bijdehandje :7

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

ddc:
Bijdehandje :7
ja ach, niet dat ik 't ooit zou gebruiken maar goed ;)

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz

Pagina: 1