title: How to connect to api using codeigniter
body: <p>newbie here in Restful API.  How can I connect to the API? I've tried several ways on how to connect it but nothing seems to work. I provided the restful API connection codes below but I don't know how to connect it. I have provided my codes below. Any help will be appreciated. Thank you.</p>
  <p>Views:</p>
  <pre><code>&lt;form action=&quot;&lt;?=base_url('account/dologin');?&gt;&quot; method=&quot;post&quot;&gt; 
  
       
  &lt;!--  login   --&gt;
  
       &lt;form id=&quot;doLogin&quot;&gt;
  
    
          &lt;div class=&quot;input-group mb-3 dropShadow&quot; style=&quot;padding:35px 35px 5px 45px;&quot;&gt;
            &lt;input type=&quot;text&quot; class=&quot;signinrow&quot; name=&quot;formUsername&quot; placeholder=&quot;Username&quot;&gt;
            &lt;div class=&quot;input-group-append&quot;&gt;
              &lt;div class=&quot;input-group-text&quot; style=&quot;background:transparent; border: none;&quot;&gt;
                &lt;i class=&quot;fas fa-at&quot;&gt;&lt;/i&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;input-group mb-4 dropShadow&quot; style=&quot;padding:1px 35px 25px 45px;&quot;&gt;
            &lt;input type=&quot;password&quot; class=&quot;signinrow&quot; name=&quot;formPassword&quot; placeholder=&quot;Password&quot;&gt;
            &lt;div class=&quot;input-group-append&quot;&gt;
              &lt;div class=&quot;input-group-text&quot; style=&quot;background:transparent; border: none;&quot;&gt;
                &lt;span class=&quot;fas fa-lock&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
      &lt;div class=&quot;text-bold text-sm afterLoginForm text-center&quot; &gt;
        &lt;p class=&quot; mb-2&quot; style=&quot;font-size: 18px;&quot;&gt;
  
         
          &lt;a data-toggle=&quot;modal&quot; data-target=&quot;#recoAcc&quot; type=&quot;button&quot; class=&quot;dropShadow bebas&quot; &gt;&lt;u&gt;I forgot my password &lt;/u&gt;&lt;/a&gt;&lt;br&gt; 
  
          &lt;/p&gt;
        &lt;/div&gt;
        &lt;br&gt;
        &lt;br&gt;
    &lt;div&gt;
      &lt;button id=&quot;btnSubmit&quot;&gt; Sign In&lt;/button&gt;
       &lt;img id=&quot;submit_preloader&quot; src=&quot;&lt;?=pubPath('/assets/imgs/order_button_preloader.gif'); ?&gt;&quot; alt=&quot;Processing...&quot; style=&quot; display:none;&quot; id=&quot;reg_preloader2&quot; &gt;
       &lt;/div&gt;
        &lt;/form&gt;
  </code></pre>
  <p><strong>Controller:</strong></p>
  <pre><code> public function dologin()
      {
        
          if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
          {
              $ip=$_SERVER['HTTP_CLIENT_IP'];
          }
          elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
          {
              $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
          }
          else
          {
              $ip=$_SERVER['REMOTE_ADDR'];
          }
        
          $ci =&amp; get_instance();
          $username = $ci-&gt;input-&gt;post('formUsername');
          $password= $ci-&gt;input-&gt;post('formPassword');
          $ipAddress =$ip;
          $baseSessionID = $ip.$username;
       
         
  
          $url = &quot;https://blabla.com/Auth/login&quot;;
  
          
          $data_array = array('username' =&gt; $username,'password' =&gt; $password,'baseSessionID' =&gt; $baseSessionID,'ipAddress' =&gt; $ipAddress);
  
          
          $data = http_build_query($data_array);
          $data1 = array(
              'Content-Type: application/x-www-form-urlencoded',
              'Auth-Key: simplerestapi',
              'Client-Service: frontend-client'
  
              
          );
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
          curl_setopt($ch, CURLOPT_HTTPHEADER, $data1);
          $reply=curl_exec($ch);
  
          
  
          
          $decode = json_decode($reply,true);
  
          
          $username1=$decode['message'];
          $password1=$decode['password'];
          $userfailed=$decode['mali'];
  
          
          $_SESSION[&quot;username&quot;] = $this-&gt;input-&gt;post(&quot;formUsername&quot;);
          if($username1 ==='Successfully login.'||$password1 ==='Successfully login.'){       //Login success
              redirect(site_url('account/dashboard'), $data);
  
              
          }elseif($userfailed ==='failed username'){                                          //Wrong Username
              echo '&lt;script&gt;alert(&quot;Wrong Password or Username!&quot;);&lt;/script&gt;';
              redirect(site_url(), $data);
  
              
              curl_close($ch);
       
  </code></pre>