0

i have two files. In first (parent, address: www.myaddress.com/fun/test.php) is jQuery function:

<script type="text/javascript">         
$(function(){
    $(document).ready(function()
    {
        import_f = setInterval(function()
        {
            $('#file').load('fun2.php?id='+ Math.random());

        }, 5000);       
    });
});         
</script>

When i print in fun2.php file full page address, i get: /fun2.php?id=0.31089064538474454.

How get paren page address. (www.myaddress.com/fun/test.php).

Parent's address may always be another, so I need to find a function that.

Thanks

3 Answers 3

2

is this what your looking for?

function getParentAddress(){
  return window.location;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Sounds like you are looking for the HTTP Referrer. You can get it via $_SERVER['HTTP_REFERER'].

But note that this can be changed by the user to something else, so you actually cannot rely on that.


Maybe it is better to send the current URL via the Ajax call, along with the ID:

$('#file').load('fun2.php?id='+ Math.random() +'&parent=' + encodeURIComponent(window.location));

But again, if one really wants to, he can change this too. So you can never 100% trust that one request is really coming from a certain page.

Reference: window.location, encodeURIComponent

Comments

0

The current address of the page is stored in the window.location property.

console.log(window.location)

run on this page yields

hash: ""
host: "stackoverflow.com"
hostname: "stackoverflow.com"
href: "http://stackoverflow.com/questions/4031148/php-jquery-load-function-and-page-address"
origin: "http://stackoverflow.com"
pathname: "/questions/4031148/php-jquery-load-function-and-page-address"
port: ""
protocol: "http:"
search: ""

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.