Ken Boone
Ken Boone

Reputation: 153

$_SERVER['REQUEST_URI'] returns PHP file not URL

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?

Upvotes: 0

Views: 6308

Answers (1)

rakeshjain
rakeshjain

Reputation: 1761

$_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)

Upvotes: 2

Related Questions