tags:

views:

31

answers:

2

Hi, I'm new here, also a novice programmer, and not really familiar with PHP. I don't even know the name of some of the techniques I used when building my apps. I'm sorry for that, but I'll try to explain the best I can.

So I'm building a web apps with PHP / AJAX right now, and I've got to the point where some users (with their own privilege) have their own home page, which shows notification for them when something new happened in the system. I think I used the "get" method from the url to determine which page is the user in right now.

Here's a simple illustration :

  1. A user with "Staff" privilege logged in, and then redirected to his home page. (http://localhost/apps/staff.php)

  2. He open the notification page, and the url changes to : "http://localhost/apps/staff.php?cmd=notification"

I don't know the name of the technique, but here's how I do it : I get the cmd value using "$_GET['cmd']" and then pass it onto a function that checks what page to display.

The problem is, I want to delete the content of notification table and move it to the history table when the user leave the page so only the newest notification will shows. So I think I need to know when the user leave (move) to another page, or when the cmd value change. My question is, how ?

Ps. I'm still a student on a university so this is my homework. Please just point me on a direction and/or clue rather than write the code for me (and a clue to the name of that "get" technique is welcomed :p). I know I still got a lot to learn, but english is not my native and I've tried google and stackoverflow with no result (I believe it's because of my bad english and not knowing the name of the techniques I used).

Thanks before for your help.

A: 

You can check if user went to notification (after his default user page) page like this:

if (isset($_GET['cmd']))
{
    // delete old notifications
    // and move to history table
    // show new ones now
}

This checks if query string value cmd is there, he has moved to notification page.

Sarfraz
Isn't isset only used to check if the cmd is empty or not ? What if I have more than one cmd value ( like addusr for adding user, and etc ?). Checked the documentation in http://php.net/manual/en/function.isset.php and looks like there's no isset($_GET['cmd'] != 'notification')...
bertzzie
@bertizzie: you won't find the documentation of $_GET['cmd'] != 'notification' on php.net, it is your own solution, and also even if more users are added, this will check for them too :)
Sarfraz
A: 

Use a cookie to track the status of the notification.

See this thread for more info: http://stackoverflow.com/questions/2057576/best-way-to-show-an-admin-message-to-certain-users/2059370#2059370