-2

Think my current page url is: http://example.com/id=10

In this this page has link to go other page, I want to pass current URL as a query string like this:

http://example.com/about-us/?edit=1&return=http://example.com/id=10

in PHP

http://example.com/about-us/?edit=1&return=<?php echo $_SERVER['QUERY_STRING'] ?>

but this is not working, could anyone help me to do this.

Anand Solanki
  • 3,419
  • 4
  • 16
  • 27
Gayan
  • 2,845
  • 7
  • 33
  • 60

2 Answers2

1

Use this (I assume you are using http only);

$currentUrl = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");

$link = "http://example.com/about-us/?edit=1&return=" . $currentUrl;
Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73
0

use urlencode($_SERVER['QUERY_STRING'])

It encodes the link.

iCode
  • 1,456
  • 1
  • 15
  • 26