Include Problem... (was Listing Declared Variables)
| From: | Dan Tappin | Date: | Wed, 07 May 2003 15:18:25 +0000 |
| Subject: | Include Problem... (was Listing Declared Variables) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-146685@lists.php.net to get a copy of this message | ||
Hi Steve,
Thanks for the tip. I do not know how I did not find that on the PHP site
my self.
I used this function and it lists the variables as I suspected. This
problem is that I do not have a variable conflict.
The PHP include file I am using is at
http://www.maxmind.com/download/geoip/api/php/geoip.inc.
If I create a plain php file (test.php) and add the following sample code
they have provided:
#!/usr/bin/php -q
<?php
// This code demonstrates how to lookup the country by IP Address
include("geoip.inc");
$gi = geoip_open("/usr/local/share/GeoIP/GeoIP.dat",GEOIP_STANDARD);
echo geoip_country_code_by_addr($gi, "24.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "24.24.24.24") . "\n";
echo geoip_country_code_by_addr($gi, "80.24.24.24") . "\t" .
geoip_country_name_by_addr($gi, "80.24.24.24") . "\n";
geoip_close($gi);
?>
It works fine. The country code and name are displayed.
If I create a second file (test2.php) in which I include the first file:
<?
include('test.php');
?>
Again all is well and the country codes return.
Now I have an existing page where I want to add the geoip feature to display
the country name and flag based on an IP address. I have a stats page where
I am pulling log data fram a mySQL db and displaying a table view. On each
line of the table I added my call to the geoip functions to display the
counrty info.
On this particular site my links are like this:
http://mysite.com/index.php?inc=stats&id=1
I set this up so that I can have a generic index.php page which includes a
'stats.inc' file which parses based on the 'id=1' data.
The problem is that if I now add the geoip include in the 'stats.inc' it
fails. No error - no data echoed back. If I add the geoip calls in the
base index.php it works fine.
I even tried creating a function in my default include file and again it
works in the other pages and my other examples above but still not in my:
http://mysite.com/index.php?inc=stats&id=1
page.
I am pulling my hair out trying to figure this out.
Dan
> -----Original Message-----
> From: Steve Keller [mailto:skeller@healthtvchannel.org]
> Sent: Tuesday, May 06, 2003 5:06 PM
> To: dan.tappin@orourke-eng.com
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Listing Declared Variables
>
>
> At 5/6/2003 04:37 PM, dan.tappin@orourke-eng.com wrote:
>
> > Is there an easy way to list the declared variables in a PHP file?
>
> I'm just pulling this out of my butt, but you should be able to do this:
>
> <?
> $thisArray = get_defined_vars();
> foreach ($thisArray as $key => $value) {
> echo $key." : ".$value." <br />\n";
> }
> ?>
>
> and get a list of every variable that's been set by the current
> script (at
> the point that code is run).
>
>
>
> ~Steve-o