最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - jQuery ajax referer url - Stack Overflow

matteradmin5PV0评论

How can I get the url of the referer in an ajax request?

A file named main.php has jQuery that sends an ajax call to a file named request.php.

Is it possible to somehow figure out the referer when I'm on request.php? To be precise, I want to print the string "main.php" (dynamically) while running request.php.

How can I get the url of the referer in an ajax request?

A file named main.php has jQuery that sends an ajax call to a file named request.php.

Is it possible to somehow figure out the referer when I'm on request.php? To be precise, I want to print the string "main.php" (dynamically) while running request.php.

Share Improve this question asked Nov 5, 2014 at 9:56 sleepless_in_seattlesleepless_in_seattle 2,2344 gold badges27 silver badges37 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Normally the the browser will send the referer page using the header Referer as part of the ajax request so you can read it

So you could do something like

$_SERVER['HTTP_REFERER']
  • How do you get the 'referer' header in PHP?

If you don't want to depend on the default Referer header, pass a custom header of your own

$(document).ajaxSend(function (event, jqXHR) {
    jqXHR.setRequestHeader('my-referer', 'some-value');
});

yes on request.php u can get referee like this $_SERVER['HTTP_REFERER']

Post a comment

comment list (0)

  1. No comments so far