-2

I need get current url (url can be different), I want send this url to email by ajax form, but I cant get right url. I use:

echo $_GET['ref']

But it return empty value.

Addition: I have ajax form which send some data (including current url) to my email. Yes, I use this 2 values:

$url1 = $_SERVER['HTTP_HOST'];
$url2 = $_SERVER['REQUEST_URI'];

But it return me url like this:

/cloud/abuse/abuse_mailer.php

not my current URL.

Geranya
  • 31
  • 3
  • 2
    It may help $_SERVER['REQUEST_URI']. Ref : http://stackoverflow.com/questions/1283327/how-to-get-url-of-current-page-in-php – Elangovan Oct 03 '16 at 09:16
  • 2
    $_GET only shows parameters transferred by get, I.E.: everything after the question mark. try your luck in `var_dump($_SERVER)` – Franz Gleichmann Oct 03 '16 at 09:16
  • Please provide some more information on what you would like to achieve (e.g. show some more of your code)! – M.S. Oct 03 '16 at 09:24
  • Added some additions in post. ['REQUEST_URI'] give me incorrect url, not current. – Geranya Oct 03 '16 at 09:43

1 Answers1

0

$_GET is an array containing data passed through a GET request method. If you want to get your current URL, then you can use $_SERVER; it contains server and request data. As an example:

echo $_SERVER['REQUEST_URI']; // outputs current URI of client

Or you can try:

echo $_SERVER['PHP_SELF'];
Rax Weber
  • 3,730
  • 19
  • 30
  • It gives me url wich generating after sending form /cloud/abuse/abuse_mailer.php, but I need original url from which I send my form. – Geranya Oct 03 '16 at 09:46
  • Thanks, but as result the same url ...abuse/abuse_mailer.php – Geranya Oct 03 '16 at 10:05