Can A PHP Page Knows Who's Linking To Itself?

free web hosting
Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Can A PHP Page Knows Who's Linking To Itself?

whistle
Some webpage with frames that each can be assigned to link to an url path, i.e. http://a.domain/test.php. When webpage A is requested by a browser, another webpage B containied in the frame of webpage A will be queried too.

As we know, a phpinfo() can tell us the information about the url of the webpage we get or post. When a webpage "B" is requested by the get or the post from a frame, can webpage B know the url where the webpage A locates?

I hope to know that because I wich webpage B can only be used in the frame of webpage A. If anyone request it directly, the webpage B return a something else.
For example, if someone save webpage A in his harddisk, the url of the saved page will not be the original one where the webpage A is. Thus webpage B won't be shown correctly in the frame of the saved webpage.

Can anyone tell me whether webpage B can know the url of webpage A? And how?
Or is there any other way to reach the same objective?

Reply

calixt
QUOTE(whistle @ Aug 10 2005, 08:40 AM)
...Can anyone tell me whether webpage B can know the url of webpage A? And how?
Or is there any other way to reach the same objective?
*


whistle,

if I understood you right, you can use javascript to reach your objective.
Example:
Page A (iframe_a.html)
CODE
<html><head><title>Mainpage</title></head>
<body><h2>Mainpage</h2>
<iframe src="iframe_b.html" style="width:80%; height:50%"></iframe>
</body></html>

Page B (iframe_b.html)
CODE
<html>
<head><title>iFrame</title>
</head>
<script language="javascript">
document.writeln("Calling page (link): "+parent.location.href+"<br />");
document.writeln("Calling page (host): "+parent.location.hostname+"<br />");
document.writeln("Calling page (path): "+parent.location.pathname);
</script>
<body>...</body></html>


Just compare your.domain to parent.location.hostname to decide what to do with the page request
If parent.location.pathname has "iframe_b.html" then the iframe has been called directly.

Hope this is what you meant
calixt

 

 

 


Reply

Hercco
A PHP page can know from which page th euser came into it, ie. in which page the link was located when the user clicked it.

