Jump to content

Recommended Posts

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

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>

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.