Is this possible with PHP?
I have created a website that works with different sessions and every users has his own page at mydomain.com/user . I want to know that is it possible that if one user logs in from his account and clicks on a button, it displays a HTML BOX on the dashboard of the button specfied user?
When the intended user logs in, he should be able to see the box from his account.
I would specify the username on whose dashboard the box should appear in the button.
Say - I have 4 buttons named 1b, 2b, 3b, 4b.
If user clicks on 1b, i开发者_如何学Got should display a box on the dashobard of user a. if he clicks on b2, it should display a box on the dashbaord or user b and so on.....
Is this possible? It's like Facebook's instant friend request feature. If yes, can you guys plz give some hint.
Thank You
To do something like that, you need a way to store the messages (boxes) you want to show to the users (using a database with messages associated to users is the easiest). The action of the pressed button would add data there. This action can be done via a simple form with POST method or via an Ajax Query.
Then, you can check if there are new messages for an user when he/she logs in or refreshes his/her dashboard. You just need to check the database, take the message and remove it (or set a boolean "received" to true). This is pure PHP and not instant (only on login or page refresh). With this technique, you insert the block in the HTML before sending it to the client.
Finally, if you want instant notification, you should prepare a javascript to do queries for new messages regularly. On the server side, you have a PHP script looking in the database and returning the message data. With this technique, you send the page without the block and you have another request to get the block and then add it to the HTML with javascript.
Some useful links:
- Short introduction to relational databas
- Introduction to SQL
- PHP PDO tutorial (to access DBs with PHP)
- jQuery AJAX features (to easily do queries with javascript)
- AJAX (Wikipedia article on AJAX, to understand better)
Pure PHP, not really. This sort of thing is where you'll need JavaScript. When user a clicks on b2, they'll make a background request to the server, which records that there's a message waiting for user b. Then you'll need a periodic request to go out from user b's browser that checks to see if there are new messages available. If so, display the box to the user.
Yes, it is possible to do so.
You could create, for example, a table that would serve as a 'buffer' for that kind of messages. Dashboard or any page where user is logged in could have a little ajax script that would check that table from time to time, and deliver messages if they exist for the logged in user.
精彩评论