Welcome Guest, Not a member yet? Register   Sign In
Curl Login Problem
#1

[eluser]aruntvla[/eluser]
Hai friends...
plz help me ...iam a new web developer with 3 months exp...now iam using CURL in my website for login to a remote site...but
the response going to the login page...but i need it goes to the dashboard....
iam giving my codes in the controller page and curl library page...plz correct it...and post me.......

***************controller page code*********************

Code:
<?php
    class home extends Controller{
        function index()
        {  

            //$this->load->model('home_model');

            //$data['result'] = $this->home_model->getData();
            $data['page_title'] = "CI Hello World App!";

            $this->load->view('home',$data);
        }
        
        function curllogin()
        {
        $username=$_POST["username"];
        $password=$_POST["password"];
            $this->load->library('curl');
            //for loading page
            //echo $this->curl->simple_get('http://8.14.146.44/CDR/');
            //$this->curl->simple_post('controller/method', array('foo'=>'bar'));
            // Start session (also wipes existing/previous sessions)
$this->curl->create('http://8.14.146.44/CDR/');

// Option & Options
$this->curl->option(CURLOPT_BUFFERSIZE, 10);
$this->curl->options(array(CURLOPT_BUFFERSIZE => 10));

// Login to HTTP user authentication
$this->curl->http_login(''.$username.'', ''.$password.'');

// Post - If you do not use post, it will just run a GET request
$post = array('foo'=>'bar');
$this->curl->post($post);

// Cookies - If you do not use post, it will just run a GET request
$vars = array('foo'=>'bar');
$this->curl->set_cookies($vars);

// Proxy - Request the page through a proxy server
// Port is optional, defaults to 80
//$this->curl->proxy('http://8.14.146.44/CDR/', 8080);
//$this->curl->proxy('http://8.14.146.44/CDR/');

// Proxy login
//$this->curl->proxy_login(''.$username.'', ''.$password.'');

// Execute - returns responce
$result = $this->curl->execute();
echo $result;

// Debug data ------------------------------------------------

// Errors
$this->curl->error_code; // int
$this->curl->error_string;

// Information
$this->curl->info; // array

        }
    }
?>


********************curl library**************

i am giving only execute function......

public function execute()
    {
        // Set two default options, and merge any extra ones in
        if(!isset($this->options[CURLOPT_TIMEOUT]))           $this->options[CURLOPT_TIMEOUT] = 30;
        if(!isset($this->options[CURLOPT_RETURNTRANSFER]))    $this->options[CURLOPT_RETURNTRANSFER] = TRUE;
        if(!isset($this->options[CURLOPT_FOLLOWLOCATION]))    $this->options[CURLOPT_FOLLOWLOCATION] = TRUE;
        if(!isset($this->options[CURLOPT_FAILONERROR]))       $this->options[CURLOPT_FAILONERROR] = TRUE;

        if(!empty($this->headers))
        {
            $this->option(CURLOPT_HTTPHEADER, $this->headers);
        }

        $this->options();

        // Execute the request & and hide all output
        $res=$this->responce = curl_exec($this->session);
        //print_r($res);
        // Request failed
        if($this->responce === FALSE)
        {
            $error_code = $this->error_code = curl_errno($this->session);
            $error_string = $this->error_string = curl_error($this->session);
            echo "login not success";
            echo $error_string;
            echo "<br>".$error_code;
            // $info = $this->info = curl_getinfo($this->session);
            //print_r($info);
            curl_close($this->session);
            $this->session = NULL;
            return FALSE;
        }
        
        // Request successful
        else
        {
            $info = $this->info = curl_getinfo($this->session);
            //print_r($info);
           // echo "login success";
           // $this->debug($this->session);
            curl_close($this->session);
            $this->session = NULL;
            return $this->responce;
          // header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname
//($_SERVER['PHP_SELF']) . "/index.php");
        }
    }

iam waiting for ur reply.............if any doubt regarding this ask me...i need it urgent plz help....
#2

[eluser]Cro_Crx[/eluser]
Enclose your code within [code] [/code] tags so others can read it well Smile
#3

[eluser]theprodigy[/eluser]
can you please show the view that contains the login form?

Also, there is no code in your curllogin function to show a view, redirect to another page, or anything. You are logging them in, but nothing after that.
#4

