iframe GET url variable - php

I'm trying to give the users of my website the option to externally embed an html5 player , and in order to do that I thought of putting a value in the iframe's src by reading it from the parent page, then passing it as a variable in the php file which will be shown to the user.
Let's say that
$value_from_parent_page = "song1"
and parent page contains copy-able code for the users
<iframe src="http://example.com/load.php?embed='$value_from_parent_page'" ></iframe>
The load.php contains
<?php
$val  =  $_GET['embed'];
echo "<audio src='"$val".mp3'></audio>";
?>
The result has to be like
<audio src='song1.mp3'></audio>
Is it possible to work like that and is the code valid? (i apologise I don't have access to normal computer to test).
Thanks in advance.

This should work, and is valid, now the issue of using an iframe would be well, make sure that it is an iframe you need as there are probably better ways of going about this, but in your scenario i would say this is the best way to do it and valid for best cross platform support.

Related

I am trying to embed global session variables with url using iframe

I am trying to embed session variables to url that are set by another module in drupal 7.When i try to make an iframe the iframe works but my session variables are not embedded with url.
Any help will be much appreciated.i also checked sessions using devel modules session viewer they are shown there.
Here is the code that i am using in the iframe content type.
<iframe src="http://www.w3schools.com?"$_SESSION['name']""></iframe>
actully im not aware about drupal but i think this will work
<iframe src="http://www.w3schools.com?sname='"<?php echo $_SESSION['name']; ?>"'"></iframe>
please try this
$_SESSION['name'] shoud be
You need to add php code tag for php code.
Always use for dyanmic codde
i am not drupal developer but in this iframe php syntax is not proper. concatenation is missing .
<iframe src="http://www.w3schools.com?"<?php echo $_SESSION['name'];?>""></iframe>
please try this.

file_get_contents not returning entire webpage

I've been trying to retrieve the contents of a webpage (http://3sk.tv) using file_get_contents. Unfortunately, the resulting output is missing many elements (images, formating, styling, etc...), and just basically looks nothing like the original page I'm trying to retrieve.
This has never happened before with any other URLs I have tried retrieve using this same method, but for some reason, this particular URL (http://3sk.tv) refuses to work properly.
The code I'm using is:
<?php
$homepage = file_get_contents('http://3sk.tv');
echo $homepage;
?>
Am I missing anything? All suggestions on how to get this working properly would be greatly appreciated. Thank you all for your time and consideration.
Thats normal behaviour, as you are only grabbing the file, and not related images, stylesheets etc...
I have one quick workaround to fix relative paths
http://www.w3schools.com/tags/tag_base.asp
Just add to your code <base> tag.
<?php
$homepage = file_get_contents('http://3sk.tv');
echo str_replace(
'<head>',
'<head><base href="http://3sk.tv" target="_blank">',
$homepage
);
?>
It's should help.
This is to be expected. If you look at the source code, you'll notice many places which do not have a full URL (ex lib/dropdown/dropdown.css). This tells the browser to assume http://3sk.tv/lib/dropdown/dropdown.css. However, on your website, it will be YOURURL.COM/lib/dropdown/dropdown.css, which does not exist. This will be the case for much of the content.
So, you can't just print another website's source and expect it to work. It needs to be the same URL.
The best way to embed another website is usually to just use an iframe or some alternative.
The webpage is not completely generated server-side, but it relies heavily on JavaScript after the HTML part loads. If you are looking for rendering the page as it looks in browser, you may need a headless browser instead - see e.g. this binding to PhantomJS: http://jonnnnyw.github.io/php-phantomjs/

php open dynamic link in new window with iframe

Hello I am trying to figure out how to make it so when someone clicks a link on my search results it will open in a new window and in the new window have an iframe that displays the url. I am not sure how to go about doing this. I have
$row['url']
that displays the url for each result to use.
To be more specific I am trying to do what filestube does. I like the feature a lot and would like to use something like it on my site. Here is an example url to show you want I mean http://www.filestube.com/5a4c10249bd9fce003e9/go.html
when the link is clicked on filestube it will open a page like this. I have seen lots of sites do this but filestube is what pops in my head right now. Can anyone provide me with a code example or try to explain how to do this? thanks.
You need to redirect to a URL inside of your application, example my_url.php and post to it in parameters the URL you want to show. Than in that script, load an iFrame with that URL.
Example of my_url.php?url=http://www.google.ca:
<div>You Header</div>
<iframe src="<?php $_GET['url']"></iframe>
<div>Your Footer</div>
The link should point to another PHP page. Something like this.
http://www.google.com
In your open-link.php, write your iframe code.
<iframe src="<?=$_GET['url']?>"></iframe>
Assuming you have PHP file named external.php
Make that PHP file accept a $_GET parameter.
Pass the URL as a param
Use that URL to point the iframe in that PHP file to whatever URL is passed

How can I redirect using a PHP script called from an SSI?

On a WAMP server, I have a server-side include in a file, a.shtml, composed of the following code:
<!--#include virtual="./req.php"-->
The contents of req.php are:
<?php
Header("Location:index.php");
echo "still here";
?>
When I open a.shtml, I see the text still here, but the page has made no attempt to redirect itself. Why is this? And is there any way to make it work?
Thanks for the help
EDIT: The reason I want to do this is because I have some session variables that I want to influence the way the PHP script acts. If the session variables are not set, I need it to redirect to a login page. I know I can just write the entire thing in PHP, but I'd like to do it this way if possible. If it's not possible to change header information from an included PHP file from SSI, then I'll just do it entirely in PHP.
it's impossible
you don't need that.
just address tour script that set session variables directly, not through ssi
MAYBE (with capital letters Lol), you can pull this off if you call that script in an IFRAME and that IFRAME outputs some JScript like window.parent.location = <some_url_here> forcing its parent to change its location... Its just fast-thinking from my part, I might be wrong with IFRAMEs' parent-child relation to the original document, as I haven't tested the "idea" myself :)
If your req.php returns the following html code, the redirect will happen:
<html><head>
<title>HTTP 301 This page has been moved</title>
<meta http-equiv="Refresh" content="0;URL=https://www.example.com/index.php">
</head>
<body></body></html>
But: "Google Warning: Using The Meta Refresh Tag Is Bad Practice"

Load page within the page

I'm a beginner in PHP and Javascript..
I found a link from http://cmichaelis.whsites.net/whblog/jquery-extjs-1/example2
Inside it there is a code saying :
function addPanel(location)
{
tabpanel.add({
autoLoad: {url: location},
title: 'More Information...',
closable:true,
autoScroll:true
}).show();
}
how to use :
<a href="javascript:void(0);"
onclick="addPanel('loadpage.php?a=http://www.google.com')">
head over to Google
</a>
What I want to ask is.. what is the code for loadpage.php?
The PHP page does not echo out the contents of google.com as suggested in the other answer. It outputs an iframe that points to Google:
<iframe src="http://www.google.com" width="100%" height="100%" frameborder="no"></iframe>
It looks like loadpage.php could be in use to echo out the contents of www.google.com, using file_get_contents.
loadpage.php:
<?php
// Simplified output - should sanitise $_REQUEST params etc first..
echo file_get_contents($_REQUEST['a']);
?>
loadpage is effectively acting as a proxy, allowing your javascript to call pages which are not on your own domain.
As #annakata points out in the comments, the code above is obscenely dangerous as-is. The code is an illustration of the basic idea behind a proxy file - in production, this file would need to make sure that the $_REQUEST parameters were sanitised, e.g. only accept values from a whitelist.
The same origin policy is a security element of javascript that stops you from pulling content from outside your domain on to your page using javascript.
Some sites get around this by calling a proxy page on their own server (loadpage in this instance) which effectively just prints out the content of a target url. As this proxy page is on your server, this by-passes the same origin security issue, and still makes available the content of a page from another domain - here www.google.com
Oops, I somewhat foolishly didn't RTFA, but just the code in the question and hypothesised at what it could be doing. #andynormancx is right in his answer as to what the page linked in the q is actually doing.

Categories