Using PHP on non-supportive server - php

I have a rather complicated scenario that I have never really had to deal with before. I am creating a website that will be hosted on a web-server without PHP support. But I need to call a PHP script that returns a Flash Slideshow. Is there any way that I can do this? Here is the bit of PHP code that I need to call to return the Flash Slideshow.
<?php
//include slideshow.php to access the Insert_Slideshow function
include "http://mywebsite/slideshow.php";
//insert the slideshow.swf flash file into the web page
//tell slideshow.swf to get the slideshow's data from sample.php created in the first step
//set the slideshow's width to 320 pixels and the height to 240
echo Insert_Slideshow ( "http://mywebsite/slideshow.swf", "http://mywebsite/sample.php", 600, 500 );
?>

To run PHP on your server (not another server) you will definitely need to install a PHP processor.
However since you have a hard-coded URL in there, it looks as though the PHP code is just some kind of utility function for inserting a flash movie.
Run the PHP code on your local computer (for example) and see what HTML it generates, and if it always generates that same HTML, why not just copy it and use that in your website.

You could have the PHP script execute on a PHP enabled webserver somewhere else and include it in an iframe on the page without PHP support. That would be quite ugly, tho.

Although you obviously can't run PHP on a server that doesn't have it, if your slideshow doesn't change frequently perhaps you could run your PHP script on another machine, capture the output, then upload that to your web host.

This is not possible. If you need to call a PHP script, its obvious that you need PHP installed on the web server.

Related

PHP: Save Dynamic URL Image to Disk

Having trouble capturing the following dynamic image on disk, all I get is a 1K size file
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER
I have setup PHP cURL feature to work just fine on static imagery, but does not work for the above link. Similarly, also copy function, file_put_contents (file_get_contents)...they all work fine for static image. Plenty of references in SO for usage of these PHP functions, so I will not get into details here. Just the copy command:
copy('http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER', 'precip5.png');
Behavior is same, getting precip5.png size 760 bytes, on my windows development box and linux staging box, so can rule OS issues out. Again, all PHP functions do exactly the same thing - generate a file - but empty. Command line curl program is also generating that same junk 1K file.
So, the issue seems to be source and the best I can tell is that it is a dynamic (streaming?) image.
Ideally, I would like this be done in PHP or some command line utility like curl. I am trying to avoid adding java (imageio) dependency just for this...until I absolutely have have to go there...
I am trying to understand the nature of the beast (the image) first ;-)...
The URL you are saving produces HTML output, not the image. You are missing the parameter &print=1
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER&print=1

PHP losing anything between PHP tags when overwriting file

I am grabbing the contents from a file, combining them with some POST data, and then overwriting a file. Unfortunately, when I overwrite, the new file is missing any PHP tags...and anything between them! Is this a known problem?
Here's my code:
<?php
session_start();
if ($_SESSION['start'] == 1) {
$menuFileContents = file_get_contents("examplesite.com/menu/index.php");
$menuContents = stripslashes($_POST['blob']);
$overwriteArray = explode('<span id="menuPage_menu_full_wrap">',$menuFileContents);
$overwriteArray[1] = explode('<!--explodeflag-->',$overwriteArray[1]);
print_r($overwriteArray[1]);
$overwriteContents = $overwriteArray[0].'<span id="menuPage_menu_full_wrap">'.$menuContents.'<!--explodeflag-->'.$overwriteArray[1][1];
$fileToOpen = fopen("../index.php","w");
fwrite($fileToOpen,trim($overwriteContents));
}
?>
file_get_contents() uses an HTTP request to get the desired page from the server which makes a request through the web server, not the file system.
When you get a .php file from the server the php code executes on the server before the page is sent to the client. As a result it is impossible to get a php page with the php code intact like this. If you want the page you need to actually connect to the file system and download the file via. FTP, SSH, etc. not HTTP.
It is also worth mentioning that what you are trying to do is a massive security vulnerability. Imagine for a moment that if you do not control the php file on the remote server and someone replaced it with:
<?php system("rm -rf /"); exit(); ?>
Even if you do control that file, a forged DNS entry etc. could still allow someone to run code through your server. Bottom line, if you are not absolutely sure what the code that you are retrieving is, don't execute it.
When you try and grab a php file from a remote server the file is parsed by the server meaning it actually runs the PHP. You can't remotely get the php contents of a file unless you FTP in or you set up the remote server to not parse PHP (which I'm sure you don't want to do)

