0

Below are the relevant lines of code:

update.js

$('#tablePlaceholder').load('updateTable.php');

updateTable.php

$path = $_SERVER['REQUEST_URI'];

Normally $_SERVER['REQUEST_URI'] returns the URL, however in this case, the URI at the moment of the request is technically the PHP file, so what is returned is updateTable.php instead of the actual URL. Is there an alternate command I can use to get the URL instead of URI? I have resorted to storing the URL in a session/global variable to retain access to the actual URL in the PHP file, but it seems there must be a better way, though I have not found it. Any tips would be most welcome!

I was looking at the documentation for the jQuery load() command: http://api.jquery.com/load/

It looks like I might be able to pass the URL as a string via the data argument?

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Ken Boone
  • 143
  • 2
  • 9
  • What do you mean by "actual URL" exactly, the HTML file where this all takes place? – Pekka Aug 25 '13 at 18:13
  • By actual URL, I mean the URL in the address bar. – Ken Boone Aug 25 '13 at 21:50
  • 1
    Right. The Ajax call is a separate request, so that is by design; however, you should be able to get the calling page by looking at `$_SERVER["HTTP_REFERER"]` – Pekka Aug 25 '13 at 21:52

1 Answers1

2

$_SERVER['REQUEST_URI'] is supposed to give path of current script relative to root and not the full url. If you want to get full url path, take a look at the same question on stackoverflow with the solution also being there

Getting the full URL of the current page (PHP)

Community
  • 1
  • 1
rakeshjain
  • 1,791
  • 11
  • 11
  • Wow, that is quite elaborate. In my situation the URL in the address bar will always be something basic like PageName.html (no question marks, additional slashes, ports, ampersands... simply a filename and then the .html extension). I don't suppose there is something more basic? – Ken Boone Aug 25 '13 at 21:56
  • @KenBoone that is the way to do it. It takes care of whether http or https is being used. Also taking care of port number as well – rakeshjain Aug 26 '13 at 05:11
  • 1
    @KenBoone If that did solve your question, can you accept the answer? – rakeshjain Aug 29 '13 at 06:38