后台能获取当前页面的url么?

时间:2022-05-12 22:17:14
如题
我是希望能在用户发起某个cgi请求的时候,得到他当前所在页面的url。
有可能么?

7 个解决方案

#1


文件名+路径+主机名不就行了么?

#2


当然可以。

#3



//这是这个页面请求的HTTP头,你需要的就是提取Referer
GET http://topic.csdn.net/u/20110324/09/8f131cc1-be62-4b3a-ba1c-0651328347b8.html?98286 HTTP/1.1
Host: topic.csdn.net
Connection: keep-alive
Referer: https://forum.csdn.net/BList/Cpp/
Cache-Control: max-age=0
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
Cookie: __message_district_code=000000; UN=bluesky12312388; UserName=bluesky12312388; UserInfo=DcPEGZUUYLPVOpGFWeTkdkFi8tiIRn9GqaKVaNubzvcrcIJtw4GDvM4XLEOcyMllUJamz1FX%2bC5SWUV8v%2bLKFAU9IFxlDpUNyfkd34tm88ftwzM6bqwySziLnuFwgKwrSqTF59PIADPPySHgk5fBTs4GGz4UBRuhMXsq2dYTzDHGvJ3oHEeG8vZ1KG16ZMRlbEDEnQrs3dofEumLa77xa3cECxVjq848X6kEYbr9B3I%3d; __gads=ID=29504fc10f139e56:T=1300690583:S=ALNI_MbqXOTUOBLxYPVN7VRN6p7MC6V7eg; __utma=17226283.908946270.1300696701.1300696701.1300696701.1; __utmz=17226283.1300696701.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); skin=3; __message_sys_msg_id=936; LastVisitedForum=17673f58-331a-4f41-a240-3ac1d698fd74*e9563447-9ad0-4be1-8372-f81c2a9e9d24*b5f1380c-f04c-4682-861a-54357b14186a*5fc6f290-9ab1-492e-af2c-fbd31e9e3002*8bbce98e-b54f-41ea-8f96-9ee6311513c0; __message_gu_msg_id=0; __message_cnel_msg_id=0; __message_in_school=0
If-Modified-Since: 2011-03-24 10:41:21

#4



string  URL = HttpContext.Current.Request.Url.ToString();


测试通过

#5


你把environment打印出来就知道了.

#6


