Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
Do I really have to reload my page twice?

I am currently working on a project including the Facebook SDK. I already made it to Login/Logout myself using the javascript code.

I'm using an AJAX POST request to save the userID and the name from the response in a Session.

The problem here is, that I actually have to reload the page twice, the first time to get the POST parameters and save them into a $_SESSION. The second refresh is needed to load the Session.

Is there a clean way to avoid that?

javascript: $.post( "login.php", { id:userID, name:response.name } );

login.php: $_SESSION['name'] = $_POST['name']; $_SESSION['userID'] = $_POST['id'];

I appreciate every kind of help. Thank you.

edit: I would like to give the user who logged in with facebook additional oppurtunities on my website. The only way I know how to do this is with a Session in PHP. Whenever he logged in I created a Session who said that a person is logged in.

Now I have to do the same with a facebook login. It worked local with the PHP SDK already, but the webspace does not support that kind of SDK. That is why I have to dodge to the javascript one. Is there another way to make sure a person is logged?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are using AJAX,
So you can avoid reloading of Page,

<?php    
    session_start();

    if (isset($_GET['name'])) {$_SESSION['name'] = $_GET['name'];}
    if (isset($_GET['userID'])) {$_SESSION['userID'] = $_GET['userID'];}

    if(isset ($_POST['name']  ) && isset ($_POST['userID'])){
        $_SESSION['name']= $_POST['name']; 
        $_SESSION['userID']=  $_POST['userID'];
    }else{
        $_SESSION['userID'] = 0;
    } 
?>

and javascript code is:

$.post( "/login.php", { id:userID, name:response.name } );
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda