tzflorida Posted January 11, 2011 Share Posted January 11, 2011 I'd like to pass a value from a URL to an iframe. This would look as follows: URL: http://www.mysite.com?www.mysite2.com The value (www.mysite2.com) will be an actual web address which should then be inserted into an iframe on www.mysite.com via php. Since I know little to no php, I don't know how the URL has to be structured and what php coding I need to use to include the web address in the iframe. Any suggestions are highly appreciated Link to comment https://forums.phpfreaks.com/topic/224090-pass-value-from-url-to-iframe/ Share on other sites More sharing options...
QuickOldCar Posted January 11, 2011 Share Posted January 11, 2011 Here, just made this up for you. I tried to handle if no http or if they type uppercase. <?php function getparsedHost($new_parse_url) { $parsedUrl = parse_url(trim($new_parse_url)); return trim($parsedUrl[host] ? $parsedUrl[host] : array_shift(explode('/', $parsedUrl[path], 2))); } $url = mysql_real_escape_string($_GET['url']); $url_input = mysql_real_escape_string($url); $input_parse_url = strtolower(getparsedHost($url_input)); /*check for valid urls*/ if ((substr($input_parse_url, 0, == "https://") OR (substr($input_parse_url, 0, 12) == "https://www.") OR (substr($input_parse_url, 0, 7) == "http://") OR (substr($input_parse_url, 0, 11) == "http://www.") OR (substr($input_parse_url, 0, 6) == "ftp://") OR (substr($input_parse_url, 0, 11) == "feed://www.")OR (substr($input_parse_url, 0, 7) == "feed://")) { $new_parse_url = $input_parse_url; } else { /*replace uppercase or unsupported to normal*/ $clean_url .= str_replace(array('feed://www.','feed://','HTTP://','HTTP://www.','HTTP://WWW.','http://WWW.','HTTPS://','HTTPS://www.','HTTPS://WWW.','https://WWW.'), '', $input_parse_url); $new_parse_url = "http://$clean_url"; } if (!isset($_GET['url'])) { $new_parse_url = "http://www.google.com"; } ?> <div align="center">; <form action="" method="get"> Insert url: <input type="text" name="url" value="<?php echo $new_parse_url;?>" class="text" style="width:480px; height:25px;" /> <input type="submit" value="Go" class="button" style="width:80px; height:30px;" /> </form> </div> <iframe src ="<?php echo $new_parse_url;?>" width="100%" height="500"> <p>Your browser does not support iframes.</p> </iframe> Link to comment https://forums.phpfreaks.com/topic/224090-pass-value-from-url-to-iframe/#findComment-1158049 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.