简体   繁体   English

使用$ _SERVER获取PHP中的查询字符串URL路径

[英]Get Query String URL Path in PHP with $_SERVER

I have a form that has a " textarea " where I'm looking to capture the full URL of the page the user is on. 我有一个带有“ textarea ”的表单,我想在其中捕获用户所在页面的完整URL。 Once this form is submitted I'm looking to include the full URL into an email that goes out. 提交此表单后,我希望将完整的URL包含在发出的电子邮件中。

However, the problem I keep running into is that the string gets cut off at the first " & " in the URL string. 但是,我一直遇到的问题是该字符串在URL字符串的第一个“ ”处被截断。

Here is an example URL string: 这是一个示例URL字符串:

example.com/folder/results.php?lat=38.10591&lng=-51.556916898&zipcode=32827&countryIso=US

Here is what I have tried: 这是我尝试过的:

<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url; ?>

I've also tried: 我也尝试过:

<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']; echo $url; ?>

Neither one worked to include the full URL... Is there something I'm missing? 没有人设法包含完整的URL ...我缺少什么吗?

Unless you send your form's POST request to this url : 除非您将表单的POST请求发送到此url:

example.com/folder/results.phplat=38.10591&lng=-51.556916898&zipcode=32827&countryIso=US

I think your problem is that you are logging the url of the url of the file processing the form. 我认为您的问题是您正在记录处理表单的文件的url的url。 Have you tried storing the content of this into an hidden field of your form? 您是否尝试过将其内容存储到表单的隐藏字段中?

<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM