How do I save specific responses from webservers in my local computer - php

I have been asked to write to save the data in some secure place after certain task is completed by a client.
Here my client has alot of staffs who makes data entry in online forms provided by some different vendors. After some steps the entered data generates some results. i.e after submitting the web form. Now he wants the generated results to be saved either in local computer or in some online server.
Can it be done by:
1.) Creating a local web server which sits in between the users and the online main third party server and record all the generated results?
2.) Creating a browser extension [m thinking about firefox] and forcing users to navigate via the specific browser and record all the generated results?
**I am pretty sure that second method can work as firebug is doing that only need to add some functionality to save the data.
any idea will be appreciated.
Sorry for mis-leading guys. To make more clear here are some more explanation.
a.) I am writing application to one of my client who has many staffs who enters data in abc.com website.
b.) User submits the data to abc.com.
c.) the website abc.com produces or generates some result as per input data and sends back to user.
d.) Now I need a system which will be inbetween the staffs/user and abc.com website and track the responses of abc.com and save it to some location automatically.
e.) Currently the data entry user will manually save the result to his local computer and if he/she forgets to save then we miss the result so want to do it automatically so that we wont be missing any single result.

A local webserver wouldn't really help so much because of crossdomain issues, unless you wanna go with something as JSONP. In that case, you might wanna use a signed java applet, which (assuming the user accepts the certificate) has any access an installed Java app would have, so it could potentially bind a port and server as HTTP server (I'm not sure how well this works on linux or unix).
Another idea would be to use Flash's local shared objects. Depends on how much data you want to save. You may need to make the Flash visible, so the user can see the dialog for allowing the data to be saved. You can communicate from JavaScript to Flash using ExternalInterface.
Yet the most simple thing is to give the user a permanent cookie, and save the data associated with that cookie on a web server.
greetz
back2dos

Take a look at HTML5 local storage if you don't need a lot of data to be stored or you can use local databases, see http://blog.darkcrimson.com/2010/05/local-databases/ .
You can also sync it with a server once the client is online again..

Related

iOS and PHP: Check if server has updates/ database has changes

Background
I have an iOS app that retrieves data from a server and writes it to a file with NSFileManager, so that the user does not have to retrieve data again from the server every time they want to visit a page. The data that they are retrieving can change from time to time, so I would like to update the data in the app files when it does.
I am using php pages for my backend web services.
Question
What is the technique for checking if the data in my database has changed so that I know that I should update the data in the app? The only way I can think to do this is to create a php page that checks if the data is different from what I have stored, but this kind of defeats the purpose of saving information to files within the app. I want to minimize when the user communicates with the server, because in situations where the user has no service, I would still like there to be valid data that they can see within the app.
Please ask questions if you do not fully understand what I am trying to achieve. Thank you!
If you want to list the most recently added restaurants for example, you could :
Store the ID of the most recent restaurant on IOS and send it to the server when you want to check for updates.
If the ID isn't the same in the DB, then you have to update your client.
If it's the same, you can just send a response with a 304 status (Not modified) so you minimise the amount of data being exchange.
If you want to cache computed data, like top 10 user-rated restaurants, you can :
Store a hash of the 10 restaurant IDs and send it to server when you want to check for updates.
The server redo the request and compute the current hash for the top 10.
If the hash is different, update your client
If the hash is the same, send a response with a 304 status
NB : If the computation is expensive on server side, you might want to think about a more clever way to detect data changes.
In this case you need to define your release ID on server and store somewhere in app as well. For example, when you do some changes in database or there is an update from server side. Just change that release ID from server.
On IOS side you need to check that release ID. If ios release id is lower than server's ID, then update your database in ios local storage.

How can you save and share the data WITHOUT logging in

I was looking at jsfiddle and shrib.com and the concept of saving and sharing your notes/code without logging in or making an account fascinated me a lot. I noticed they make a different URL for every new entry. So do they save the entry associated with the corresponding code in the database and send cookies to remember the computer or something(using php)? I obviously looked at the source code but obviously the website wouldn't be just HTML. I just wish to understand the concept that works behind. I'm uncertain what should I Google so I came here. My friend thinks there would be no cookies involved.
Thank you for your feedback in advance.
They generate a unique ID which is embedded in the URL that you share; this is associated with the data in some back end storage so that it can be displayed when someone visits the URL.
Because of the requirement to share between users you can't use local storage or cookies, as this would only allow the original user to see the content, not share it.
They probably do use a database of somesort to keep track of the URL's and its content. i doubt it has much to do with anything and that as soon as you visit the url the request is checked and the corresponing page is show to the user.
Also. they probably keep track of the last time visit/active and destroy the input after a certain time period altho im not sure about this
Drawback of using cookies
Limited with low amount of data nearly 4kb It will include your every
HTTP request Will send same data again and again – it’s enough to
slow down your web application Unencrypted data over the internet
(unless your entire web application is served over SSL)
You can use HTML5 Local storage for save data
if(typeof(Storage) !== "undefined") {
// Code for localStorage/sessionStorage.
localStorage.setItem("lastname", "Smith");
} else {
// Sorry! No Web Storage support..
}
For More detail about HTML5 local storage you can refer Here

Comunicate NodeJs with PHP and viceversa

