简体   繁体   中英

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. Once this form is submitted I'm looking to include the full URL into an email that goes out.

However, the problem I keep running into is that the string gets cut off at the first " & " in the URL string.

Here is an example URL string:

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?

Unless you send your form's POST request to this 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. 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; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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