Extracting the source of a Javascript in a page with PHP - php

I am trying to find an embedded stream link from a page. When I check for the source code of that page it returns something similar to below:
<script type='text/javascript'> swidth='640', sheight='460';</script>
<script type='text/javascript' src='http://www.sawlive.tv/embed/hqfootyerech1'></script>
This also returns code like:
http://sawlive.tv/embed/watch/xxxxxxx_
I have tried with file_get_contents to crawl to http://www.sawlive.tv/embed/hqfootyerech1 but it does not return anything.
The page only loads from http://myiframe12.altervista.org/
Is there a way to get the full source code of the page including the embedded page and script? I can inspect the elements loaded on that page with Firefox, but the source codes are different.
I have heard of Selenium2. But no idea how it works either.

You should use file_get_content.
There is a difference if you call it with http or a path to your file.
If you wish to get the source code you should write:
file_get_contents('path/to/YOUR/FILE.php');
You probably called a file with it's URL which is different, if you use http u can only see the ouput of the PHP script, so use the path.
I don't think you can access the source code of a file not on your domain, but i'm not sure about that.
*EDIT : *
In case this dosen't work, i found this code, not tested but should work too :
ob_start();
include "yourfile.php";
$myvar = ob_get_contents();
ob_end_clean();

Related

What should a server-side script contain in order for file_get_contents() to work on the client side?

For the first time ever I've tried to use file_get_contents() in a file (index.php):
echo $globalIP=file_get_contents("tools.php");
The contents of tools.php, for the time being, is as follows:
<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo $ip;
?>
but when I run index.php it doesn't display anything at all.
Peculiarly, all info on the Internet about file_get_contents() pertains to the client side rendering, and not about what the server-side script should contain. I also experimented with stream_context_create() in tools.php to no avail.
By the way, the idea is to replace the URL in
$globalIP=file_get_contents("http://bot.whatismyipaddress.com");
with my own script. Whatismyipaddress returns a string containing the IP, nothing else, which is what I am looking for.
The answer was much more straightforward:
If a relative link is used, the php code of the actual file is displayed: file_get_contents("tools.php")!!!!
In order for it to work a full URL is needed, in my case:
file_get_contents("http://localhost/tools.php");

Source code of my website is different than that shown by firebug

Recently one of my client website was hacked When I checked the source code of the website it was fine(No such hacking information was there),
But when I checked the same with firebug it was showing different i.e hacked code with some iframes,
Then I tried to use file_get_content() function to display the index page which was displayed as hacked but when I tried to check the source of the website with file_get_content() again no such hacking information was there.
In such scenrio how i can get the actual source of the webpage in PHP
I would Suggest Using
FTP
to the source documents or find the source documents on your own server and use an editor to look for the bad code.
If you don't have FTP access or access to the source files then you need to get that access.
I use
FileZilla FTP Client
I know this Doesn't Help In Your Question But There Could Be More Wrong With Source Files then some simple IFrames.
If you still don't see any Problems With The Source Files Then There Most Likely Isn't Anything In That File And Not Added Somewere else with:
include 'file.php';
or
require_once 'file.php';
To Use PHP file_get_contents please refer to http://php.net/manual/en/function.file-get-contents.php
You could run a search:
$text = file_get_contents('http://test.com/home.html');
if(strpos($text, "<IFrame")!==false)
{
echo('IFrame found');
}
else {
echo('IFrame Not found');
}
Or
if(preg_match('/^<iframe /',$text)){
echo 'That has an iframe using Regular Expressions!!';
}
If that still doesn't help then always use a backup system when done with a change back up. Restore A Back up of said site or files see if that helps.

PHP - file_get_contents follow header refresh

I have a script that use the
header('Refresh: 5; url=http..');
die();
And i call this script with another php file that use the function "file_get_contents". Unfortunately it does not work.
With header location there aren't problems.
Any suggestions?
-- UPDATES --
I have followed the advice of Oscargeek.
I have updated the code with a print of HTML that contains meta-refresh.
The script that call this url, is a "system" of cron, and make this call in a foreach. So i think it can't work.
I have changed this call with a cron and wget, but the result is the same.
Other suggestion ?
When you are doing a file_get_contents, you get the HTML but not the headers of the first page.
file_get_contents only return a string without headers, header location it's working because are doing the redirection before return this string.
Try to do the redirect from the HTML, in your first page write this content:
<html>
<head>
<meta http-equiv="refresh" content="5; url=http://google.com" />
</head>
</html>
In the PHP that you are calling, you should only print this content without other data and the refresh will do.
Okay, first of all, I'm wondering why you use file_get_contents to include a PHP-File. I'd use include or require.
For your problem some additional information:
The problem is: None of those headers ever was running in your other script. So this means IF they are send, they got send by the file you were trying to read - but: Since the script didn't got send via HTTP-Protocol, it doesn't send.
If you want to use it like this, I'd advice you to use HTML-Refresh like Oscargeek stated, or use Include / Require, if you want to keep PHP-Code.

Constant set using define() not working in included PHP file

I have this code inside of my header
<?php
define('RELPATH','http://www.saint57records.com/');
include_once(RELPATH.'sidebar.php');
?>
and an example line of code in the sidebar
<img style="margin:10px;" src="<?php print RELPATH;?>images/logo.png" width="60px"/>
but when it gets to the page it includes the file correctly but all the links inside of the file just print RELPATH instead of the web url like this
<img style="margin:10px;" src="RELPATHimages/logo.png" width="60px"/>
It works fine on the other pages of my website, just not inside of Wordpress. Does anyone know what might be causing this issue?
The short answer is to provide a filesystem path to RELPATH, not a web URL.
The long answer is that when you use a web URL to include a PHP file, the PHP file will be treated like an external source. It will be called remotely, executed in a process of its own, and return the results. A constant defined previously can not have an effect in this remote resource.
If http://www.saint57records.com/ is on a different server, you'll have to pass RELPATH to it some other way, e.g. through a GET variable (which you'd have to sanitize with htmlentities() prior to use.) However, including content from a remote server in this way isn't good practice. It'll slow down your page as it'll make an expensive web request. If the target server is down, your page will time out.

PHP include not working with IE 7, 8 and 9

I use the following code to include page content in a index.php file (template).
if(isset($_GET['page']))
{
include($_GET['page'].'.php');
}
if(isset($_GET['special']))
{
include($_GET['special'].'.php3');
}
The url could look like this: http://www.example.com/?page={PageToShow}
This works fine for Chrome, Firefox and Safari, but the content is not shown in IE 7,8 & 9. Any idea why?
The server side PHP scripts wouldn't be affected by the browser that you use to view the page, so this looks like a rendering issue - check that the included code produces valid HTML, and that you haven't got <html> tags being included within other <html> tags.
You might want to rethink the way you're including page content - doing this via a GET variable is potentially insecure: for a start, it doesn't limit the files to those within the document root of your website.
At the very least I'd recommend doing some sanity checks on the input files (i.e. are they in the webroot?), but a more modern method is to use .htaccess rewriting to send all requests to index.php, where you can then choose which files to include depending on the request (take a look at this post for more information).
The server side script you put above should return the same result with all browsers. Try debugging with $_SERVER["REQUEST_URI"] and see if you get the same results.
Also, I would advise not to use such kind of includes for security reasons.

Categories