Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/132100-solved-grab-webpage-url-from-iframe/
Share on other sites

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..

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

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.

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.

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'];

 

 

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.

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.

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>

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.

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 =)

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.