# PHP\_SELF and HTTP\_HOST producing weird results

**URL:** <https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671>\
**Category:** General PHP Help\
**Created:** [October 16, 2020, 9:52pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671 "2020-10-16T21:52:15Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 16, 2020, 9:52pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/1 "2020-10-16T21:52:16Z")

</div>

hey guys,

see attached image for what I’m questioning. I have traffic analysis code behind all of my pages. and a file that is ““included”” contains this code, among other lines:

```
$host = $_SERVER['HTTP_HOST'];
$page = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';

```

the issue is that, sometimes when I view the log page, the PHP\_SELF info that was captured comes through in all capital letters. and, sometimes too, in another bout of weirdness, the information is captured as ““[mail.domain.com](http://mail.domain.com)””. has anyone seen this before!? why would this happen? I’m guessing it’s a result of the endless amount of bot software running rampant on the internet, sourced from all different underground people the world over?

thanks.

Adam

 ![weird_transacting_by_PHP](https://www.phphelp.com/uploads/default/original/2X/0/078287c592f9e7244582893f76da7accd14ac0a1.jpeg)

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [October 16, 2020, 10:06pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/2 "2020-10-16T22:06:13Z")

</div>

Do not use _$\_SERVER[‘PHP\_SELF’]_. It is vulnerable to an XSS attack.

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 17, 2020, 12:06am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/3 "2020-10-17T00:06:24Z")

</div>

well I appreciate that, ben. but you didn’t answer a single thing I asked in this thread. LOL. care to expand on your one sentence answer? =)

and I’m not too worried about any attacks really, as my contingency measures and backups are extremely unique. more than likely I will be hacked at some point in the future, but that doesn’t bother me too much. The money I bring in is not dependent on the sites that I manage being up and running or not.

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [October 17, 2020, 3:17pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/4 "2020-10-17T15:17:07Z")

</div>

Well, you might want to read this link that explains a little about HTTP\_HOST. [HTTP\_HOST](https://stackoverflow.com/questions/13772934/php-server-variables-serverhttp-host-vs-serverserver-name)  
One thing you should remember is that robots are quite often ran on local servers. And, can be a WAMP server on a pc or laptop somewhere. On these system, you can set the headers to be just about anything you want. Also, sometimes they are on a local lan system and this can also alter the IP addresses in odd ways. As far as the PHP\_SELF goes, you already know the page you are on, so just use that to save in the database.

And, what Benanamen was talking about is using the PHP\_SELF in a link on the page. You should not use that in links to other pages. Here is an explanation about it: [XSS-Vulnerability](https://www.webadminblog.com/index.php/2010/02/23/a-xss-vulnerability-in-almost-every-php-form-ive-ever-written/)

Lastly, when you decode IP addresses and domain names, there are ways to hide them. You can check for IVP4/IVP6 values and look for sub-net’s and proxies to get the real IP of the visitor. Here is a code sample from someone that might work well for you. [Get-Real-IP](https://www.phpclasses.org/package/10365-PHP-Get-the-real-IP-address-of-a-user-accessing-a-site.html)

Hope this helps explain it further for you.

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 18, 2020, 1:19am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/5 "2020-10-18T01:19:33Z")

</div>

Ernie,

I’m not sure anything you said made sense to me, although I understand everything you said in your post. Do you understand what my question is? It’s not so much that I’m bothered by bots running all over the internet sourced from all over the world and from many different organizations, but rather wanted an understanding of why PHP\_SELF appears as different strings or capitalized sometimes. Does that make sense? Did you answer that in your post here? Here’s examples of everything I’ve seen, as the information printed by the global on the site I reference in my first post:

=\> [www.adamevanovich.com](http://www.adamevanovich.com)  
=\> [WWW.ADAMEVANOVICH.COM](http://WWW.ADAMEVANOVICH.COM)  
=\> [adamevanovich.com](http://adamevanovich.com)  
=\> [ADAMEVANOVICH.COM](http://ADAMEVANOVICH.COM)  
=\> [mail.adamevanovich.com](http://mail.adamevanovich.com)

thanks Ernie.

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [October 18, 2020, 3:58am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/6 "2020-10-18T03:58:58Z")

</div>

Well, are all of these posted from the same system? Or did you test it from different systems?

For robots, you can add a robots file to stop them. This will not stop the hacker robots, but, will stop many of the common ones such as Google.

If you are testing these from different systems, it is most likely that they have different host names set up.  
Also, it may be a caching issue on the server. Or even a browser cache issue. Are you testing with several different systems?

Sorry if I did not help you much with your main question.

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 18, 2020, 4:18am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/7 "2020-10-18T04:18:43Z")

</div>

Well ernie,

As I stated before it’s just a curiosity issue. The global variable I am talking about returns all sorts of strings in terms of the web page that’s being visited as per my previous post. So as far as it being a browser caching issue, I seriously doubt that’s the case because I dump all the temporary junk all the time from chrome and Firefox when I view this report page and these records in the traffic law always show up like this all the time. Some more or less what I’m saying is that just out of curiosity and based off of everything you said, I’m guessing that the reason the same string appears in all different forms after a transaction comes through and the PHP code records the website visit, the server that’s visiting the page has all sorts of different configurations. Based on what you said that’s the only thing that makes sense at this point and if you want to view the page that I’m talking about take a look at it, it’s here:

www. [adamevanovich.com/r/r.php](http://adamevanovich.com/r/r.php)

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [October 18, 2020, 4:36am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/8 "2020-10-18T04:36:23Z")

</div>

Heading to bed shortly… But, went to your site and it does have my ISP correctly listed.  
But, it has your domain name for the “visitor domain name”.

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 18, 2020, 5:32am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/9 "2020-10-18T05:32:48Z")

</div>

I know that Ernie. that is a mistake by me in the code, but I know what is what, so it is irrelevant. the fact of the matter is, that the VISITOR DOMAIN NAME is being printed by the database which gets its value from PHP\_SELF. so my question still stands.

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [October 18, 2020, 7:36am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/10 "2020-10-18T07:36:33Z")

</div>

How about posting the code so we can see what you’re working with.

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 18, 2020, 10:24am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/11 "2020-10-18T10:24:50Z")

</div>

sure thing, ben. here ya go:

_CAPTURE CODE:_

```
<?php

$dbHost = "ip";
$dbName= "dbName";
$dbUsername = "username";
$dbPassword = "pw";
$ip = gethostbyaddr($_SERVER['REMOTE_ADDR']);
$host = $_SERVER['HTTP_HOST'];
$page = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '';
date_default_timezone_set('America/Chicago'); //change server time zone to UTC-600 (Chicago, IL time)
$date = date("Y/m/d");
$time = date("H:i:s");

	mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
	$conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

	$stmt = $conn->prepare("INSERT INTO tblTraffic (ip, host, page, date, time) 
						  	VALUES (?, ?, ?, ?, ?)");
	$stmt->bind_param("sssss", $ip, $host, $page, $date, $time);
	$stmt->execute();
	$stmt->close();
	$conn->close();

?>

```

_REPORT CODE:_

```
$sql = mysqli_query($conn, "SELECT ip
                                     , host 
                                     , page
                                     , DATE_FORMAT(date, '%m/%d/%y') as date
                                     , TIME_FORMAT(time, '%T') as time
                                FROM tblTraffic'
                                ORDER BY date DESC, time DESC"); 

<?php 
    // printing table rows
    while($row = mysqli_fetch_row($sql)) {
        echo '<tr>';
        $index = 0;
        foreach ($row as $key => $col) {
            if ($index > 0)
                { echo "<td>$col</td>"; }
            $index++;
        }
    		echo '</tr>';
    }
    $conn->close(); 
?>
```

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [October 18, 2020, 6:09pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/12 "2020-10-18T18:09:52Z")

</div>

> [@vba\_php](#):
>
> the PHP\_SELF info that was captured comes through in all capital letters

Here is the first problem with your post. PHP\_SELF is the filename. The data you are getting in caps is from _$\_SERVER[‘HTTP\_HOST’]_

**$\_SERVER[‘HTTP\_HOST’]** is based on the request from the client.

You can test it here. Just enter your domain in caps or whatever and view the Request Header response shown  
[https://websniffer.cc/](https://websniffer.cc/)

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 18, 2020, 7:12pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/13 "2020-10-18T19:12:53Z")

</div>

yes you’re right, and I put in a couple of test runs on that site, typed in my domain and it returned the same thing. so if I type the domain in, in all CAPS, it returns the HEADER in all caps. that makes perfect sense. I’m guess that’s what you wanted me to see? I guess that’s good, but that still doesn’t tell me what’s going on with their server, which is probably the most important in part of this process.

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [October 18, 2020, 8:01pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/14 "2020-10-18T20:01:14Z")

</div>

If you want more info on what is making the request, capture the User Agent and Browser info. That may give you the answer you want.

```
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
print_r($browser);
```

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 18, 2020, 10:24pm UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/15 "2020-10-18T22:24:12Z")

</div>

it’s not that I care too much, ben. I know that bots are all over the place and that they come from all sorts of sources. I mean I look this crap up all the time, and I’ve seen stuff render the page from every country in the world and virtually from any type of org in the world. and my only suspicion is that, simply because of the hatred and greed that runs the world, people all over the world are spying on everyone else to try and find out who’s profiting from what. wouldn’t you think that would be the case?

---

<div class="post-metadata">

**Author:** ![ErnieAlex](https://www.phphelp.com/letter_avatar_proxy/v4/letter/e/bc8723/32.png) [@ErnieAlex](https://www.phphelp.com/u/ErnieAlex)\
**Post date:** [October 19, 2020, 1:48am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/16 "2020-10-19T01:48:01Z")

</div>

I agree with that comment! But, also since media now runs the world, everyone wants to know everything about you. Take Facebook for example. I keep away of that place! Ha!

PS: Ben’s name is Kevin! Ha!

---

<div class="post-metadata">

**Author:** ![vba\_php](https://www.phphelp.com/user_avatar/www.phphelp.com/vba_php/32/3469_2.png) [@vba\_php](https://www.phphelp.com/u/vba_php)\
**Post date:** [October 19, 2020, 4:40am UTC](https://www.phphelp.com/t/php-self-and-http-host-producing-weird-results/32671/17 "2020-10-19T04:40:05Z")

</div>

everyone wants to know EVERYTHING about ME? why would you think that!? What do they care about me? I live in a small room and no one knows I exist! LOL. Except you guys here, perhaps…

Regarding your comment too Ernie, I think what you mean by ““everyone wants to know everything about you””, is really like ““people have access to so much information and they can’t help themselves, they’re literally freaking insane””. =)
