Environmental and/or global variable help..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eriol
Forum Newbie
Posts: 3
Joined: Mon Jul 22, 2002 4:06 pm

Environmental and/or global variable help..

Post by eriol »

I'm not sure if what I'm looking for is a predefined global variable within PHP or if it's an Apache environmental variable.. I didn't find it at php.net(reserved.variables.php) nor did I find it within Apache's environmentals(/docs/env.html).. I've been searching google for every SSI and Environmental/Global Variable page I can find, but so far, I haven't had any luck..

I've seen this on other sites before reflecting my ISP's info, so I know it's possible, but I wasn't how it was done.. Basically I want to be able to find something like the following example.. The php script:

Code: Select all

<?
      $msg = "You're using: ".$_SERVER&#1111;"WHAT_EVER"]."\n";
      echo "$msg";
    ?>
When run, it'd return something similiar to this:

You're using: blahblah.123.laj.centurytel.net

CenturyTel is my ISP, so it'd be different for every visitor to that page just as IP and UA is.. I know it'd have to call something from the client just as HTTP_USER_AGENT and REMOTE_ADDR would.. I thought it may be REMOTE_HOST, REMOTE_DOMAIN or IP_DOMAIN, but none of them worked.. Hopefully I'm making sense..

Is it possible to replace "WHAT_EVER" in the code above with something to get me the results I'm looking for via PHP? Thanks in advance..

Take care.. peace..
eriol
gnu2php
Forum Contributor
Posts: 122
Joined: Thu Jul 11, 2002 2:53 am

Post by gnu2php »

I've wondered the same thing myself, so I did a search for +"REMOTE_HOST" +php at Google, and I found this at FAQTs.com:
Why is $REMOTE_HOST returning an empty string?

You're not doing anything wrong - hostname lookups are turned off by default in many web hosting setups - that DNS lookup can slow your site down by 20% or more.

Try doing a gethostbyaddr() call on the contents of REMOTE_ADDR;

http://www.php.net/manual/en/function.gethostbyaddr.php

An example :

<?php

if (!empty($REMOTE_ADDR)) {

$host = @getHostByAddr($REMOTE_ADDR);

} else {

$host = 'no host or ip';

}

?>


http://www.faqts.com/knowledge_base/vie ... /346/fid/2
You might also want to check out http://www.php.net/network
eriol
Forum Newbie
Posts: 3
Joined: Mon Jul 22, 2002 4:06 pm

Post by eriol »

Thank you for the quick response and links.. That's exactly what I was looking for and it works wonderfully.. :)

Take care.. peace..
eriol
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you want to see which $_SERVER variables are available to you, upload a PHP script with

Code: Select all

<?php phpinfo(); ?>
in it to your host and run it.

A good place to start (to save you having to search around the web) is the PHP manual where you'll find lots of information on pre-defined variables.

Mac
eriol
Forum Newbie
Posts: 3
Joined: Mon Jul 22, 2002 4:06 pm

Post by eriol »

Thanks for the suggestion, but I do regularly use phpinfo() as a quick reference tool.. It does come in handy, but it has nothing listed or displayed for REMOTE_HOST.. I also did list that URL (the filename anyway) in my first post.. I always search before bothering someone else with my questions.. That's what I actually needed and thankfully it was answered earlier in the thread..

Take care.. peace..
eriol
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

As you said, it was a suggestion, not a critisism of the question or answer. $REMOTE_HOST and $_SERVER['REMOTE_HOST'] are both listed in my phpinfo() output I didn't know they weren't in yours. I apologise for missing the bit about the pre-defined variables but I wasn't accusing you of anything. You did mention trying to find $_SERVER['something'] so I thought that you did not know about phpinfo().

Basically, although you had had your question answered I thought that the additional information might help others who come searching later and I should have said that in my first post.

Mac
Post Reply