Koala
Koala

Reputation: 5523

Set iframe location as the location in the $_GET element

How can I set an iframe src as the location in the $_GET properly.

Currently i'm trying this:

.htaccess

RewriteRule ^stream/(.*)$ index.php?p=stream&link=$1

stream.php/http://bbc.co.uk

<?php
echo '    
<div class="container" style="height:1000px;">
<iframe src="'.$_GET['link'].'" frameborder="0" width="100%" height="100%"></iframe>
</div>
 ';

?>

This sets the iframe to go to 127.0.0.1/stream/http://bbc.co.uk when it should just go to bbc.co.uk

Upvotes: 1

Views: 102

Answers (4)

Koala
Koala

Reputation: 5523

I fixed this using preg_replace

Probably not the best option, however it did work.

<?php
$link = preg_replace('~http:/~si', '', $_GET['link']);
echo '    
<div class="container" style="height:1000px;">
<iframe src="http://'.$link.'" frameborder="0" width="100%" height="100%"></iframe>
</div>
 ';
?>

Upvotes: 0

MrLore
MrLore

Reputation: 3780

As I indicated in my comment, you need to rewrite php files to remove the .php so that the rule you posted matches, e.g.:

RewriteRule (\w+).php $1
RewriteRule ^stream/(.*)$ index.php?p=stream&link=$1

Which means your link will be re-written as so:

http://example.com/stream.php/http://bbc.co.uk
http://example.com/stream/http://bbc.co.uk
http://example.com/index.php?p=stream&link=http://bbc.co.uk

Then your php will output:

<div class="container" style="height:1000px;">
<iframe src="http://bbc.co.uk" frameborder="0" width="100%" height="100%"></iframe>
</div>

Which works as expected.

Upvotes: 1

Dinesh G
Dinesh G

Reputation: 242

Simply try this

RewriteRule ^stream/(.+)$ index.php?p=stream&link=$1  [L,QSA]

I hope this will hep you.

Upvotes: 0

abhinsit
abhinsit

Reputation: 3272

The url itself is not correct ie. it should have been in the form

stream.php?link=http://bbc.co.uk

Then you will get it in:

 $_GET['link']

Other way would be store a mapping of the above get variable with the corresponding url:

ie.

var urlsMapping = {"bbc":"http://bbc.co.uk","toi":"http://timesofindia.indiatimes.com"}

Then make your url like:

stream.php?link=bbc

Set iframe src as

urlsMapping[<?=$_GET['link']?>]

Upvotes: 0

Related Questions