Is it possible to pass variables from one webserver to another using php? I need to be able to pass variables from a webhost to a local server for processing and I dont know if it can be done.
You have to communicate between the servers somehow. How you do that communication determines if, and how, you would pass data. (You can't generally pass actual variables, just the contents of them).
If, for instance, you were communicating with HTTP then you could pass the data in the query string of the URI, or in the body of a POST request.
Post a web request to that server.
You can do that using curl and add header data or post data too.
Check php curl manual
Simple post request will also do the trick.
There are many ways you could do this. The simplest way and most service oriented would be to make a "catcher" php script which will recieve the variables on the target server and then the local server can run:
file_get_contents('http://targetserver.com/catcher.php?var1=val1&var2=val2&var3=val3...');
also look into sockets and direct connections, FTP, and other ways to do it.
Related
An external application is calling my PHP script and passing URL parameters and a SOAP envelope. I can access the URL parameters in the $_GET array. However I cannot access the SOAP envelope. I was expecting it in the $_POST array, but that is empty.
The IIS log clearly shows that the SOAP envelope is being received by IIS but somehow I cannot access it in PHP - or I am using the wrong methods/variables.
When I check the "failed requests log" in IIS, I see the SOAP data as "GENERAL_REQUEST_ENTITY".
However I am at a loss when trying to access said data from within my PHP script. Is this kind of content stored in a different variable (other than $_GET, $_POST or $_REQUEST)? Or is IIS not forwarding this to my script and if so, why not?
Edit: I am not tied to PHP if PHP is not capable of doing this, I am open to any language that gets the job done. However my knowledge of ASP.NET is more limited than that of PHP. Is there a better language for capturing the missing data from the request?
This problem is not going away and I need to find a solution. So far no matter how much I search via Google, I keep running into dead ends.
Edit #2: Here is a screenshot of the log file for clarification. It clearly shows the XML and so does Fiddler, which I have also just now tested:
How can I capture this XML with PHP (or ASP.NET for that matter)?
Best regards
Max
I'm trying to accomplish remote php call and return as described in this question: PHP: Remote Function Call and returning the result?
However, I don't know how to make the listener script that responds to the GET request. How do I create the script, allow it to be called remotely, and have it process the request appropriately? Is there an example somewhere?
I understand this is probably a very low-level question, but I'm very new to PhP.
You don't need to implement a listener, the web server is doing that for you. Just create a script and put it in your web directory. When the web server receives a GET request to that script, it will execute the PHP script.
In the script, you can just echo the values that you want to send back in a format that your calling function understands. (Of course you could also set some headers, if you feel that this is necessary).
Your listener PHP script responding to a remote call should be just like a script responding to a web browser's request. Use $_GET to get the input data.
I don't suppose there's a way to, using PHP, intercept what mysql_query sends out and rewrite it before sending it out?
mysqli::__construct has an option parameter $socket. If streams could be passed for that parameter then you could pass php://memory to it it seems but it doesn't seem to work that way.
Any ideas?
You can setup a proxy server with something like squid that will forward to a database server from the frontend.
I want to handle http requests via another webserver or own written server in future.
I want to understand how to provide php with request data properly.
in what form request data should be provided
how data is provided to php, via stdin or somehow else
how php handles received request data afterwards, any additional actions required to fill $_SERVER variables etc.
It's pretty simple actually. The Webserver communicates with PHP through the CGI interface. This entails setting up environment variables, invoking the php interpreter, piping a POST body through stdin, and then reading the PHP response from stdout.
Call PHP from virtual/custom "web server"
How to pass POST data to the PHP-CGI?
http://pear.php.net/package/HTTP_Server
What is Common Gateway Interface (CGI)?
As to PHP postprocessing the $_SERVER variables: That's fairly minimal, it only constructs PHP_SELF and PHP_AUTH_USER etc. as documented in the manual. The rest is provided by the webserver (e.g. all HTTP headers converted into HTTP_* env variables).
Go download the source code for php, and look at the code for mod_php, written in C I believe, cause that's where it's done.
I am trying to perform a simple jQuery AJAX attempt using either a .get() or a .post().
If I have a local copy on my server and do:
$.get('/hash.php',...,...)
I monitor in my console in firebug that the get is done and I get a response.
All I change is the URI to an outside server and nothing happens.
$.get('https://secure.mysite.com/subdir/hash.php',...,...)
Doesn't help if I take the 's' off or if I use post instead. Am I missing some parameter that I should use in jQuery?
EDIT: I forgot to mention the reason I'm doing this is because I am eventually migrating from a PHP4 site to a PHP5 site, but for now the live PHP4 site needs a function that isn't in PHP4. So I am calling a PHP5 server to do it. I think I have a good workaround. Thanks!
You cannot send an Ajax Request to another domain than the other on which your application is deployed. This is because of the Same Origin Policy implemented in web-browers -- a security measure.
There are two possible solutions, though :
sending the request to your own server, that will act as a proxy to another (either via a PHP script, or, better, using some of Apache's mod_proxy_http module)
or not using "Ajax", but other techniques, like dynamically creating <script> tags -- which are not subject to the SOP constraint.
It's true that you normally can't do Ajax outside your domain due to the browsers. However using JSONP it is possible to do this. jQuery also has a jsonp param for Ajax now. To make this work you need to control the output of the server though.
Javascript cannot access a server outside of where the javascript file came from.
That is a security feature.
Depending on how browser-specific you want to get you may get around this, but that becomes a bit of a slippery slope.
You cannot do cross domain ajax requests directly, this would be a security concern.
You will need to call your local php file from jquery and have the php file talk to the other domain.
There's a method called JSONP which is used to circumvent that. See the 2nd reply on SO #570100