I posted a while ago that I added a page with ASP Classic to show your current IP. This worked because the site was being hosted in IIS with ASP.NET, ASP Classic, and PHP all enabled but I have now moved to a PHP only host and wanted to quickly get the IP lookup working again (I use it quite often).
I can potter around with PHP and would be able to figure it out but I did a quick search to find a converter and discovered this great online tool which did the work for me!
Here’s the original code.
<%@Language="VBScript"%> <% If Request.QueryString("debug") = "1" Then Response.Write("<pre>") For Each x in Request.ServerVariables Response.Write(X & " = " & Request.ServerVariables(X) & vbCrLf) Next Response.Write("</pre>") Else If Len(Request.ServerVariables("HTTP_X_FORWARDED_FOR")) = 0 Then Response.Write Request.ServerVariables("REMOTE_ADDR") Else Response.Write Request.ServerVariables("HTTP_X_FORWARDED_FOR") End If End If %>
Here’s the converted result.
<? if ($_GET["debug"] == "1") { echo "<pre>"; foreach ($_SERVER as $x) { echo $X." = ".$_SERVER[$X]."\r\n"; } echo "</pre>"; } else { if (strlen($_SERVER["HTTP_X_FORWARDED_FOR"]) == 0) { echo $_SERVER["REMOTE_ADDR"]; } else { echo $_SERVER["HTTP_X_FORWARDED_FOR"]; } } ?>
It works exactly the same as before but this time it’s PHP. You can try it with the same link: What is my IP?
Leave a Reply