-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,370
  • 4
  • 15
  • 27
Mak
  • 2,765
  • 7
  • 31
  • 56

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,214
  • 4
  • 50
  • 72
0

use urlencode($_SERVER['QUERY_STRING'])

It encodes the link.

iCode
  • 1,436
  • 1
  • 14
  • 26