Jump to content

[SOLVED] Grab webpage URL from Iframe


allex01

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.