title: Using curl, how can i call a php class and a function inside the class from a form i have on another website (different server)
body: <p>site1 has the php function and site 2 has a form, both sites are on different servers. What's the most concise way to accomplish this task?</p>
  
  <p>The form on site 2 is a very simple login with "email" and "password".</p>
  
  <p>The php class on site 1 is called Shopper and i need to run the login method inside of the shopper class if the credentials are correct on the form on site 2.</p>
  
  <p>I feel way out of my element here.. would something like this work and if so how would i instantiate the Shopper class and run the login function? Do i need to use SOAP protocol?</p>
  
  <p>Any and all help would be greatly appreciated. Thank you.</p>
  
  <pre><code>public function login($password) {
  
  global $db;
  
  if (!$this-&gt;get_email()) {
      return false;
  }
  
  // Log them in now that we know who they are. 
  $vars = array();
  $vars[] = array(':i_email_id', $this-&gt;get_email());
  $vars[] = array(':i_password', $password);
  
  // This also exists, but is not yet in use:
  // $token = $db-&gt;get_function_as_proc('custom.japi_shopper_identity.login_by_username(:i_username, :i_password)', $vars);
  $token = $db-&gt;get_function_as_proc('custom.japi_shopper_identity.Login_by_Email(:i_email_id, :i_password)', $vars);
  // todo: what if it's bad credentials?
  
  if ($token == null) {
      return false;
  
  } else {
      $this-&gt;set_sign_in_token($token);
      return $this-&gt;get_sign_in_token();
  }
  </code></pre>
  
  <p>}</p>
  
  <hr>
  
  <p>Just for clarification:</p>
  
  <p>Login page (siteB):</p>
  
  <pre><code>&lt;form id='register' action='http://siteA/test/profile' onsubmit="return validateForm()" method='post' accept-charset='UTF-8'&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Log In&lt;/legend&gt;&lt;br/&gt;
  &lt;label for='email' &gt;Email Address*:&lt;/label&gt;
  &lt;input type='text' name='email' id='email' maxlength="50" /&gt;&lt;br/&gt;&lt;br/&gt;
  &lt;label for="password"&gt;Password*:&lt;/label&gt;  
  &lt;input type="password" name="password" placeholder="password" required&gt;&lt;br/&gt;&lt;br/&gt;
  &lt;input type='submit' name='Submit' value='Submit' /&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt;
  
  
  &lt;?php
  
  $username = $_POST['email'];
  $password = $_POST['password'];
  
  $shopper = new Shopper($username);
  $token = $shopper-&gt;login($username, $password);
  
  echo json_encode(array("token" =&gt; $token));
  
  print_r ($_POST);
  
  ?&gt;
  </code></pre>
  
  <p>Action page (siteA):</p>
  
  <pre><code>$shopper = new Shopper($email);
  $shopper-&gt;login($password);
  
  $cInit = curl_init("http://siteB/test/login");
  curl_setopt_array($cInit, array(
      CURLOPT_RETURNTRANSFER=&gt;true,
      CURLOPT_POST=&gt;true,
      CURLOPT_POSTFIELDS=&gt;urlencode(implode("&amp;", array("email" =&gt; $email, "password" =&gt; $password)))
      ));
  
      $content = curl_exec($cInit);
      $err     = curl_errno($cInit);
      $errmsg  = curl_error($cInit);
  
      $results = json_decode($content);
  
      //$results =  array("token" =&gt; "pleasework" );
  </code></pre>
  
  <p>Does that look right?</p>