Browsers send the pages address in the HTTP request, it is labeled HTTP referer and you can read it from the HTTP_REFERER global variable. ($_SERVER['HTTP_REFERER']wink.gif

There is a slight problem however... As the information is dependent on the browser, it is not always reliable, someone can easily send fake HTTP requests with bogus referers and some browsers and firewalls block the referer sending.

So be careful when using HTTP_REFERER.

Reply

whistle
Hi, calixt:
I do test your example as following:

QUOTE(calixt @ Aug 10 2005, 05:09 PM)
Example:
Page A (iframe_a.html)
CODE
<html><head><title>Mainpage</title></head>
<body><h2>Mainpage</h2>
<iframe src="iframe_b.html" style="width:80%; height:50%"></iframe>
</body></html>

Page B (iframe_b.html)
CODE
<html>
<head><title>iFrame</title>
</head>
<script language="javascript">
document.writeln("Calling page (link): "+parent.location.href+"<br />");
document.writeln("Calling page (host): "+parent.location.hostname+"<br />");
document.writeln("Calling page (path): "+parent.location.pathname);
</script>
<body>...</body></html>


Just compare your.domain to parent.location.hostname to decide what to do with the page request
If parent.location.pathname  has "iframe_b.html" then the iframe has been called directly.
*



Finally, I get see a blank iframe and there is no desirable output. My example is http://reurl.net/see/test.htm. I just know javascript a little. May you give me more detail or tell me what's wrong with it? Than you.

Reply

whistle
QUOTE(Hercco @ Aug 10 2005, 10:26 PM)
A PHP page can know from which page th euser came into it, ie. in which page the link was located when the user clicked it.

Browsers send the pages address in the HTTP request, it is labeled HTTP referer and you can read it from the HTTP_REFERER global variable. ($_SERVER['HTTP_REFERER']wink.gif

There is a slight problem however... As the information is dependent on the browser, it is not always reliable, someone can easily send fake HTTP requests with bogus referers and some browsers and firewalls block the referer sending.

So be careful when using HTTP_REFERER.
*



Thank you. I do test the HTTP_REFERER, it does show the right url of the webpage link to it. I have tried the $_server variable, there is no string containing "HTTP_REFERER". You give me the exact way to do the right thing. Thank you very much.

Reply

whistle
QUOTE(whistle @ Aug 12 2005, 02:10 AM)
Hi, calixt:
  I do test your example as following:
Finally, I get see a blank iframe and there is no desirable output. My example is http://reurl.net/see/test.htm. I just know javascript a little. May you give me more detail or tell me what's wrong with it? Than you.
*



After I save the webpage as a file in my harddisk, and open the saved file. It shows as following

Calling page (link): file:///C:/Documents%20and%20Settings/1/My%20Documents/test.htm
Calling page (host):
Calling page (path): /C:\Documents%20and%20Settings\1\My%20Documents\test.htm ...

I have to mention one think, I use the os version is tranditional Chinese. So some chinese words are cover to be the strings with "%".

It is strange, the same code in the web server shows nothing. However, the right contents can be shown in a local saved file. Can anyone tell me why? I do care about "why", not only the solusion. Thanks.

Reply

calixt
QUOTE(whistle @ Aug 11 2005, 08:10 PM)
Hi, calixt:
  I do test your example as following:
Finally, I get see a blank iframe and there is no desirable output. My example is http://reurl.net/see/test.htm. I just know javascript a little. May you give me more detail or tell me what's wrong with it? Than you.
*


Hi whistle,
when the source of the iframe does not belong to the same host as the main page, it will not have access to the "parent" object. This policy shall prevent cross site scripting.
Anyway, for your purposes it does not make any difference: If parent.location.href is not "http://reurl.net/see/test.htm" then the iframe src has not been called by the proper page.

Of course you can try to use $_SERVER["HTTP_REFERER"] but this can be faked as Hercco already mentioned. But if $_SERVER["HTTP_REFERER"] is not set then the iframe source surely has NOT been called by your Page A, and that is exactly the information you need, if I understood you right.
Greetings from Nuremberg (Germany),
C.

Reply

whistle
QUOTE(calixt @ Aug 12 2005, 03:25 AM)
Hi whistle,
when the source of the iframe does not belong to the same host as the main page, it will not have access to the "parent" object. This policy shall prevent cross site scripting.
Anyway, for your purposes it does not make any difference: If parent.location.href is not "http://reurl.net/see/test.htm" then the iframe src has not been called by the proper page.
*



Thank you. You have clearly answer me what I hope to know. Now I see and learn a lot. You do really understand what I say although I use a poor English. Thanks again.

Reply

JUDGE_RELIC
I was going to my nickles worth but it's just restating what has already been posted... good job guys!

Reply

aria
If you anytime want to know any data in any array(eg. $_SERVER)you should use:
<pre>
<?php echo var_dump($_SERVER); ?>
</pre>

or maybe my own little code bit:

<?php
foreach($_SERVER $a AS => $b){
echo htmlentities($a)." <b>:</b> ".htmlentities($b)."<hr>";
}
?>

Note: I have'nt test the script!

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. php $_server parent frame - 42.59 hr back. (2)
  2. php get page name parent iframe - 99.77 hr back. (1)
  3. how to post a page to itself in php - 139.55 hr back. (1)
  4. iframe get own hostname javascript - 209.50 hr back. (1)
  5. php calling another webpage - 230.52 hr back. (1)
  6. php faking http_referer - 233.69 hr back. (1)
  7. php check "page in iframe" - 251.40 hr back. (1)
  8. php page name referer - 277.65 hr back. (1)
  9. ie iframe call php page - 326.38 hr back. (1)
Similar Topics

Keywords : php, page, whos, linking

  1. Who's Logged In?
    I know how to start.. but not how to end.. (4)


      Looking for php, page, whos, linking






*SIMILAR VIDEOS*
Searching Video's for php, page, whos, linking
advertisement




Can A PHP Page Knows Who's Linking To Itself?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE