Part of the EllisLab Network
   
 
Curl Login Problem
Posted: 09 December 2009 02:37 AM   [ Ignore ]  
Grad Student
Rank
Total Posts:  31
Joined  12-09-2009

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*********************

<?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_BUFFERSIZE10);
$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….

Profile
 
 
Posted: 09 December 2009 03:05 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  279
Joined  07-20-2008

Enclose your code within [code] [/code] tags so others can read it well smile

 Signature 

I heard that big fonts are in this summer? All the cool kids seem to be doing it!  | Mario Visic - Freelance Web Programmer | HumorList - It’s got stripes!

Profile
 
 
Posted: 10 December 2009 02:32 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  650
Joined  11-18-2008

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.

 Signature 

Quality Coder | Looking for work? | Logo by InsiteFX

Profile
 
 
Posted: 10 December 2009 03:28 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  31
Joined  12-09-2009

*********view page code here***************

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

*********************************************************************************


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

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….

Profile
 
 
Posted: 10 December 2009 03:35 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  650
Joined  11-18-2008

are you receiving an error message?
is it not responding as it should be?
How is it “not working correctly”?

 Signature 

Quality Coder | Looking for work? | Logo by InsiteFX

Profile
 
 
Posted: 10 December 2009 07:01 AM   [ Ignore ]   [ # 5 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3153
Joined  06-11-2007

Grab the new version and use “echo $this->curl->debug()” for more information.

 Signature 

————————
Blog | Twitter | GitHub | BitBucket
————————-
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management

Profile
 
 
Posted: 11 December 2009 12:14 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  31
Joined  12-09-2009

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….......

Profile
 
 
Posted: 15 December 2009 09:01 AM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  31
Joined  12-09-2009

=============================================
CURL Test
=============================================

Responce

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html >
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Untitled Document</title>
<
style type="text/css">
<!--

-->
</
style>
<
link href="style.css" rel="stylesheet" type="text/css" />
<
style type="text/css">
<!--
.
style2 {
font
-size18px;
font-styleitalic;
color#999999;
}
-->
</
style>
</
head>

<
body>


<
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>

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


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

<
div class="User" style="margin-top:0;">
<
div class="Username">&nbsp;</div>
<
div class="TextBox"><input name="submit" type="submit" value="" id="submitbutt" /></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>
</
form>



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


</
body>
</
html>

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


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… rolleyes

Profile
 
 
Posted: 16 December 2009 12:21 AM   [ Ignore ]   [ # 8 ]  
Grad Student
Rank
Total Posts:  31
Joined  12-09-2009

[http_code] => 200 in curl means “HTTP_SUCCESS_NO_PROCESS” how i can change it as [http_code] => 0 (HTTP_SUCCESS)

Profile
 
 
Posted: 17 December 2009 07:02 AM   [ Ignore ]   [ # 9 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3153
Joined  06-11-2007

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?

 Signature 

————————
Blog | Twitter | GitHub | BitBucket
————————-
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management

Profile
 
 
Posted: 17 December 2009 08:54 AM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  31
Joined  12-09-2009

i got few classes from phpclasses.org,regarding curl. so can i use tat classes in codeignitor????

Profile
 
 
Posted: 17 December 2009 10:43 AM   [ Ignore ]   [ # 11 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  3153
Joined  06-11-2007

With some modifications im sure they will work fine. I will have an improved CodeIgniter class posted before the weekend is up if you can wait that long, otherwise I wish you good luck with the other classes. grin

 Signature 

————————
Blog | Twitter | GitHub | BitBucket
————————-
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management

Profile
 
 
Posted: 06 January 2010 09:25 AM   [ Ignore ]   [ # 12 ]  
Grad Student
Rank
Total Posts:  31
Joined  12-09-2009

I am waiting for your replies now…so…...if you know any idea or suggestions post here.............arun chandran smirk

Profile