Reputation: 92
I have the current set up of... a javascript file containing
$(document).ready(function() {
$.ajax({
cache: false,
type: 'GET',
url: './memberfunctions/getRef.php',
data: {},
beforeSend:function(){
},
success:function(data){
// successful request; do something with the data
console.log(data);
},
error:function(){
// failed request; give feedback to user
alert("idk what happened");
}
});
});
getRef.php is
<?php
$httpReferer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
echo $httpReferer;
?>
If i go to pastebin, type in and click mysite.com, i go to mysite.com and the console says mysite.com. Obviously I want the console to say pastebin.com/######
I know HTTP_REFERER is insecure, vulnerable, poor, unreliable. It serves a tiny non-vital purpose.
Upvotes: 1
Views: 2107
Reputation: 1289
For your AJAX request, the referrer is not pastebin.com. Your parent page would have had the referrer set to pastebin.
You can try something like this as inline script:
<script>
var ref = "<?php echo $_SERVER['HTTP_REFERER']; ?>";
</script>
OR below which need not be inline
<script>
var ref = document.referrer;
</script>
Unless am missing something in the intent of the AJAX call.
Upvotes: 3