I put in situation:
I have a website entire make in PHP 5.3 and MYSQL, the site need to user to login for get access, the login "simply" check user/password and create a $_SESSION in the domain with the user ID and other user non-personal data.
In PHP i need to read this $_SESSION to detect if user is logued.
Now, i think in create a NodeJS real-time chat with websockets (only work in last browsers obiously, but i looking for pure HTML5 site, not external client-js like socketio.js), but here is my problems:
First problem I need to get the $_SESSION['user'] in the NodeJS, for make this i need to "pull" from PHP TO NodeJS, send a message like "update-this-user-auth" with the $_SESSION['user'] data, but the problem is, first HOW is the best way to pull from PHP Server to NodeJS Server runing in the same (or not..) machine.
And second problem HOW identify the user in NodeJS, because the user have $_SESSSIOn in PHP but i dont know if the request is from user nº1, nº32 or nº 999999.
For the problem of the comunicate from PHP to NodeJS I read some posts, and get 2 ways:
CURL User, usin PHP Curl to "call" a NodeJS service, and send-read data from PHP to NodeJS
Sending messages from PHP to Node.js
DNODE, i found this googling, have good look, but require some extra librarys, and i like to make the code clear and preferably simple.
http://bergie.iki.fi/blog/dnode-make_php_and_node-js_talk_to_each_other/
I thanks to all ideas and comments for the best solution to this two problem.
With PHP:
You can save a random generated key in the database, associated with user's ip, user id and any other session information (time created, last active, expiration date...). Also, save that key in a cookie too.
With Node.js:
Read the cookie, find the key in the DB and check if the session is valid or not.
So, basically, instead of storing all info in PHP, use a shared storage like for example a DB.

PHP session across multiple domains

I have a webservice (abc.com) for my company with an own user database and it is working just fine. Now my company wants to add some additional services which are located on a completly different server with another domain (xyz.com) but still use the same login data from abc.com because we have complete control over it and there are going to be similar servers like xyz.com so it is out of question to just import the user database on xyz.com.
My first thought was to use my checkuser.php from abc.com while submitting the login form from xyz.com but then I learned that the session cookie stuff is bound to the domain. At least that is how I understood it.
After that I wanted to access my checkuser.php via AJAX and HTTPS and submit the session data encrypted via POST to xyz.com. That failed too as AJAX seems not to work across multiple servers for security reasons.
Now I am out of ideas and dont know how I can securly authenticate out users on the foreign servers using our user database.
I would use single sign on (SSO) in stead of a shared session. That way, you don't make the sites code dependent on each other. If you later decide to change something on one of the sites, there is less reason to worry about breaking functionality on the other sites, and if you choose to link in a new site you are able to reuse the same solution.
What's better is that someone already made it for you, and it may even be more secure that what you'll be able to create yourself.
Wikipedia has some good general knowledge on SSO. Also, look into OAuth and OpenID. Combine these terms with PHP and a search should get you on the right track.
Another option is to simply have the login function on xyz.com connect directly to the database of abc.com to check the login name and password. Then you use xyz.com's database for everything else. Also if you really wanted to you could store the session information in your database on abc.com instead of a temporary file then you can also access that data from xyz.com. Here is an example of how to do this.
I haven't been working with php very long and have not encountered this problem myself, however, I've been hitting the books hard and came across an answer that my help you out.
If you are just trying to access the scripts and DB on server xyz.com, you can literally grab the content of a script using its url or IP address from within a script located on a separate server (abc.com) using the following function:
/* This example allows my example script on server mvc.com
to access the script on oreilly.com */
file_get_contents("http://oreilly.com");
Since you are accessing the code remotely, and I'm taking a shot in the dark here, I think that file_get_contents ( ) would allow you to set variables via $_POST or $_GET methods from the script on server xyz.com and send the values to the script on server abc.com. From there, you could then store these variables inside $_SESSION variables located on a single server, which ever server that handles the original $_SESSION variables and most of the processing.
It could become a quite complex 'game of catch' between the servers if you need to go back and forth frequently, but I think it may be a way around your problem if you can't move the data onto a single server. If you plan the structure of your scripts well this would allow you to store those $_SESSION variables all in a single place.

Fill Forms Offline

This is what I am trying to implement and I don't know how to do it:
I have a few forms that users should be able to complete offline. Once the user has filled in the form they should be able to hit save and their data needs to be saved offline. Then later when they are online they can submit all the form data which was saved by hitting a button. They will be asked to log in and once they have done so their data will be saved on server.
These forms will be submitted via iPad/iPhone. The user can save multiple copies of each form.
I am looking for an HTML5/JavaScript/jQuery solution. My backend is php. I have not tried anything yet as I don't have any idea how to do this. Where do I start?
Thanks
You can provide a manifest file to provide a specific form to a user - Application cache IIRC:
http://dev.w3.org/html5/spec/offline.html
Caveat - without making it a native app the user would have to have visited the website while online before they will see any forms at all
Then once the user fills this in store the results in localStorage, ready to access when online.
If the user is online, the standard page will be displayed, and you can check local Storage for any unsubmitted forms, and on submission remove from localSorage.
Check out the principles used in this tutorial, they should get you most of the way there, but you'll have to look into offline html and localStorage a lot more to get a working app:
http://sixrevisions.com/web-development/html5-iphone-app/
Hope that helps.
I don't think this is possible as an web-only solution targeting iOS, since you can't count on the forms staying up in Safari. Even if the user loaded the form in their browser ahead of time when they had an active internet connection, you can't count on Safari not trying to reload the page (which would clear the page and give a connection failure since they're offline).
Therefore, I think you have to create a native iOS app for this functionality.
If you were targeting desktops instead, you could probably accomplish this with browser plugins.

Categories