Array ( [HTTP_HOST] => 192.168.1.10 [HTTP_CONNECTION] => keep-alive [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_ACCEPT_CHARSET] => GBK,utf-8;q=0.7,*;q=0.3 [PATH] => /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [LD_LIBRARY_PATH] => /usr/local/apache2/lib: [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.4.1 (Unix) PHP/5.4.0 [SERVER_NAME] => 192.168.1.10 [SERVER_ADDR] => 192.168.1.10 [SERVER_PORT] => 80 [REMOTE_ADDR] => 192.168.1.9 [DOCUMENT_ROOT] => /home/apache/web/ [REQUEST_SCHEME] => http [CONTEXT_PREFIX] => [CONTEXT_DOCUMENT_ROOT] => /home/apache/web/ [SERVER_ADMIN] => you@example.com [SCRIPT_FILENAME] => /home/apache/web/index.php [REMOTE_PORT] => 2241 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => / [SCRIPT_NAME] => /index.php [PHP_SELF] => /index.php [REQUEST_TIME_FLOAT] => 1338215669.221 [REQUEST_TIME] => 1338215669 )


这里面有的, 你应该大致都可以通过environment拿到.

#7


NAME
       environ - user environment

SYNOPSIS
       extern char **environ;

DESCRIPTION
       The  variable  environ  points  to  an array of pointers to strings called the "environment".  The last pointer in this array has the value NULL.  (This
       variable must be declared in the user program, but is declared in the header file <unistd.h> in case the header files came from libc4 or libc5,  and  in
       case  they  came  from  glibc and _GNU_SOURCE was defined.)  This array of strings is made available to the process by the exec(3) call that started the
       process.

#1


文件名+路径+主机名不就行了么?

#2


当然可以。

#3



//这是这个页面请求的HTTP头,你需要的就是提取Referer
GET http://topic.csdn.net/u/20110324/09/8f131cc1-be62-4b3a-ba1c-0651328347b8.html?98286 HTTP/1.1
Host: topic.csdn.net
Connection: keep-alive
Referer: https://forum.csdn.net/BList/Cpp/
Cache-Control: max-age=0
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.215 Safari/534.10
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
Cookie: __message_district_code=000000; UN=bluesky12312388; UserName=bluesky12312388; UserInfo=DcPEGZUUYLPVOpGFWeTkdkFi8tiIRn9GqaKVaNubzvcrcIJtw4GDvM4XLEOcyMllUJamz1FX%2bC5SWUV8v%2bLKFAU9IFxlDpUNyfkd34tm88ftwzM6bqwySziLnuFwgKwrSqTF59PIADPPySHgk5fBTs4GGz4UBRuhMXsq2dYTzDHGvJ3oHEeG8vZ1KG16ZMRlbEDEnQrs3dofEumLa77xa3cECxVjq848X6kEYbr9B3I%3d; __gads=ID=29504fc10f139e56:T=1300690583:S=ALNI_MbqXOTUOBLxYPVN7VRN6p7MC6V7eg; __utma=17226283.908946270.1300696701.1300696701.1300696701.1; __utmz=17226283.1300696701.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); skin=3; __message_sys_msg_id=936; LastVisitedForum=17673f58-331a-4f41-a240-3ac1d698fd74*e9563447-9ad0-4be1-8372-f81c2a9e9d24*b5f1380c-f04c-4682-861a-54357b14186a*5fc6f290-9ab1-492e-af2c-fbd31e9e3002*8bbce98e-b54f-41ea-8f96-9ee6311513c0; __message_gu_msg_id=0; __message_cnel_msg_id=0; __message_in_school=0
If-Modified-Since: 2011-03-24 10:41:21

#4



string  URL = HttpContext.Current.Request.Url.ToString();


测试通过

#5


你把environment打印出来就知道了.

#6


Array ( [HTTP_HOST] => 192.168.1.10 [HTTP_CONNECTION] => keep-alive [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_ACCEPT_CHARSET] => GBK,utf-8;q=0.7,*;q=0.3 [PATH] => /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [LD_LIBRARY_PATH] => /usr/local/apache2/lib: [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.4.1 (Unix) PHP/5.4.0 [SERVER_NAME] => 192.168.1.10 [SERVER_ADDR] => 192.168.1.10 [SERVER_PORT] => 80 [REMOTE_ADDR] => 192.168.1.9 [DOCUMENT_ROOT] => /home/apache/web/ [REQUEST_SCHEME] => http [CONTEXT_PREFIX] => [CONTEXT_DOCUMENT_ROOT] => /home/apache/web/ [SERVER_ADMIN] => you@example.com [SCRIPT_FILENAME] => /home/apache/web/index.php [REMOTE_PORT] => 2241 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => / [SCRIPT_NAME] => /index.php [PHP_SELF] => /index.php [REQUEST_TIME_FLOAT] => 1338215669.221 [REQUEST_TIME] => 1338215669 )


这里面有的, 你应该大致都可以通过environment拿到.

#7


NAME
       environ - user environment

SYNOPSIS
       extern char **environ;

DESCRIPTION
       The  variable  environ  points  to  an array of pointers to strings called the "environment".  The last pointer in this array has the value NULL.  (This
       variable must be declared in the user program, but is declared in the header file <unistd.h> in case the header files came from libc4 or libc5,  and  in
       case  they  came  from  glibc and _GNU_SOURCE was defined.)  This array of strings is made available to the process by the exec(3) call that started the
       process.