allex01 Posted November 10, 2008 Share Posted November 10, 2008 How can i get the url of a webpage from within iframe. For exmaple on the website domain.com i have an iframe loading from xyz.com. When i try the following function $_SERVER['HTTP_REFERER'] from the within the iframe, i get the url of the iframe xyz.com and not the webpage url domain.com. How can i get the URL of the webpage. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/ Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 When I try it, I get the expected referrer. Can you provide the code that produced the result? Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-686627 Share on other sites More sharing options...
allex01 Posted November 10, 2008 Author Share Posted November 10, 2008 I might have forgotten to explain one other important thing, Â The iframe is loading a file from xyx.com/file.php. file.php contain and image with a link that looks like $img What i did was add the following to the $img variable ?id="$_SERVER['HTTP_HOST']; Â When i access the main site domain.com, the iframe loads xyz.com/file.php id is coming up as xyz.com and not domain.com. I want to have grab domain.com in the id not xyz.com. Â I hope my explanation is clear.. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-686991 Share on other sites More sharing options...
rhodesa Posted November 10, 2008 Share Posted November 10, 2008 nope...i don't get it...one more time? Â maybe you can post some code? Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687015 Share on other sites More sharing options...
dropfaith Posted November 10, 2008 Share Posted November 10, 2008 okay im not sure how its done but i think i grasp his idea so i will attempt to lay it out the way i see what hes saying  xyz.com is my site domain.com is someone elses site  xyz.com has an iframe linking to domain.com and he needs it to grab the id from domain.com to the iframe..  so say domain.comfile.php?id=3  that id isnt being transfered over to the iframe on xyz.com Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687026 Share on other sites More sharing options...
allex01 Posted November 10, 2008 Author Share Posted November 10, 2008 I have the domain domain.com on domain.com/index.php i have  <body> <iframe src="http://xyz.com/file.php"></iframe> </body>  file.php which is on xyz.com contains <a href="whatever.com?id=<?php echo $_SERVER['HTTP_HOST'];?>">link</a>  My intention to have id=domain.com. Rather it's grabing xyz.com. $_SERVER['HTTP_HOST']; thinks xyz.com is host and not domain.com. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687051 Share on other sites More sharing options...
allex01 Posted November 10, 2008 Author Share Posted November 10, 2008 Seems to be a real challange. Any ideas. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687267 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 That's because xyz.com is the host, and not domain.com. The code will get the host of the page, the i-frame is just displaying the page from another host, not hosting it. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687289 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 Yes exactly. How can we get the domain.com url. This is the challange. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687299 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 I just told you, you can't, sorry that is written wrong, it should say you have. The code has done what it should of, which is get the page's host. My only suggestion is having a look at some Javascript, as it may be able to do this, but i am not sure it can. But php can't as far as i know. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687302 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 Of course this can be done. it's being done all over the web. The reason for this is to track which site the click is coming from. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687317 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 You are very arrogant after you have been told it can't be done with php , from people who know what they are talking about you still contradict and tell us that it can. Â To find out what site someone is coming from use $_SERVER['HTTP_REFERRER']; Â Â Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687320 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 I'm sorry but i believe you were the only person who replied with "it can't be done". THis is being close minded. Anything can be done with some thinking. I apprciate yoru point of view and replies, but You can ignore this thread if you don't want to read further replies. Hopefully someoen else can share there expertise or point of view. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687329 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Still arrogant, why do you think people haven't replied because it can't be done in PHP. Â And you are wrong in programming the phrase "anything can be done when you put your mind to it" is irrelevant, because in programming there are limits to what can be done. So stop being arrogant and accept the fact that PHP can not do it. You are wasting your time. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687335 Share on other sites More sharing options...
rhodesa Posted November 11, 2008 Share Posted November 11, 2008 you can use HTTP_REFERER or, just pass the host to the iframe: Â <body> <iframe src="http://xyz.com/file.php?id=<?php echo $_SERVER['HTTP_HOST'];?>"></iframe> </body> Â <a href="whatever.com?id=<?php echo $_GET['id'];?>">link</a> Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687336 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 rhodesa this worked Great. Thank you. Hopefully Blade280891 Can learn something from this and not be soo close minded. You only stop learning when you think you know everything. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687351 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 He proved me right, lol, maybe you should learn php before you start pretending you know it. Â He printed the host of your page onto your page, not onto the page in the i-frame like you wanted. Then he printed it from the i-frame onto there page in it. Â If you asked how to do that then i would of shown you, maybe next time be clearer on what you want. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687353 Share on other sites More sharing options...
premiso Posted November 11, 2008 Share Posted November 11, 2008 Just a side note, how other sites do it is with javascript and an image.  Check out stat tracking sites, always javascript with an image. That may be the way to go to allow this code to work without php. I am sure you can find a free script that does it at http://javascript.internet.com  Just a suggestion =) Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687356 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 Blade280891, learning php is something and applying is something else. No everyone that have the lumber and tools can build a house even if you know how to use the tools. I was asking for a way to do it and You just asnwered it can't be done and you called me arrogant. If i knew how to do it i wouldnt be using this forum. I also never said i wanted to print the host in iframe. You just assumed it. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687357 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 you can use HTTP_REFERER or, just pass the host to the iframe: Â <body> <iframe src="http://xyz.com/file.php?id=<?php echo $_SERVER['HTTP_HOST'];?>"></iframe> </body> Â <a href="whatever.com?id=<?php echo $_GET['id'];?>">link</a> Â Althought this works great, if a user pasted the iframe code in a non .php page the <?php ?> will never get executed. This code is for a widget i'm building where users copy and paste the code on there site. Maybe javascript would be the best way to go at it as premiso mentioned. Anyone insights about how this can be achieved using javascript would be great. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687390 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Lol. Â This is a PHP forum, if you want javascript help ask in the JS forum. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687394 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 I dont' want to open duplicate thread on the forum for the same topic. If admin wants to move this question to the javascript section. That is fine. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687399 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Here <script> host = window.location.hostname; locat = "http://xyz.com/file.php?id=" locat = locat+host; document.getElementById('i_frame').src = locat; </script> <iframe id="i_frame" src=""></iframe> Try that Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687404 Share on other sites More sharing options...
DeanWhitehouse Posted November 11, 2008 Share Posted November 11, 2008 Solved? Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687421 Share on other sites More sharing options...
allex01 Posted November 11, 2008 Author Share Posted November 11, 2008 Thanks Blade, but the code as you have it does not work. Must be something missing there. Nothing shows in the iframe now. Quote Link to comment https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/#findComment-687425 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.