pop up to another user of same application in php - php

I am using a php application. Here many users can login at same time like a web site.
Here a want when a user is saving form , a pop up should automatically appear on the browser of another user. id of 2nd user will be mentioned in form , when 1st user is savinf the form.
Please any body give me any idea.At least what type of technique i should use and what type of technology is required.
Thanks !
Rakesh

The technology you need is AJAX.
You should write a javascript function that calls periodically your server (through XMLHttpRequest) for any event you want to notify to your user,and when you have a relevant answer, that same function should pop up the warning.
You'll probably want to start using jQuery, a wonderful Javascript library (that includes Ajax calls) that will save you a lot of time.

Related

Jquery + PHP, wrapped in Phonegap, how to keep users logged in?

I'm making a simple mobile web app where users should be able to login/authenticate to sign up for private events.
I love the way JQuery mobile looks and feels, but want PHP to do everything in the backend: Handle form processing, talk to the DB and so on.
I currently have no authentication, but want to add that.
Wrapping the current solution in Phonegap actually worked, but I suspect the authentication/session handling is going to crash with that.
My hope is that I can exchange data with a PHP script when:
- the form loads (to check for PHP user session etc), and
- a "submit" button is clicked.
I covered the submit button part, and it works. Data is sent to, and returned from my PHP processing script to the JQuery front-end.
For handling the submit event, for some reason this code worked:
$(document).ready(function(){
as opposed to an onclick thing which didn't work.
This baffles me, as I read that document.ready is an event that occurs when the document has completed loading.
Q1: Could this have something to do with me using Jquery mobile sections (
Q2: What would be the correct JQuery event/trigger to use prior to loading, to control form "context"? (based on data from backend PHP).
Q3a: Is it a viable solution to rely on PHP sessions in such a case?
Q4: Also considering that I'd like to Phonegap it...will a PHP session be able to "see" the Jquery-based, phonegap-wrapped app like a client session just like if it was someone using a web-browser?
4b. When does a Phonegap app user session "end"? (When does the user have to log in again...).
I know similar questions have been raised several times, but please consider I'm a gullible idiot that knows too little to understand which case is similar enough to mine. There are some concepts here that I need to grasp before I can decide what to investigate and ask about :-)
Here's to tolerance and understanding! Cheers!
Eivind
You can store mobile id and users id in database with flag logged_in when they first logged in. Then again if user open that app, you can check the mobile id with the record in database whether user is exists or not and if exists then whats his/her status.

automatic write back if user leaves page/system halts

I've been designing a site that is used to collect data, but the person I'm designing for wants some form of redundancy just in case the window is closed or the system shuts down. Is there any way to take data that's been collected and write it to a MYSQL database if the user is disconnected for a certain amount of time, or if they shut the browser window/shut the system down without submitting the data?
The web is stateless and disconnected - so all data will (or rather: should be) persisted between page requests.
I assume you have a web-page generated by PHP that contains a lengthy data-entry form, and you want to save the data in that form in the event the user closes their browser window - the solution is to use a client-script that polls the server with the current data in the form, or at the very least hooks on to the window close event.
Actual implementation is a task left up to the OP.
This can't be done just with a pure HTML page - if the user doesn't submit the form, your server doesn't know what they've typed.
However, you could put some Javascript on the page that made an AJAX call every few seconds (or every few key-stokes or clicks). The idea would be for the JavaScript to invisibly submit the whole form to a PHP page which saved it into a sort of "holding area".
If the user then submitted the form, the holding area could be cleared out, but if they never did, then the data in the holding area would show you where they got to.
The most common techniques to partially prevent this szenario is that web apps work with a heartbeat-function which fires via javascript in a constant interval and sends a request to the server, p.e. to show that the user is still logged on - or, in your case, maybe to submit data already typed into form fields, too.
Think of it as an ajax-powered auto-save-function!
You have to add some javascript to your code for this, but the commonly used javascript libraries, like jquery or mootools, are well documented and offer alot of examples how to do something like this.

How to implement clock like functionality in the "quiz" like form

Hi I am a PHP noob and I have been working on this PHP quiz application for my college project.
I have a database of questions and a PHP view page which will load a question from the database and when the user clicks the submit button.
It will then submit the form; on the server side it first stores the id of this question in the session so repetition of questions does not occur, check the answer of the question, and depending upon whether the response was correct or incorrect, an appropriate message will be transferred to the client side along with the current score and other details.
What I want now is a clock-like functionality which will automatically do something should the user run out of time.
Can anyone help me with that?
You may need to look for using setTimeout in javascript which runs the clock in client-side. Also you need to take care of tracking the starttime of the test in PHP $_SESSION and verify the submission in server-side.

Dynamic updates in social networking webpages

I am creating a social networking site using php,jQuery and MySQL. I have a big doubt. How to dynamically update a user's home page when one of his/her friends does an action and if that has to appear on current user's page as soon as the friend has updated. I am new to this, please help me in this problem?
It looks like you're looking for a way to implement push functionality from your web server to a current user's page.
The push data will be sent as part of a friends' action or soon after (in a queued fashion), and once it arrives to the client Javascript should be used to update the view.
Some methods of doing that are described on the push technologies Wikipedia page.
You can add a JavaScript timer function in web page side. And regularly to check whether new information is gather.
If there is information, then add new information in the page or notice user.
This is a jQuery Timer.
This is function of jQuery.ajax(). You can use this function in jQuery Timer to check whether there have new information.
If there have new content, you can use "Adding elements to the DOM" to display them out. This is a reference for this topic, Adding elements to the DOM.
I think this way would be helpful.

AJAX Some questions

So I am very new to this concept.
So why not go headfirst :) Some things I don't understand;
What happens if js is disabled?
If using mysql databases (ie; checking forms and such) why not just use php?
To confirm what others have said, disabling Javascript will also disable the AJAX call. After all, AJAX stands for "Asynchronous Javascript and XML".
To address why you can't just use PHP, there are some things that just can't be done without it. PHP is great to load the page with the initial information, but after the page is loaded, it actually requires the page to be reloaded to load something else. AJAX allows you to get around this hassle.
For your example of form validation, AJAX can be used to validate the information while the person is filling it out. Otherwise, you are required to reload the page each time someone fills out another field in the form.
Another example is from a project that I have worked on. The form required a zip code and would load the appropriate city and county based on the inputted zip. Using strict PHP, I would need the client to download the entire zip table embedded in the HTML/JS (which would add another 100k at least to the download).
Using AJAX, I can get around this. The user can input the zip code, which triggers an AJAX call that downloads the few rows that I need (this will be less than a few hundred bytes, for comparison).
[Edit:] Also, a tip because you said that you were new to AJAX. If your dealing with some form of authentication (logging in, etc.), remember to validate the user on the AJAX pages themselves. Otherwise, tricky users will be able to access sensitive information for your database.
Ajax just adds to the user experience and allows a web application to feel more like a desktop application to users. So they can delete a record and stay on the same page without reloading, you just let the record disappear.
And remember to validate on the server-side, even if you validate on client-side. Your weakest at your client-side as someone can easily just submit the values straight to your script so ALWAYS check on the server-side and do client-side if you would like to add some nice effects etc.
But you will always need to keep in mind that there are people out there who have javascript disable be it a security policy or just because their paranoid. So when you don't have JS enabled you javascript and AJAX requests won't work. So while developing you will need to make sure that if javascript is not their to do the operation that the form is submitted just like a normal HTTP form, this will allow all those paranoid people to also use your application :D.
OR you could always just deny access to those who don't have Javascript enabled but that's not very nice ... So if you want to check if they have javascript enabled checkout - http://www.w3schools.com/TAGS/tag_noscript.asp - for a example.
AJAX is a Javascript client based technology. If js is disable it simply doesn't work.
Php is a server based technology.
In Php you write pages that are dinamically built by the server. Once built they are sent as html to the client.
Using javascript (and Ajax) you can call the server just to request some datas (hint: look at JSON) or just a little html snippet which is plugged in the current page directly by the browser without requesting a full refresh from the server.
With js and AJAX you can achieve a very rich client experience without reloading a full page every time.
I believe nothing will happen if js is disabled. You need js to grab the data.
If you want to use mysql databases, you can use js to access a php script, which can then return any data gathered from a database, rather than doing it in the page.
AJAX is a way for Javascript (client side) to access PHP/ASP/Whatever serverside language you are using. This means, that if you have an PHP script for getting some data from your MySQL database, and want to run that script when the user clicks some random button, AJAX can do that (async)m and you wont have to reload you page to execute the PHP script.
If Javascript is diabled, AJAX won't work.

Categories