PDA

View Full Version : PHP code to ASP.NET?


pixencom
05-21-2008, 07:10 AM
Hey can anyone change this code to ASP.NET? Its basically submitting information about a visitor to my stats website.


<?php
if(getenv("HTTP_CLIENT_IP")){
$ssv_ip = getenv("HTTP_CLIENT_IP");
}else if(getenv("HTTP_X_FORWARDED_FOR")){
$ssv_ip = getenv("HTTP_X_FORWARDED_FOR");
}else if(getenv("HTTP_X_FORWARDED")){
$ssv_ip = getenv("HTTP_X_FORWARDED");
}else if(getenv("HTTP_FORWARDED_FOR")){
$ssv_ip = getenv("HTTP_FORWARDED_FOR");
}else if(getenv("HTTP_FORWARDED")){
$ssv_ip = getenv("HTTP_FORWARDED");
}else{
$ssv_ip = $_SERVER["REMOTE_ADDR"];
}
$ssv_host = $_SERVER["HTTP_HOST"];
$ssv_page = $_SERVER["REQUEST_URI"];
$ssv_pageurl = "http://$ssv_host$ssv_page";
$ssv_pageurl = base64_encode($ssv_pageurl);
$ssv_ref = $_SERVER["HTTP_REFERER"];
$ssv_ref = base64_encode($ssv_ref);
$ssv_agent = $_SERVER["HTTP_USER_AGENT"];
$ssv_agent = base64_encode($ssv_agent);
$ssv_url = "http://mydomain.com/input.gif?entrytype=php&ip=$ssv_ip&page=$ssv_pageurl&ref=$ssv_ref&useragent=$ssv_agent";
$ssv_handle = fopen($ssv_url, "r");
$ssv_fgets = fgets($ssv_handle);
fclose($ssv_handle);
?>


Thanks!

saeed
05-21-2008, 01:24 PM
http://www.hashemian.com/tools/whoami.php

HTH! :thumbsup:

chump2877
05-23-2008, 01:17 AM
Explore the Request.ServerVariables collection object:

http://msdn.microsoft.com/en-us/library/ms525396(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms524602(VS.85).aspx
http://www.4guysfromrolla.com/webtech/092298-3.shtml

Edit: Apparently, there is also the HttpRequest.ServerVariables (http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx) collection that exposes additional server variables specific to ASP.NET...

Debugger
06-01-2008, 11:27 AM
I am giving an example of getting IP of user in ASP.NET

#Region "IP Tracking"
Function getIP() As String
Dim strIP As String
'strIP = ""
strIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If strIP = "" Then
strIP = Request.ServerVariables("REMOTE_ADDR")
End If
Return strIP
End Function
#End Region

Similarly you can you any server variable to convert your PHP code to ASP.NET.

Thank you.