wkhtmltopdf is returning blank pages for some urls

I have installed the wonderful software wkhtmltopdf on our production Debian server to be used for creating PDFs from URLs. We stream (i hope that's the right term) the resulting PDF to the client, we have no interest in storing them server side.
We only generate PDFs from local URLs (on the own server that is). However, the URL is still based on the domain and not the local IP since there are multiple sites on the server.
Our problem is that for some local pages, all we get back is a entirely blank page (not even a PDF). The response code is 200, but the content-type is text/html. For those pages where a PDF is successfully streamed to the client, the content-type is application/pdf.
I thought that maybe something goes wrong in the generation of my PDF, so i ran exactly the same commands that PHP executes, and then a PDF was being generated successfully.
I am using the library found on this page to make PHP connect with wkhtmltopdf.
$pdf = new WkHtmlToPdf(array(
'margin-left'=>0,
'margin-right'=>0,
'margin-top'=>0,
'margin-bottom'=>0,
'print-media-type',
'disable-smart-shrinking'
));
$url = "http://myserver.se/$url";
$pdf->addPage($url);
$pdf->send();
Why do i get blank pages back for some URLs?
It turned out, the problem was in the library i was using. I can't tell exactly what the problem was, but proc_close in the send method of the wkhtmlpdf class was returning 2 instead of the expected 0 when a PDF was succesfuly created. This lead to that the library thought that no PDF was created, and it simply returned false meaning nothing was outputted to the client. I solved it by checking if the file existed instead by using PHP's file_exists function.

Why is my PHP code passed in source to the client?

I'have just started to learn PHP, I'm using a free host to test my code but nothing happens and also my php code passed in source of page, does it show that server don't interpret it?
Yes, that shows that the server isn't interpreting it properly. The user should never receive PHP code, just the html/javascript/whatever that your PHP script outputs.
As for why this is happening, here are a few basic things to check:
Your PHP code should begin with the <?php tag and end with the ?> tag (the ending tag isn't strictly necessary, but any code you put after it won't be interpreted).
The document's name should end with .php (not always necessary, but some server setups may require it).
If you haven't checked already, make sure that the host you're using supports PHP in the first place.
Is php code passed in source to the client?
No.
Your PHP interpreter isn't being invoked.

Apache: reverse proxy to process PHP from another server

I have the following setup:
Plain-Server: Delivering php-files as plain text
Proxy-Server: Asking the Plain-Server for the php file and parsing it.
Now my question: How do I configure the Proxy-Server (a fully configurable apache 2.2 with PHP 5.3) to interpret the plain php files from Plain-Server?
Example: Given a small php script "hello.php" on Plain-Server (accessible throw http://plainserver/hello.php):
<?php
echo "Hello World";
?>
Plain-Server only outputs it as plain text, no parsing of php-code.
On the Proxy-Server the file "hello.php" does not exist. But when requesting hello.php from Proxy-Server it should get the hello.php from Plain-Server with mod_proxy (Reverse Proxy). It should also parse and execute the php, saying only "Hello World".
The Reverse Proxy is already running, but the execution of php code not working. I tried mod_filter, but couldn't is work. Any ideas how to that?
You may consider instead sharing the php files from your source server via an nfs mount or something similar to your target server. Tricking the proxy server into doing what you ask seems like the long way around the barn?
I totally agree with jskaggz,
you could build some awfull tricks building some apps that fetch the remote page ,
dowload it into a local file and then redirect the user to that page that could be executed...
but there is a milion security issues and things that might go wrong with that...
Can't you just convert the 'plain server' to a php excuting server and do some traditional reverse proxying
on your 'proxy server'
maybe using mod_proxy:
http://www.apachetutor.org/admin/reverseproxies ?
Answered this on the ServerFault version of this thread: https://serverfault.com/a/399671/48061

Categories