Allow access to a PHP page only 1 user at a time

Asked

Viewed 1,029 times

5

I’m creating a call answering system, and to avoid confusion when it comes to answering a request, I need to restrict the PHP page that contains the call data to 1 access at a time for each user of the call team, so when someone is answering a call, another user from the same team cannot access the page.

Question: Could this restriction be made using SESSION?

  • The best way to do this is with javascript, because only with php, mysql sessoes or cookies can create a problem. imagine that the attendant closes the browser without closing the session or leaving the page wrongly... the other attendants will not be able to access the page because the last attendant did not confirm his exit correctly from that location.

  • I put the javascript tag to see if someone appears, because I don’t know

  • 2

    @Andreicoelho The solution may even involve Javascript, but it is linked to a global state of the application, and that state can only be on the server. Javascript may even help in terms of usability, but the crux of the problem is server-side.

  • True... you have rasão @bfavaretto, but only with php mysql will generate problem.

  • 1

    @Andreicoelho The suggestion you had given and deleted (why?! was good!) can be implemented only with PHP and a BD.

  • That way yes @bfavaretto but I thought that’s not what Alan asked why I deleted.. =)

  • @Could Andreicoelho show the suggestion you had erased? It might be useful.

  • So Alan, my suggestion was this: there will be a queue of users... The attendant who is free, requests a user to be served

  • He clicks on a button... "I’m Free"... then you link that user with that attendant.. I know that’s not what you’re developing, but it might help

  • @Andreicoelho, it’s a very interesting idea. And he believes that I could do it using PHP and Mysql, or even Javascript?

  • This way you only need php and mysql. Because the queue is only linked to users who are waiting to be served.. if you want I can make an example

  • Please, friend, give me an example just so I can get a sense of what it would be like, then I’ll turn around.

Show 7 more comments

1 answer

1


I think it’s cool to do it like this:

The user who wants to be served makes a minimum registration on a form example: name and e-mail.

Through the post method it is inserted into a table and redirected to the queue.

adding.php

<?php

 $nome = $_POST['nome'];
 $email = $_POST['email'];

 // repare que criei um status que será usado mais tarde, se for 0 significa que está na fila
 mysql_query("INSERT INTO fila(id_fila, nome_usuario, email_usuario, status) VALUES (0, '$nome', '$email', 0");

 // abre uma sessao
 $_SESSION['email'] = $email;

 header("Location: esperando.php");

?>

expecting php.

 <?php

 $emailUsuario = $_SESSION['email'];
 $selecionaUsuariosEspera = mysql_query("SELECT * FROM fila WHERE email = '$emailUsuario'");
 $usuariosEmEspera = mysql_fetch_assoc($selecionaUsuariosEspera);


 //verifica se o usuário ainda está na fila

 if($usuariosEmEspera['status'] == 1){
//se o status dele for 1 significa que o atendente solicitou a presença em um outro ambiente, e ai ele vai.....

header("Location: areaDeAtendimento.php");

 } else {

  //se não ele continua a esperar.....

?>
<html>
<head>
// repare abaixo que a página vai ficar fazendo refresh a cada 1 minuto(acho)...
// Para que? Para fazer a analise do banco de dados denovo...
<meta http-equiv="refresh" content="60">
</head>
<body>

aguarde...

</body>
</html>

 <?php } ?>

areaDoAtendente.php

You will have to create a service table like this..

-id

-sender

-destinatario

-msg

-on-call

When the attendant clicks on the "Next to the Queue!" button it goes to another page that will happen this...

requestUsuario.php

<?php

 //seleciona o último da fila que o status = 0
 $selecionaUltimoDaFIla = mysql_query("SELECT * FROM fila WHERE status = 0 LIMIT 1");

  $ultimoUsuario = mysql_fetch_assoc($selecionaUltimoDaFIla);

  $email =  $ultimoUsuario['email'];

  //altera o status do usuario selecionado
  mysql_query("UPDATE fila SET status = 1 WHERE email = $email");


  //seleciona o ultimo numero de atendimento realizado
   $ultimoNumero = mysql_query("SELECT num_atendimento FROM atendimento ORDER BY num_atendimento DESC LIMIT 1");

   $numero = mysql_fetch_assoc($selecionaUltimoDaFIla);

   $numero = numero + 1;

  mysql_query("INSERT INTO atendimento(id, remetente, destinatario, msg, num_atendimento)VALUES(0, '$atendente', '$email', 'Seja Bem Vindo! Em que possoa ajudar', $numero)");

 $_SESSION['id_atendimento'] = $numero;

 header("Location: areaDeAtendimento.php");

?>

in the area of php support. you select all posts where the call number was = the call SESSION.

I think I’ve gone too far. kkk ... I don’t know if that’s what you need in the end but ok

Hug!

  • In the end javascript will be required.. you will need to update a part of the service area... like a div... where the posts are.. but the structure I think is this.. of course as I do not know the purpose of this system, you will have to shape it according to your needs

  • http://rafaelcouto.com.br/actualizr-div-de-segundos-em-segundos-com-php-jquery-ajax/ I think this is even better

  • thank you so much for the example. It’s not exactly in the same vein that I was going to develop, but the base is all there to create what I need.

  • Relax... Don’t forget to approve the answer if it helped you =) hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.