Load php in local html - php

I have a problem with a local file, I don't know if it's possible but I like to know if its...
My code in my local HTML is:
$(document).ready(function(){
$("#load").load("http://localhost/prueba.php",{estado:"ok"});});
And the php online is:
<?php
echo '<script>alert("' . $_POST["estado"] . '");</script>';?>
If I run my local HTML like "http:// localhost /prueba.htm" runs fine!
But if I try to run my local file like "C:\documents\prueba.htm" not run the php code and that is what I need.
This is only an example, really I want to run a query in php and get me back my info to my HTML file.
Can anyone help me?
Sorry by my english its bad but I've no more options... any idea how to do it?

The main problem is that your request will not be allowed because of the browser's Same Origin Policy. Please have a look at jQuery Ajax request from local filesystem (Windows file:///)

Where did you place php code?
Make sure you put it in same folder.

Related

PHP runs only partially in MAMP

I recently setup a MAMP environment (v3.5)` to test my website locally rather than having to upload to the host.
The PHP works fine on the remote host, in this case the form will submit.
Here's a link: PHP Form
When I run the site locally only html and css work but the PHP pages show the first few lines of the POST sequence.
Partial run
This is the content shown in the viewport
Content-Type: application/x-www-form-urlencoded Content-Length: 59 sendername=&senderemail=&contactno=&user_message=&send=Send
As you can probably guess, this is not the result I am expecting. In the normal scenario, the acknowledgment.php page will load with a 'thank you' message.
Can anyone tell me what is wrong with the MAMP installation that would cause this?
Thank you very much indeed.
check if you put the method="post" attribute in your form
check if you close each tag
Check the version of php on your mamp: preferences -> php
Reeinstall your mamp
in any case if it does not work, you can try manually install php
other think will be that you post your code of file acknowledge.php to check for possible errors
I hope it helps you...
Thank you guys so much for your insight. I am so humbled by the help provided here!
I opened the acknowledgement.php file only to discover that somehow the content had been erased leaving only a few lines.
I corrected it, using the file from the remote host and it is working now!

Debugging PHP during a jQuery.getJSON request

I'm trying to debug some PHP that is called from a jQuery.getJSON request. Everything works on my local machine and one other server but I am having trouble getting it to work on my new server.
I have boiled it down to the following lines:
define('WP_USE_THEMES', false);
require_once('../../../../wp-load.php');
$url = 'http://findyourmp.parliament.uk/api/search?q='.$_GET['q'].'&f=json';
$feed = file_get_contents($url);
Is there anyway I can see which one of these is failing? How would I output these variables without the PHP files sending a response back to the initial jQuery call?
It's all a bit confusing as it works fine on my local machine and other server..
Thanks
Troubleshooting AJAX PHP scripts can sometimes be a hassle! The easiest way would be to see what the console is showing as RESPONSE HEADERS in the XHR section. That doesn't always apply, however.
One thing I've been doing is writing a small script that I can use independently of the rest of the application. Something like this:
<?
require( ................. ); // make sure you include all files you need for the ajax script
error_reporting(ALL);
ini_set('display_errors',1);
include('my.ajax.script.php'); // the AJAX script in question goes here
?>
Save that on your server as ajxchecker.php and you can call it anytime for a quick response.
Use FireFox. Install the FireBug extension and then install FirePHP.
http://getfirebug.com/
http://www.firephp.org/
You will then be able to fully debug your php code.

PHP Port Problem

I'm using a PHP script to detect of a referral URL is a proxy. This is a very simplified version but it works great.
The problem is that I'm trying to use the same script on my other web server but for reasons am not copying over the script. What I'm doing instead is using a get_file_contents.
My problem is that when I use get_file_contents it detects it as a proxy. Is there anyway around this, possibly by changing the port?
<?php $stop = file_get_contents("http://mysite.com/file.php"); echo $stop; ?>
Any help would be great, Thanks!
file_get_contents with a remote URL is very different from a local URL -- you are actually running the script on mysite.com and simply getting the output of that script on your local server. This actually sends another HTTP request to mysite.com, so the referrer for that request is different from the referrer for your original request.

Using PHP on non-supportive server

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.

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