I've a basic web service written in Delphi. This web service is receiving POST requests with JSON via PHP Curl Library from Phil used on Codeigniter.
The server returns the data according to the request.
On the first request i send my authentication and i get the respective JSON.
On the second request the server identifies a different session.
You need to set CURLOPT_COOKIEFILE so that cURL saves its cookies into a file. The reason you are losing your session is because cURL is not persisting your session cookie across all of your requests.
So, for Code Igniter it would be something like this:
$this->curl->option(CURLOPT_COOKIEFILE,'saved_cookies.txt');
Related
I have two applications, one in PHP and other in Meteor, My requirement is that when a user is created using PHP application, it should be also sync/add to the meteor application.
I have knowledge in meteor, but not in PHP, I am looking for creating a method in PHP, so that it can send a http or similar request with all user information to my meteor application(method), and here I can query for existing user or add a new one, is this approach possible or have some other way possible, if possible then please give me an idea how I can send request from the PHP side and get this request in meteor and accomplish my requirement.
Yes, it is possible. Create a function in PHP that would do a POST request using curl and it will send the data to and endpoint where your meteor application will take over. You can google how to send POST requests from PHP and the first link will give you an answer.
Just make an endpoint ready from your meteor app to receive the data from PHP app.
Is it safe to use php curl posting to receive data from external site to frontend?
I must send with the curl post htaccess login details to get the data. Can those login details be hacked or seen from client side (ie. when client loading page where curl triggered?
What I know this far, its just server to server post so client can't see the details posted with curl (its done with php)?
Now I have a web server written with php. And there some php script files for database accessing. I'm writing a Qt app to send get/post request to the remote php scripts. However, it's not convenient to verify user identity for each request. So, I want to use session control on the web server. But I don't know how to do in Qt application.
As Orangepill and PLB said, the solution is Passing cookies to the request url, you may refer to QNetworkAccessManager::setCookieJar.
Steps
Instantiate the QNetworkAccessManager object and call setCookieJar for it.
Send POST request to the authenticate page which activates a session. Then you will have cookies got from the page in the cookieJar.
Send requests to the pages under the domain will with the session alive.
What is the best way to write an android application that logs into a server? I am thinking I do not want to maintain a socket, so I think I want to avoid that, I think I want to use the http protocol. My question with that is, on the server side, ideally I would like to use PHP to handle the GET/POST calls from the android app, but I don't know how to return (using PHP) information that my app can handle and not just an html file.
So for example, the facebook app for android. When you first download the app, you login and then the app maintains your connection, but obviously the app is not another web browser, but a regular app that presents its information as if it were a web site. How does the app pass the session cookie so that the PHP $_SESSION variables maintain themselves? How does the android app handle the data that comes back?
If I send a get requestion to htt://www.test.php can the PHP code that executes on the server return a custom set of data? Will the $_SESSION variables be automatically maintainted?
Thank you
You can send a get/post request to log on the server. The PHP page can return JSON or XML. Then your Java (Android) code will have to parse that response.
You can have the PHP page log first, and then start a session. Maybe generate a token key and store this in the database, and then return this to the android app. Android app will get this token (after parsing), and probably save it in a preferences file. This approach is basically a custom session. You will have to figure out things like expiration of token, etc.
There might be a way to store PHP sessions, but not sure how an app behaves differently from a browser. I think sessions can be little bit more complicated with apps.
More discussion here: php session destroyed in android application
You just need to create Server Side API which receives and sends data back to Client. Server start session, when API is requested, and Client receives PHPSESSID which is used to keep session opened. On Client, you use cookie for sessions.
Read about sessions: PHP Sessions (simple) and Session Handling (comprehensive)
I am trying to retrive XML from a site and process on my server. I can get the XML on my browser after I log in to the specific site. but I cannot do it by sending request from directly from server because the session is not available. How can I achive this
Assuming it's using basic auth you should be able to do this with curl setting a auth_user /password: http://php.net/manual/en/book.curl.php