Results 1 to 3 of 3

Thread: Redirect after login doesn't work

  1. #1
    Join Date
    Jan 2013

    Unhappy Redirect after login doesn't work

    for what reason this code doesn't work?

    PHP Code:


    or die(
    "Unable to connect to MySQL");

    //select a database to work with
    $selected mysql_select_db("my_americanhorizon",$con)
      or die(
    "Could not select my_americanhorizon");

    $sql="SELECT * FROM negozi WHERE Username='$f_usr'";


    $datiUtente==array()) // if empty array
    header("Location: userPanel.php"); //successfully logged


    in the php page that contains the form, the "Sorry" response is correctly processed, while header("Location: userPanel.php"); for redirect the page to the userpanel if successfully logged doesn't work

    This is the form page (it's not necessary that you read it, it's should be correct. Only one doubt, i wrote the condition "if (ajaxReq.responseText == "Sorry")"... Maybe i've to write a condition in case of redirection too?)

    HTML Code:
     <div id="logindAndRegistra">
         <div id="sezionesx">
           <div class="scritta" id="loginHeader">Login</div><br />
           <div class="scritta">eMail <br /><input id="username"/></div><br />
           <div class="scritta">Password <br /><input id="password"/></div><br />
           <button id="loginVai">Vai -></button>
    $('#loginVai').click( function() 
    						 var ajaxReq = new XMLHttpRequest();
    						 var params = "username="+$('#username').val()+"&password="+$('#password').val();
    						 var url = "tentaLogin.php";
    						 ajaxReq.open("POST", url, true);
    						 ajaxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    						 ajaxReq.setRequestHeader("Content-length", params.length);
    						 ajaxReq.setRequestHeader("Connection", "close");
    						 ajaxReq.onreadystatechange = function() 
    														  if(ajaxReq.readyState == 4 && ajaxReq.status == 200) 
    															  if (ajaxReq.responseText == "Sorry")
    																  $('#sezionesx').append($('<div id="loginSbagliato" class="baloon up scritta">I dati inseriti sono errati</div>'))
    Last edited by American horizo; 04-14-2013 at 09:30 AM.

  2. #2
    Join Date
    Aug 2004
    I don't think you can process a redirect header through AJAX (the response would actually be the page you redirect to). Instead I might send a JSON object as the response from the PHP script, and then the AJAX response handler would decide what to do based on what is in that response, including a window.location call to the specified URL if that's what the response specifies.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Apr 2013
    Like NogDog said. Echo out url and use it in your ajax processing function. Put an else there. If it is not "sorry" then you redirect to logged in page.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center