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
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.
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']?>]
Simply try this
RewriteRule ^stream/(.+)$ index.php?p=stream&link=$1 [L,QSA]
I hope this will hep you.
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>
';
?>
Related
So I'm using PHP to grab my profile picture from my steam profile and i want to display it on the page is there any way to pass the variable containing the picture to html or edit my html code from PHP???
here is my code
<?php
$pic_path = file_get_contents("http://steamcommunity.com/id/LocalSugarDaddy");
preg_match('/<div class="playerAvatarAutoSizerInner"><img src="(.*)" \/><\/div>/i', $pic_path, $pic);
?>
I guess you are trying to use PHP variable containing image URL and want to use in html tag. If so, then you can do below:
<?php
$your_picture_str = "http://www.domainname.com/picture_url.jpg";
?>
<div><img src="<?php echo $your_picture_str; ?>" width="100%" alt="" title="" /></div>
In this little snippet of code ,i show how i take the "foto1" column of my database and transfer the value of it to a variable in c# named $foto.
The $foto contains the path of the image corresponding to the product that is showing up. Ive tried to copy and paste the path and ditch out the php part and it works. But when i put it in img src it gives me like the broken image thing.And i cant figure out why it does that.
All help is aprecciated .
Have a nice day :)
<div class="row shop_box-top">
<?php
$ligaBD=odbc_connect('basededadospap','','');
$sql="SELECT * FROM produto WHERE nome_produto LIKE '%ADIDAS%'";
$resultado=odbc_exec($ligaBD,$sql);
?>
<div class="row shop_box-top">
<?php
while (odbc_fetch_row($resultado))
{
$nome = odbc_result($resultado,2);
$preco= odbc_result($resultado,4);
$foto = odbc_result($resultado,9);
?>
<div class="col-md-3 shop_box"><a href="stansmithflatwhite.html">
<img src="<?php echo $foto; ?>" class="img-responsive" alt=""/>
<span class="new-box">
<span class="new-label">Novo</span>
</span>
<div class="shop_desc">
<h3><?php echo $nome; ?></h3>
<span class="actual"><?php echo $preco; ?></span><br>
</div>
</a></div>
<?php }?>
depends of what path contains the $foto var. If is the absolute path, you have to retrive the relative path.
Try also to append an / or an http[s] in front of the path
<img src="/<?php echo $foto;?>">
So it would be : //path/to/photo
As I can see it in your comment, your image paths contain spaces, so a possible solution can be to use urlencode() before echoing them.
Try passing full path to img tag like http://localhost/xyz/images/Cal�ado/Adidas/Homem/Stan Smith/ADIDAS STAN SMITH - RED/ch-adidas-stan-smith-red-5.jpg.
Replace "localhost/xyz" with your website directory path.
I want to keep src attribute in a variable. I am working on php and tried the following method but it doesn't display the image on html page.
Code:
<?php $path="C:/horizontal.jpg"; ?>
<image src="<?php echo $path; ?>" style="width:304px;height:228px" />
I think you can use this technique:
<?php $path="http://" . $_SERVER["SERVER_NAME"];?>
<img src="<?php echo $path.'/projectName/image.jpg'; ?>" style="width:304px;height:228px" />
Where:
$_SERVER["SERVER_NAME"]: to get the server name, for example: www.example.com.
Also you can use $_SERVER["SERVER_ADDR"], in this case you can get the address IP of your server, for example: "127.0.0.1".
I hope this information helps you.
Good Luck.
<?php $path="localhost/projectName/";?>
<img src="<?php echo $path.'image.jpg'; ?>" style="width:304px;height:228px" />
Hi I want to convert pages URL like www.example.com/pictures.php?title=yyoy to something like www.example.com/page/yoyo.php
How can I do this?
www.example.com/pictures.php?title=yyoy these pages are generated when someone upload image to my website so I want to turn these types of URL to like above shown example.
Because these pages can't be index in search engines. Thanks
Picture.php
<?php
include("connection.php");
if(isset($_GET['title'])){
$page_id = $_GET['title'];
$select_query = "select * from save_data where Title='$page_id'";
$run_query = mysql_query($select_query);
while($row=mysql_fetch_array($run_query)){
$post_id = $row['ID'];
$post_title = $row['Title'];
$post_image = $row['Name'];
$page_title = $_GET['title'];
header('uploads/ ' . $page_title . '.php')
?>
<center>
<h2>
<a href="pictures.php?title=<?php echo $post_title; ?>">
<?php echo $post_title; ?>
</a></center>
</h2>
<center><img src="uploads/<?php echo $post_image; ?>" /></center>
<?php } }?>
I have not tested this, but you should use rules similar to the following in your .htaccess file:
RewriteEngine on
RewriteRule ^pictures.php?title=(.+)$ page/$1.php [R]
Note that, you will need mod_rewrite enabled for this to work in apache2
There's a good answer here: Masking $_GET variables of the URL when passing pages in PHP
That will tell you how to mask your URLs.
Alternatively, you could have these files uploaded to a directory in your file structure called "page/" Then you can access the files (as a download) inside the page directory with www.example.com/page/filename.php
Usually I would create an in-between page when posting from a form, but in your case your link looks like this:
www.example.com/pictures.php?title=yoyo
So it directs you to pictures.php with a variable 'title' in the URL.
So on your pictures.php page use:
$page_title = $_GET['title'];
And when you want to go to yoyo.php:
header('Location: $page_title.php')
From your edit this code will redirect the page but it will not display the last HTML:
<?php
include("connection.php");
if(isset($_GET['title'])){
$page_id = $_GET['title'];
$select_query = "select * from save_data where Title='$page_id'";
$run_query = mysqli_query($select_query);
while($row=mysqli_fetch_assoc($run_query)){
$post_id = $row['ID']; //Just make sure the values between [''] match -
$post_title = $row['Title']; //your columns in database.
$post_image = $row['Name'];
}
header('Location:uploads/$post_title.php');
?>
This will be left out:
<center>
<h2>
<a href="pictures.php?title=<?php echo $post_title; ?>">
<?php echo $post_title; ?>
</a></center>
</h2>
<center><img src="uploads/<?php echo $post_image; ?>" /></center>
<?php } }?>
URE This one
RewriteEngine on
RewriteRule ^pictures.php?title=(.+)$ page/$1.php [R, L]
You should use the .htaccess file. Add this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^picture/([a-zA-Z0-9]+).php$ pictures.php?title=$1
</IfModule>
If you're using a local server like WAMP, be sure to turn on de mod_rewrite or rewrite_module of apache and reboot the server.
You should also Google for Regular Expressions.
Let me know if it was useful.
i want to have an iframe, which displays the page given as parameter in the url.
I'm using ASP.NET MVC4
so I wanna do something like this:
updated it... but still not right i think
<?php
if(!isset($_GET['link']){
$link = $_GET['link'];}
?>
<iframe name="inlineframe" src="<?php $link ?>" frameborder="0" scrolling="auto" width="500" height="180" marginwidth="5" marginheight="5" ></iframe>
but i can't figure out the right code for this. can anyone help?
I also tried echoing php, but that doesnt seem to work for me.
The problem with your code snippet is this:
src="<?php $link ?>"
You're calling the variable, but doing nothing with it
To write the variable in the src attribute, use echo:
src="<?php echo $link ?>"
You should also remove the ! in your if statement
Try this:
<?php
$link = '';
if(isset($_GET['link']){
$link = $_GET['link'];
}
?>
Also echo your link variable.
src="<?php echo $link; ?>"