Jump to content

Access Url Variables Via Ajax Request?


Manixat

Recommended Posts

Heya, I'm currently brainstorming this little issue of mine, I have my page right, immediately I'm running an ajax request to call a php script but I can't seem to get the URL variables from the actual URL. Is there any way I can access the original $_GET array from the called script ? ( Without having to send the variables again in the request )

 

One way I can do this is via session, but is there an ever easier way?

Link to comment
https://forums.phpfreaks.com/topic/272376-access-url-variables-via-ajax-request/
Share on other sites

Yes, that is an obvious solution, but I am calling this script from every single page on my site and that means I have to go and hardcode all of this into the ajax calls, and if I have to change anything in future that would again mean I have to change everything by hand ( which is actually the same problem with using session ), I was hoping there was another way to access the URL variables from the external script :?

Your PHP script that generates the page, the generated HTML, and your AJAX PHP script are all separate entities. The only communication between them is what information is explicitely sent to each one on an individual basis. I think your initial idea of a session is the best solution to your problem. A session would supersede the need to pass variables between one another.

 

The only information your AJAX script would receive aside from what you pass it would be headers sent from the browser. The 'referer' header might hold the GET variables you are looking for, but these are unreliable since not all browsers are the same and the headers can be easily spoofed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.