-2

I am passing multiple parameters to a webpage successfully. On the receiving page, I would like to save the complete url string in a database or in a file, for the purpose of resubmitting it if something failed. I am saving one parameter at the time, but I do not know how to save the complete url string without manipulating it. Below is the string to save as an example. Thank you for your input, George

http://sample.net/send.php?macid='5c:cf:7f:01:32:0b:'&a1='0.00'&a2='9999.00'&a3='9999.00'&a4='15.00'&datesaved=''&power='0'&baro='0.0'&pushbutton='5'&button='5'&pump='1'&pump2='1'&pump3='1'&pump4='1'&signal='62'&temp1='20.00'&temp2='23.40'&temp3='0.00'&freq='20'&rebootfreq='864000'&clientcode=''&ip='xxx'&reboottimes='2'

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
Jojo
  • 1

2 Answers2

1
$url_string = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$file = 'file.txt';
file_put_contents($file, $url_string);

to read it

 echo file_get_contents('file.txt'); 

you can also use fopen() to get more flexible access to the file e.g rewrite or append etc

USER249
  • 1,080
  • 7
  • 14
  • Thank you very much for your quick answer. – Jojo Jun 10 '18 at 20:27
  • Hi Amr,I was using the same code in 2 different webpages, but got different answers depending of how I was sending the info. When it is sent thru a get, I have the following string and the url is repeated twice like: http://GET http://api....http://api. – Jojo Jun 11 '18 at 16:17
  • http://GET http://xxxx/send.php?macid=''&a1='13.06'&a2='2.39'&a3='0.00'&a4='2.23'&signal='62'&pump='1'&temp1='25.40'&temp2='0.00'&temp3='0.00'&freq='1774'&rebootfreq='864000'&clientcode=''&ip=''&reboottimes='2'http://xxxx/send.php?macid=''&a1='13.06'&a2='2.39'&a3='0.00'&a4='2.23'&datesaved=''&power='0'&baro=''&pushbutton='5'&button='5'&pump='1'&pump2='1'&pump3='1'&pump4='1'&signal='62'&temp1='25.40'&temp2='n/a'&temp3='0.00'&freq='1774'&rebootfreq='864000'&clientcode=''&ip=''&reboottimes='2','{"success":true,"errors":[],"token":"ac4625beb0"}',DB Updated,' ' – Jojo Jun 12 '18 at 05:33
  • I used $url_string = $_SERVER['REQUEST_URI']; to solve the duplication. – Jojo Jun 13 '18 at 02:01
0

I solve my issue by using the following: $url_string = $_SERVER['REQUEST_URI']; Thanks to everyone help

Jojo
  • 1