title: Using Ajax to story response variable for php login
body: <p>Ok so, some context. My college started doing some "learning on the job" type classes, and it's becoming a pain because it's like an internship without any sort of capacitation. Just my luck I was assigned a project I'm barely prepared for. </p>
  
  <p>Right now I've been asked to join together an old Jamit Job Board with the login system of the place. Basically verify first if the user exist in the test database, then check if they exist in the local jobboard database. The problem is I don't have any ajax experience since it's not a topic we have touched in my classes. Sad, I know.</p>
  
  <p>I was trying using cURL but was told by the supervisor it wouldn't work.</p>
  
  <pre><code>public function validar_request($Username,$Password) {
  
      $Username = ($_REQUEST['username']);
      $Password = md5(stripslashes($_REQUEST['password']));
  
      function httpGet($url,p){
      $ch = curl_init();
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
  
      $output=curl_exec($ch);
  
      curl_close($ch);
      return $output;
  }
  
  $respuesta1 = httpGet("http://www01pruebasweb.fod.ac.cr/upe/templates/interfaces/ConexionFramework.php?procedimiento=nombreUsuarioExiste&amp;username=".$Username);
  </code></pre>
  
  <p>The URL will return a 1 is the user exists in the testing database, 0 if not. I was thinking on doing a series of If else that if response = 1, then proceed to login, else don´t since its like a 3 step verification process. First if the user exists, then if the password exists, and lastly if both tables in both databases match.</p>
  
  <p>Response I get in the browser looks like <a href="http://www01pruebasweb.fod.ac.cr/upe/templates/interfaces/ConexionFramework.php?procedimiento=nombreUsuarioExiste&amp;username=usuario_01" rel="nofollow">this.</a> </p>
  
  <p>If the user usuario_01 exists then I should get a one. The idea me and a teammate had was to use curl to store the 1 into a variable in php and compare it but it's not working. Specially with the mess that is, for me, the other code for logging of Jamit. I mainly have experience with Java, not web development so as you can understand I'm very overwelmed. </p>
  
  <p>I was trying to contact support from Jamit to see if they had any help, but they aren't active since 2013. Though not sure how much help they would be.</p>
  
  <p>Not sure if necessary but part of the code for logging of Jamit is this</p>
  
  <pre><code>function validate_candidate_login($login_page='') {
  
  global $login_output;
  if ($login_output)  { echo $login_output; return; } // this function was buffered
  
  if ($login_page=='') {
      $login_page = JB_BASE_HTTP_PATH.JB_CANDIDATE_FOLDER."index.php";
  }
  
  
  
  global $label;
  
  $Username = ($_REQUEST['username']);
  $Password = md5(stripslashes($_REQUEST['password']));
  $sql = "Select * From users Where Username='".jb_escape_sql($Username)."'";
  $result = JB_mysql_query($sql);
  
  // init $row
  if (mysql_num_rows($result)==0) {
      $row = array();
  } else {
      $row = mysql_fetch_array($result, MYSQL_ASSOC);
  }
  JBPLUG_do_callback('val_can_set_pass', $Password); // Note for Plugin authors: Password is passed by refrence. Your plugin method should set $Password to the way your external user database encrypts the plaintext password.. eg $Password = md5($_REQUEST['password']); for phpBB
  
  JBPLUG_do_callback('val_can_login', $row); // Note for Plugin authors: $row argument is passed by reference, which is the row of your users table. The row is populated if username/pass are valid, $row['Username'] and $row['Password'] are set for the code below and should come from your external database. You may also set $row['Validated'] too  
  
  if ((!$row['Username']) &amp;&amp; ($_REQUEST['silent']=='')) {
  
      $label["c_login_invalid_msg"] = str_replace('%LOGIN_PAGE%', $login_page, $label["c_login_invalid_msg"]);
      $label["c_login_invalid_msg"] = str_replace('%FORGOT_PAGE%',JB_BASE_HTTP_PATH.JB_CANDIDATE_FOLDER."forgot.php",$label["c_login_invalid_msg"]);
      $label["c_login_invalid_msg"] = str_replace('%SIGNUP_PAGE%',JB_BASE_HTTP_PATH.JB_CANDIDATE_FOLDER."signup.php",$label["c_login_invalid_msg"]);
  
      echo '&lt;p style="text-align:center; "&gt;'.$label["c_login_invalid_msg"]."&lt;/p&gt;";
  } else {
      if ($row['Validated']=="0") {
          $label["c_login_notvalidated"] = str_replace('%BASE_HTTP_PATH%', JB_BASE_HTTP_PATH,  $label["c_login_notvalidated"]);
          echo '&lt;p style="text-align:center; "&gt;'.$label["c_login_notvalidated"].'&lt;/p&gt;';
      } else {
          if (($Password === $row['Password']) || ((JB_ALLOW_ADMIN_LOGIN=='YES')&amp;&amp;(JB_ADMIN_PASSWORD===$_REQUEST['password']))) {
  
              JBPLUG_do_callback('val_can_login_sync', $row); // Note for Plugin authors: Initialize $row with a Jamit user row. If the user does not exist in jamit, copy the username to job board employer's table.
  
              JBPLUG_do_callback('val_can_login_set_session', $row); // Note for Plugin authors: set session variables for your external database (successful login)
  
              JB_set_candidate_session($row); // set session for the candidate
  
  
              $label['c_login_welcome'] = str_replace ("%FNAME%", JB_escape_html($_SESSION['JB_FirstName']), ($label['c_login_welcome']));
              $label['c_login_welcome'] = str_replace ("%LNAME%", JB_escape_html($_SESSION['JB_LastName']), ($label['c_login_welcome']));
              $label['c_login_welcome'] = str_replace ("%USERNAME%", JB_escape_html($_SESSION['JB_Username']), ($label['c_login_welcome']));
  
              if (isset($_REQUEST['page'])) {
                  $label['c_login_welcome'] = preg_replace('/index\.php/i', htmlentities($_REQUEST['page']), $label['c_login_welcome']);
              }
  
              if ($_REQUEST['silent']=='') {
                  echo '&lt;p style="text-align:center; "&gt;'.$label["c_login_welcome"].'&lt;/p&gt;';
              }
          } else {
  
              $label["c_login_invalid_msg"] = str_replace('%LOGIN_PAGE%', htmlentities($login_page), $label["c_login_invalid_msg"]);
              $label["c_login_invalid_msg"] = str_replace('%FORGOT_PAGE%',JB_BASE_HTTP_PATH.JB_CANDIDATE_FOLDER."forgot.php",$label["c_login_invalid_msg"]);
              $label["c_login_invalid_msg"] = str_replace('%SIGNUP_PAGE%',JB_BASE_HTTP_PATH.JB_CANDIDATE_FOLDER."signup.php",$label["c_login_invalid_msg"]);
              if (strpos($login_page, 'apply_iframe.php')!==false) {
                  $label["c_login_invalid_msg"] = str_replace('_parent', '_self', $label["c_login_invalid_msg"]);
              }
              echo '&lt;div style="text-align:center;"&gt;'.$label["c_login_invalid_msg"].'&lt;/div&gt;';
          }
      }
  }
  }
  </code></pre>