I have a proble in getting parent url address in iframe from my project.

so, i have let's say ads.php located in www.domain1.com/ads.php
it's look like this

<?php
//iklan.php
if($_GET['klik'] == 'yes')
{
    //klik process
    exit;
}

$some_content = '
	document.write('<iframe src="www.domain1.com/ads.php">
	<a href="www.domain1.com/ads.php&klik=yes">klik_link</a>
	</iframe>');
	';
echo $some_content;
?>

and then i have test.html located in www.domain2.com/test.html that look like this

<html>
<head>
</head>
<body>
<script type="text/javascript" src="www.domain1.com/ads.php">
</script>
</body>
</html>

my question is, how can i get the value of url address frame parent which is "www.domain2.com/test.html" in my ads.php file.

i already try $_SERVER and $_SERVER but i got me "www.domain1.com/ads.php" which is the src of my iframe.

i also try with javascript "parent.location.href" but failed, because it's only work if the domain is the same.

anyone has a solution? been struggling with this in this 2 day. :(

sorry i tried reading this over n over but i just couldn't get what you meant can you please try expatiating on what you really want that way you can get help

thanks for reply..

the test.html if we run it...
will display a link, if we click that link, it will brought back the ads.php script.

<?php
//iklan.php
if($_GET['klik'] == 'yes')
{
    //if the klik_link is click the code will back here
    echo $_SERVER['HTTP_REFERER'];
    //this will print "www.domain1.com/ads.php" which is the src of iframe
    //what i want is to get the value of parent url address of the iframe which is "www.domain2.com/test.html"
    //what code should i put here so i can get the value?
    exit;
}

$some_content = '
	document.write('<iframe src="www.domain1.com/ads.php">
	<a href="www.domain1.com/ads.php&klik=yes">klik_link</a>
	</iframe>');
	';
echo $some_content;
?>

if i have another test2.html located in "www.domain3.com/test2.html" and the source code like this

<html>
<head>
</head>
<body>
<script type="text/javascript" src="www.domain1.com/ads.php">
</script>
</body>
</html>

it will again display a link "klik_link" and when we click that link it will again bring us back to ads.php on www.domain1.com/ads.php

<?php
//iklan.php
if($_GET['klik'] == 'yes')
{
    //if the klik_link is click the code will back here
    echo $_SERVER['HTTP_REFERER'];
    //this will print "www.domain1.com/ads.php" which is the src of iframe
    //what i want is to get the value of parent url address of the iframe which is "www.domain3.com/test2.html"
    //what code should i put here so i can get the value?
    exit;
}

$some_content = '
	document.write('<iframe src="www.domain1.com/ads.php">
	<a href="www.domain1.com/ads.php&klik=yes">klik_link</a>
	</iframe>');
	';
echo $some_content;
?>

hope this explanation will describe it. :)

Since you want the first page to point to itself then use

echo $_SERVER['PHP_SELF'];

i guess that should do it but if it doesn't let me know

sIpIt_nya can you please do me a favour by telling me what you want to do in plain english without the codes involve and i'll get back to you

i just want to get the parent url address from an iframe inside it.

example :
i have test.html located in www.client-domain.com. this test.html has an iframe, and the source of the iframe is my php file in my domain. let's say ads.php in www.my-domain.com. this iframe in test.html will display a link that if user click that link will redirect to my php file in my domain "www.my-domain.com" also, let's say it's ads-click.php

all wanna do is, how can i grab the url address from the web that display my iframe which is "www.client-domain.com" from my php file ads-click.php

is it clear enough?
sorry for my poor english.

got this function for you hope it works

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

and you do

<?php
  echo curPageURL();
?>

shalom shalom

sorry the last part will print out the page url for you

let me if that helps

your code is not working..
the value is the same with $_SERVER

here the simple code, hope u can fully understand.

first at file "test.html" at "www.client-domain.com"

<html>
<head>
</head>
<body>
<iframe src="http://www.my-domain.com/iframe.php"></iframe>
</body>
</html>

second file "iframe.php" at "www.my-domain.com"

<a href="http://www.my-domain.com/klik.php">klik sini</a>

third file "klik.php" at "www.my-domain.com"

<?php
echo $_SERVER['HTTP_REFERER'];
//this will display http://www.my-domain.com/iframe.php
//all i want is to grab "www.client-domain.com/test.html"
//how can i grab the value?
?>

Hi
Is there any update on this post.
I think the issue has not be resolve yet.
Am also facing the same problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.