Forum Moderators: coopster

Message Too Old, No Replies

Can't Pass Variable

Variable isn't passed to included page

         

chunk_split

11:40 pm on Jun 12, 2006 (gmt 0)

10+ Year Member



I'd usually include a file like this:

<?php include('http://www.somewebsite.tld/includes/header.php?country=costa-rica');?>

Which worked fine until my host switched allow_url_fopen = off, so I thought this might work instead:

<?php

$country = "costa-rica";

include($_SERVER['DOCUMENT_ROOT']."/includes/header.php");

?>

The variable doesn't pass to header.php for me.

header.php's code is something like:

<?php

$country_new = $_GET['country'];

$country_lower = str_replace("-", " ", $country_new);

$country = ucwords($country_lower);

?>

I then echo $country where needed.

eelixduppy

11:51 pm on Jun 12, 2006 (gmt 0)



If "URL fopen wrappers [us3.php.net]" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Appendix M for a list of protocols) instead of a local pathname.
--from php.net

Also, in your revised code, you didn't specify the url query:
<?php
//$country = "costa-rica"; Not needed, unless you want to change your header.php code (see note below)
include("includes/header.php?country=costa-rica");//this should be sufficient
?>

If you want to leave your current file with the include in it, and change the included file, header.php should look like this:
<?php
$country_new = $country;
$country_lower = str_replace("-", " ", $country_new);
$country = ucwords($country_lower);
?>

Good luck!