Jump to content

[SOLVED] Passign GET variables to include() file


rtadams89

Recommended Posts

I start all of my PHP pages off with this code:

<?
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/config.php');
?>

 

The "config.php" file contains (among other things) this:

ob_start("ob_gzhandler");

which enables gzip compression for all my pages.

 

I have one page on my site for which I need gzip compression OFF. I tried surrounding the gzip code in the "config.php" with an IF statement as follows:

if (!isset($GET_['gzipoff']))
{
ob_start("ob_gzhandler");
}

 

then one the file for which I want gzip off, I changed the require_once line to:

<?
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/config.php?gzipoff=1');
?>

 

Unfortunately this results in an error about not being able to include the file. Is it not possible to pass a variable to the included file this way? If not, is there a simple way to disable the gzip compression on just this one page?

From my experiance you need to set it to a variable.

 

<?php
$docroot = $_SERVER['DOCUMENT_ROOT'][
require_once($docroot/includes/config.php?gzipoff=1');
?>

 

Also, always start php with the full php tags as short tags may not be supported on the server.  In your case right now they probably are, but if you ever move servers, they may not be.

Including/requiring a file thought the file system literally includes that code into the main file. GET parameters are not parsed on the end of the URL because that is a feature of HTTP requests and web servers, not file system requests. Just use a variable or a defined constant -

 

$gzipoff = false; // cause the variable to be set (actual value is not important.)
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/config.php');

 

if (!isset($gzipoff']))
{
ob_start("ob_gzhandler");
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.