Ad:
 
  • PHP Discussion Thread
  • Unsolved
  • Views: 2675
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Similar Threads
Oct 22nd, 2009
0

[ASK] get parent url in iframe

Expand Post »
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 Syntax (Toggle Plain Text)
  1. <?php
  2. //iklan.php
  3. if($_GET['klik'] == 'yes')
  4. {
  5. //klik process
  6. exit;
  7. }
  8.  
  9. $some_content = '
  10. document.write('<iframe src="www.domain1.com/ads.php">
  11. <a href="www.domain1.com/ads.php&klik=yes">klik_link</a>
  12. </iframe>');
  13. ';
  14. echo $some_content;
  15. ?>

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

PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <script type="text/javascript" src="www.domain1.com/ads.php">
  6. </script>
  7. </body>
  8. </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['HTTP_REFERER'] and $_SERVER['SERVER_NAME'] 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sIpIt_nya is offline Offline
5 posts
since Apr 2009
Oct 22nd, 2009
0

Re: [ASK] get parent url in iframe

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
Reputation Points: 13
Solved Threads: 6
Light Poster
kaion is offline Offline
34 posts
since Apr 2009
Oct 22nd, 2009
0

Re: [ASK] get parent url in iframe

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 Syntax (Toggle Plain Text)
  1. <?php
  2. //iklan.php
  3. if($_GET['klik'] == 'yes')
  4. {
  5. //if the klik_link is click the code will back here
  6. echo $_SERVER['HTTP_REFERER'];
  7. //this will print "www.domain1.com/ads.php" which is the src of iframe
  8. //what i want is to get the value of parent url address of the iframe which is "www.domain2.com/test.html"
  9. //what code should i put here so i can get the value?
  10. exit;
  11. }
  12.  
  13. $some_content = '
  14. document.write('<iframe src="www.domain1.com/ads.php">
  15. <a href="www.domain1.com/ads.php&klik=yes">klik_link</a>
  16. </iframe>');
  17. ';
  18. echo $some_content;
  19. ?>

if i have another test2.html located in "www.domain3.com/test2.html" and the source code like this
PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <script type="text/javascript" src="www.domain1.com/ads.php">
  6. </script>
  7. </body>
  8. </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 Syntax (Toggle Plain Text)
  1. <?php
  2. //iklan.php
  3. if($_GET['klik'] == 'yes')
  4. {
  5. //if the klik_link is click the code will back here
  6. echo $_SERVER['HTTP_REFERER'];
  7. //this will print "www.domain1.com/ads.php" which is the src of iframe
  8. //what i want is to get the value of parent url address of the iframe which is "www.domain3.com/test2.html"
  9. //what code should i put here so i can get the value?
  10. exit;
  11. }
  12.  
  13. $some_content = '
  14. document.write('<iframe src="www.domain1.com/ads.php">
  15. <a href="www.domain1.com/ads.php&klik=yes">klik_link</a>
  16. </iframe>');
  17. ';
  18. echo $some_content;
  19. ?>

hope this explanation will describe it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sIpIt_nya is offline Offline
5 posts
since Apr 2009
Oct 22nd, 2009
0

Re: [ASK] get parent url in iframe

Since you want the first page to point to itself then use
PHP Syntax (Toggle Plain Text)
  1. echo $_SERVER['PHP_SELF'];
i guess that should do it but if it doesn't let me know
Reputation Points: 13
Solved Threads: 6
Light Poster
kaion is offline Offline
34 posts
since Apr 2009
Oct 23rd, 2009
0

Re: [ASK] get parent url in iframe

i try it with $_SERVER['PHP_SELF'] but it wont' work.
it just return me "www.domain1.com/ads.php&klik=yes"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sIpIt_nya is offline Offline
5 posts
since Apr 2009
Oct 23rd, 2009
0

Re: [ASK] get parent url in iframe

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
Reputation Points: 13
Solved Threads: 6
Light Poster
kaion is offline Offline
34 posts
since Apr 2009
Oct 23rd, 2009
0

Re: [ASK] get parent url in iframe

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sIpIt_nya is offline Offline
5 posts
since Apr 2009
Oct 23rd, 2009
0

Re: [ASK] get parent url in iframe

got this function for you hope it works

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. function curPageURL() {
  3. $pageURL = 'http';
  4. if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
  5. $pageURL .= "://";
  6. if ($_SERVER["SERVER_PORT"] != "80") {
  7. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  8. } else {
  9. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  10. }
  11. return $pageURL;
  12. }

and you do
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. echo curPageURL();
  3. ?>
  4.  
  5. shalom shalom
Reputation Points: 13
Solved Threads: 6
Light Poster
kaion is offline Offline
34 posts
since Apr 2009
Oct 23rd, 2009
0

Re: [ASK] get parent url in iframe

sorry the last part will print out the page url for you
Reputation Points: 13
Solved Threads: 6
Light Poster
kaion is offline Offline
34 posts
since Apr 2009
Oct 23rd, 2009
0

Re: [ASK] get parent url in iframe

let me if that helps
Reputation Points: 13
Solved Threads: 6
Light Poster
kaion is offline Offline
34 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Voting issue
Next Thread in PHP Forum Timeline: How to make automatic user profile pages after registration?





About Us | Contact Us | Advertise | Acceptable Use Policy
Build Custom RSS Feed


Follow us on Twitter


© 2010 DaniWeb® LLC