PDA

View Full Version : global_variable=off --> declaration of variable?



fjellaksel
August 6th, 2004, 09:07 AM
Hi guys...

I use a include script on my index page, so all pages are loaded into the index page... yeah, you probably know what I am talking about.. like:
index.php?page=photos ... but, the server that the site is hosted on has the global_variable set to off, and it won't work if I do not declare my variables first.. at least, that's what they say... Below is the code, and I hope that someone can tell me what I have to change to get it to work...

--------------------------------------------------

<?php
$IncludeDir = "inc_files";
$DefaultPath = "inc_files/bilder.inc";
$FileExtension = ".inc";
if (isset($side)) {
$side = stripslashes(strip_tags($side));
$Forbidden1 = ereg("\.\./", $side);
$Forbidden2 = ereg("/", $side);
$IncludePath = $IncludeDir . "/" . $side . $FileExtension;
if ($Forbidden1 OR $Forbidden2) {
echo "<h1>Warning</h1>\n";
echo "<p>Foresp&oslash;rsler p&aring; tvers av definerte \n";
echo "omr&aring;der er ikke tillatt.</p>\n";
}
else {
if (@fopen("$IncludePath", "r")) {
include ("$IncludePath");
}
elseif (!(@fopen("$IncludePath", "r"))) {
echo "<p>Denne siden finnes ikke!</p>\n";
}
}
}
else {
include("$DefaultPath");
}
?>

------------------------------------------

Hope someone can help me out here...

Best Regards
Eirik Fjellaksel

Hans Kilian
August 6th, 2004, 11:33 AM
Heja Norge! ;)

Basically it means that instead of $side you have to write either $_GET['side'] or $_POST['side'] depending on whether the page was activated by the HTTP GET or POST method.

In your case it's the GET method so you should use this code:


<?php
$IncludeDir = "inc_files";
$DefaultPath = "inc_files/bilder.inc";
$FileExtension = ".inc";
if (isset($_GET['side'])) {
$side = stripslashes(strip_tags($_GET['side']));
$Forbidden1 = ereg("\.\./", $side);
$Forbidden2 = ereg("/", $side);
$IncludePath = $IncludeDir . "/" . $side . $FileExtension;
if ($Forbidden1 OR $Forbidden2) {
echo "<h1>Warning</h1>\n";
echo "<p>Foresp&oslash;rsler p&aring; tvers av definerte \n";
echo "omr&aring;der er ikke tillatt.</p>\n";
}
else {
if (@fopen("$IncludePath", "r")) {
include ("$IncludePath");
}
elseif (!(@fopen("$IncludePath", "r"))) {
echo "<p>Denne siden finnes ikke!</p>\n";
}
}
}
else {
include("$DefaultPath");
}
?>