[eluser]aruntvla[/eluser]
*********view page code here***************
Code:
&lt;?php echo form_open('home/curllogin'); ?&gt;
<div class="Login_header">MEMBER LOGIN</div>
        <div class="Login_bg"><br />
        <div class="Username">Username :</div>
        <div class="textFld">
        <img src="&lt;?=base_url().'system/application/images/';?&gt;textfld-Bgleft.gif" width="5" height="25"  style="float:left"/>
        &lt;input name="username" type="text" id="username"  class="txtBoxBg"/&gt;
        <img src="&lt;?=base_url().'system/application/images/';?&gt;textfld-BgRight.gif" style="float:right"/></div>
        
        
        <div class="Username">Password :</div>
        <div class="textFld">
        <img src="&lt;?=base_url().'system/application/images/';?&gt;textfld-Bgleft.gif" width="5" height="25"  style="float:left"/>
        &lt;input name="password" type="password" id="password"  class="txtBoxBg"/&gt;
        <img src="&lt;?=base_url().'system/application/images/';?&gt;textfld-BgRight.gif" style="float:right"/></div>
        
        <div style="float:left; width:235px; padding-left:15px; margin-top:8px;">
        &lt;input name="submitbutt" type="submit" id="submitbuttAB" value="" /&gt;&lt;/div>
&lt;/form&gt;
*********************************************************************************


i dont know how to give a code for curl login succees....
plz give me a code to reach login home....


Code:
if($this->responce === true)
        {
$info = $this->info = curl_getinfo($this->session);
            //print_r($info);
           // echo "login success";
           // $this->debug($this->session);
            curl_close($this->session);
            $this->session = NULL;
            return $this->responce;
          // header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname
//($_SERVER['PHP_SELF']) . "/index.php");
}

but this code not working correctly....
#5

[eluser]theprodigy[/eluser]
are you receiving an error message?
is it not responding as it should be?
How is it "not working correctly"?
#6

[eluser]Phil Sturgeon[/eluser]
Grab the new version and use "echo $this->curl->debug()" for more information.
#7

[eluser]aruntvla[/eluser]
Its only showing login page of http://8.14.146.44/CDR/ but i want to login to their home page after curl login success..........
#8

[eluser]aruntvla[/eluser]
=============================================
CURL Test
=============================================
Code:
Responce
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--

--&gt;
&lt;/style&gt;
&lt;link href="style.css" rel="stylesheet" type="text/css" /&gt;
&lt;style type="text/css"&gt;
&lt;!--
.style2 {
font-size: 18px;
font-style: italic;
color: #999999;
}
--&gt;
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;


<div class="Wrapper">
<div class="Header">
<img src="images/girl-headphone.jpg" alt="Headphone" style="float:left;"/>
<div class="caption">Get Connected <br />
<span class="style2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Long Calls ....Big Savings...!!</span></div>
<img src="images/companyName.jpg" alt="CompanyName" style="margin-left:40px;"/>
</div>

&lt;form name="frm" action="" method="post"&gt;
<div class="ContentSpace">
<div class="LoginBox">
<div class="User">
<div class="Username">Username :</div>
<div class="TextBox">&lt;input name="username" type="text" id="username" class="txxtt1"/&gt;&lt;/div>
</div>


<div class="User" style="margin-top:0;">
<div class="Username">Password :</div>
<div class="TextBox">&lt;input name="password" type="password" id="password" class="txxtt1"/&gt;&lt;/div>
</div>

<div class="User" style="margin-top:0;">
<div class="Username">&nbsp;</div>
<div class="TextBox">&lt;input name="submit" type="submit" value="" id="submitbutt" /&gt;&lt;/div>
</div>



</div>



<div class="Download">
<div class="tunel"><a href="http://8.14.146.44/44.zip" class="tunelLink">Tunel Client</a></div>

<div class="tunel"><a href="http://8.14.146.44/pc2phone.msi" class="PCPhone">PC2Phone</a></div>
</div>

</div>
&lt;/form&gt;



<div class="Footer">Copyright © 2009 <a href="#">net-fone</a>. All rights reserved.</div>
</div>


&lt;/body&gt;
&lt;/html&gt;

=============================================


Info

Array
(
    [url] => http://8.14.146.44/CDR/
    [content_type] => text/html
    [http_code] => 200
    [header_size] => 371
    [request_size] => 147
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 1.016
    [namelookup_time] => 0
    [connect_time] => 0.329
    [pretransfer_time] => 0.329
    [size_upload] => 7
    [size_download] => 2745
    [speed_download] => 2701
    [speed_upload] => 6
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0.688
    [redirect_time] => 0
)

when i debugging i got this reply.....but i need its loginsuccesspage.....how i do it....plz help... :roll:
#9

[eluser]aruntvla[/eluser]
[http_code] => 200 in curl means "HTTP_SUCCESS_NO_PROCESS" how i can change it as [http_code] => 0 (HTTP_SUCCESS)
#10

[eluser]Phil Sturgeon[/eluser]
This is probably a limitation of my CURL class sadly.

After execution of a request it closes the session ready for the next request to be made. I can modify the logic so that simple_get(), smiple_post(), etc always create, execute then close, but other methods keep it open?




Theme © iAndrew 2016 - Forum software by © MyBB