title: Not getting return value from curl php
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8227909/curl-exec-always-returns-false">curl_exec() always returns false</a>  </p>
  </blockquote>
  
  
  
  <p>Hi I am new in php and I am stuck on this thing for while now. So i have two domains with their own DB. So if a user tries to login on one domain and his credentials are not found in the DB it is curl to other domain to see if his credentials exists or not. So a match means num_of_rows = 1, else 0. </p>
  
  <p>I am able to curl everything after curl works fine but i dont get back any value in return. Here is my code:-</p>
  
  <p>logincheck.php:</p>
  
  <pre><code>&lt;?php
      session_start();
  if(isset($_POST['Email'], $_POST['Password'])){
      $email = $_POST["Email"];   
      $password = $_POST["Password"];
  
          print "email received $email";
          print "&lt;br&gt;password received $password";
  
      $db_username="root";
      $db_password="root";
      $database="photobook";
      $localhost = "mysql";
  
      $con = mysql_connect($localhost,$db_username,$db_password);
      mysql_select_db($database,$con) or die( "Unable to select database");
  
      $query = "select * from photobook.users where email ='$email' and password ='$password';" ;
  
      $result = mysql_query($query);
  
      $num=mysql_num_rows($result);
  
      if($num == 1){
          while($row = mysql_fetch_array($result))
               {
                  $_SESSION['email'] = $row['email'];
  
                  $_SESSION['username'] = $row['username'];   
               }
  
          header("location: home.php");
  
      }
  
      else{
  
          include "Protocol.php";
  
                  print "&lt;br&gt;email after protocol file include is $email";
                  print "&lt;br&gt;password after protocol file include is $password";
  
          $obj=new Protocol();
  
          $val = $obj-&gt;loginCheck($email,$password);
  
                  **print "&lt;br&gt;value of val received is $val";**
  
          if($val == 0){
              session_destroy();
                          print "&lt;br&gt;user does not exist";
              header("location: login.php");
          }
          else{
              $_SESSION['email'] = $val[0];
              $_SESSION['username'] = $val[1];
              print "&lt;br&gt;user exists";
              header("location: home.php");
  
          }   
      }
  
      mysql_close($con);
  
      }
  ?&gt;
  </code></pre>
  
  <p>Protocol.php on first domain:-</p>
  
  <pre><code>&lt;?php
  
      class Protocol{   
          function loginCheck($p_email,$p_password){
  
              $sid = 2;
  
              $msg="sid=$sid&amp;email=$p_email&amp;password=$p_password";
  
              print "&lt;br&gt;parameter string sent $msg";
  
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,"http://www.snapreveal.com/PhotoBook/src/Protocol.php");
              curl_setopt($ch, CURLOPT_POST, TRUE);
              curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
              $p_result = curl_exec($ch);
              curl_close($ch);
              if ($p_result === FALSE) {
                    die("Curl error: " . curl_error($ch));
              }
              return $p_result;
  
          }
  
      } //end of protocol class
  ?&gt;
  </code></pre>
  
  <p>Protocol.php on second domain:-</p>
  
  <pre><code>&lt;?php
  
      class Protocol{
  
          function loginCheckResponse($p_email,$p_password){
  
              print "&lt;br&gt;inside second domain loginCheckResponse";
              print "&lt;br&gt;email inside second domain loginCheckResponse $p_email";
              print "&lt;br&gt;password inside second domain loginCheckResponse $p_password";
  
              $db_username="root";
              $db_password="root";
              $database="photobook";
              $localhost = "mysql";
  
              $con = mysql_connect($localhost,$db_username,$db_password);
              mysql_select_db($database,$con) or die( "Unable to select database");
  
              $query = "select * from photobook.users where email ='$p_email' and password ='$p_password';" ;
  
              $result = mysql_query($query);
  
              $p_num=mysql_num_rows($result);
  
              print "&lt;br&gt;num found inside teja loginCheckResponse $p_num";
  
              mysql_close($con);
  
              if($p_num == 1){
                while($row = mysql_fetch_array($result))
               {
  
                                  $u_email = $row['email'];
  
                                  $u_username = $row['username'];
  
                                  $res = array($u_email,$u_username);
                                  print "&lt;br&gt;inside second domain logincheck, after match values in res array are, email $res[0],username $res[1]";
                                  print "&lt;br&gt;value in res&lt;br&gt;";
                                  print $res;
                                  return $res;
               }
              }
              else{
                return 0;
              }
  
          }
  
      } //end of protocol class
  
      $pobj=new Protocol();
  
      $sid = $_POST['sid'];
  
      $p_email = $_POST['email'];
  
      $p_password = $_POST['password'];
  
      if($_POST['sid'] == 2 ){
          $pobj-&gt;loginCheckResponse($p_email,$p_password);
  
          }
  ?&gt;
  </code></pre>
  
  <p>Output of prints:</p>
  
  <pre><code>email received max@gmail.com
  password received max
  email after protocol file include is max@gmail.com
  password after protocol file include is max
  parameter string sent sid=2&amp;email=max@gmail.com&amp;password=max
  value of val received is 
  inside second domain loginCheckResponse
  email inside second domain loginCheckResponse max@gmail.com
  password inside second domain loginCheckResponse max
  num found inside second domain loginCheckResponse 1
  inside second domain logincheck, after match values in res array are, email max@gmail.com,username Max
  value in res
  Array
  user does not exist
  </code></pre>
  
  <p>So "value of val received is" this line should print after curl returns value back but it print prior to that. And also there is no value received back. Any thoughts why?</p>