php - iframe not loading properly -


i loading page in iframe. code using:

file: iframe_load.html

<?php echo 'url = '.$_request['url']; ?> <iframe width="1015px" id="article_frame" src="<?php echo $_request['url']; ?>" style="border:0 none;"  height="576px" sandbox="allow-scripts"></iframe> 

in browser if browse url:

http://mywebsite.com/iframe_load.html?url=http://www.northjersey.com/r?19=961&43=515347&44=234450391&32=4497&7=309037&40=http%3a%2f%2fwww.northjersey.com%2fnews%2fsecret_bunker_under_prague_hotel_opens_to_public_.html&nid=4306612

then $_request['url'] showing value partially. iframe not showing actual page content. please me.

enter image description here

let me simplify url demonstration purposes:

http://yoursite.com/iframe_load.html?url=http://theirsite.com/index.php?a=1&b=2

notice website's url contains query string (index.php?a=1&b=2) well. because url contains &, how php splits string:

  1. url=http://theirsite.com/index.php?a=1 &
  2. b=2

as see, url holds part of url, not complete url (because split &).

the & sign 'breaks' url soon, have replace doesn't break url.

you must pass iframe_load.html encoded url, prevent php mis-interpreting url:

http://yoursite.com/iframe_load.html?url=http%3a%2f%2ftheirsite.com%2findex.php%3fkey1%3dval1%26key2%3dval2

(see part after iframe_load.html?url= doesn't contain ? or & anymore)

if link iframe_load.html page, can use php's function urlencode() you:

some page links iframe_load.html

<?php // create variable url // normal url, encode later, when echo it. $other_websites_url = 'http://theirsite.com/index.php?key1=val1&key2=val2'; ?>  <a href="http://yoursite.com/iframe_load.html?url=<?php echo urlencode($other_websites_url); ?>">click go iframe_load.html</a> <?php //                                                     ^ see, here urlencode url, before paste inside our own url. 

using urlencode(), special characters in url (such &) changed html entities, (temporarily) loose meaning, , don't break url. don't worry, url decoded when access in iframe_load.html, you'll have correct url iframe.

this website's url looks when it's encoded: http%3a%2f%2ftheirsite.com%2findex.php%3fkey1%3dval1%26key2%3dval2

as can see, & has been replaced %26, , other characters have been replaced well. can paste url:

http://yoursite.com/iframe_load.html?url=http%3a%2f%2ftheirsite.com%2findex.php%3fkey1%3dval1%26key2%3dval2

because url of other website doens't contain & anymore, php won't split url.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -