How would I pass data from a POST request? - php

I have been building an HTTP Server (in the C programming language), and I'm wondering what would handle a POST request sent by a client. That is, if a client sends me a POST request to a PHP page, then how would I pass the data sent by the client to the PHP page?
Feel free to ask for clarification.

Something needs to parse, compile and execute the PHP page. You're not about to write your own, so your server will need to act as a proxy for the request.
Solution 1: Setup a FastCGI PHP daemon. Your web server can then forward the request to PHP using the FastCGI protocol.
Solution 2: Setup a web server capable of handling PHP requests. Your web server can then (indirectly) forward the request to PHP using HTTP or HTTPS. This is less work for you, but it begs the question why you're not just using that web server throughout.

Related

Testing an multipart form HTTP POST from my iOS app

I'm finishing an app that sends data as a multipart HTTP POST to a server.
Problem is that said server is not available yet, and I want a sort of 'dummy' server to set up that can receive an HTTP POST request like that and just store/spit out the end result so I can see what I'm sending.
I have a host and know my way around a web server, but I never had to deal with a situation like this.
Thoughts?
Consider using a web proxy to verify that what you sent is correct. I use Charles. Charles can also be setup to return fake responses.
you can use wamp to set up a server on your host and any php frameworks to get http requests such as codeigniter

post cross domain without access to the server

is there a way to send a AJAX post to a PHP page that is in a server that I don't have access? The server always send Access Control Allow Origin error, because I'm sending a post from my server (that I have access) to another server (that I don't' have access). It seems that this server that I don't own only accepts post from it.
Any code, tip? I found easyxdm to do that but I don't' know how to use it.
Yes, send the post using your php server(not javascript). That's your only option if you don't have access to the other server and they aren't returning proper CORS headers.

jQuery getJSON() - What server is called?

When using PHP I can use file_get_contents or cURL to get a URL.
jQuery runs on the client
In jQuery there is a function called jQuery.getJSON(). Javascript is run on the client. What server is used for the download of the JSON code of the external URL? What information does the called URL know about? Does it know of the domain? The IP of the client user? It's a client language.
Prefered for many request
To make many requests, is it safer to do this with Javascript than PHP because it runs on the every client instead of one server point?
What server is used for the download of the JSON code of the external URL?
The one that the domain name in the URL passed to that function resolves to.
What information does the called URL know about?
It is an HTTP request, like any other. The usual information will be available.
Does it know of the domain? The IP of the client user?
Of course.
It's a client language.
… making an HTTP request.
To make many requests, is it safer to do this with Javascript than PHP because it runs on the every client instead of one server point?
You control the server. You don't control the client. JavaScript can be disabled. It is safer to make the request from your server.
(For a value of "safe" equal to "Less likely to fail assuming the service you are using doesn't impose rate limiting")
Because of the Same Origin Policy all requests made in JavaScript must go to the domain from which the document was loaded. It's a standard HTTP request, so the server will have the same information it would if a user was just navigating around (including cookies, etc.) From the phrasing of your question it appears you need to make requests to some external site, in which case making those requests from your server which is not subject to such a security policy would likely be best.
In jQuery there is a function called jQuery.getJSON(). Javascript is
run on the client. What server is used for the download of the JSON
code of the external URL? What information does the called URL know
about? Does it know of the domain? The IP of the client user? It's a
client language.
The code that runs your web browser is only on your PC, too, yet it is perfectly capable of retrieving content via the HTTP protocol from a web server, and has done so for several decades.
AJAX requests are no different. jQuery creates an XMLHttpRequest object that performs an HTTP request in a manner uncoupled from the general page context. As far as the server's concerned, it's just an HTTP request like any other.
The text contents of the result you get back happen to be written in JSON format, but the HTTP layer neither knows nor cares about that.

Passthru Soap Request (i.e.. act as proxy for Soap Request)

I am working on a project for a client, that they have several applications that communicate with a soap server, however they require all requests to go thru a proxy, and want to be able to answer several of the soap requests locally, then if it requires the outside server send the request from the inside php server basically like a proxy. So the only communication the Software has is with the rerouted internal php server.
The setup is as follows:
1. Application makes call to 255.255.255.255
2. Internal Routing redirects request to 192.168.1.2 (Internal Web Server)
3. Internal Web server serves requests for the requested page
3a. If the Method requested can be answered local it needs to answer it,
3b. Or it needs to forward the whole original request to the outside server, wait for response then return the answer back to the Software as if it was serving the answer.
Does that make sense, and does anyone have any suggestions for how to accomplish this in a php page? The network routing is already done, and the Software is being answered by the internal php page, however I cannot get it to forward the request.
The determination of 3a is outside the scope, but an important part in deciding what implementation to use; for each transport protocol you need to implement a request rewrite. If there's only the HTTP transport, you can either use fopen with URL wrappers, which isn't very flexible in terms of specifying headers or use the cURL extension. Once you've got the response from the external server, simply write out the data.

PHP code safeguard technique for Remote call, scenario based

I am thinking about safeguardimg my php code in a different way for my project, but it may be childish method. Please let me know alternative or pros and cons of this method.
Both client and server has LAMP.
Client system holds client sensitive data, which will not be shared to the server.
Client will have Auth key to access server.
When client requests the server using the Auth key, after server verifies it, server will send the php code to client for the execution. The Php code will be executed in client and it will connect to other sites from client for processing.
Client will use remote include to get code and execute.
<?php include('http://www.example.com/clientCode.php'); ?>
Client side files is provided by Server admin, with ioncube or zend safeguard encoded one.
So they will not know the PHP code (my assumption).
Also client server interaction will be processed through secure connection.
Including the remote file like that might not work as expected, as the included file is actually executed on the remote server and the result is included in the script that invokes it, not the the actually PHP code from the included file.
If that is what you wish, then that's ok; but you can't transfer the actual PHP code from the remote server.
However, if you MUST transfer the actual code from the remote server to the client, than you could create an API that takes care of the authentication and authorization of the client, reads (without interpreting) the desired PHP file, and then sends it to the client. You could then either eval the code, or cache it as a local file on the client.
You will need special encryption software like Zend Guard if you want to protect your code from your clients.

Categories