Welcome Guest, Not a member yet? Register   Sign In
calling CI's Controller from external script using curl
#31

[eluser]tulipneo[/eluser]
Hi
Thanks for ur time.u did really give enough time.
so what i cocluded is Ci framework is based upon url handling as index.php/controller/method.
where as normal curl calling CI' stuff from outside CI framework understand simple urld

a sequnce of folder ended with a file name
ie project/UI/Theme/default/index.php

so the normal php curld does not undetstand the CI url handler mechanism.
what do u think?
i will try fiddler nd let u know but i m sure what i have stated above is the problem

i wonder is there is an way to handle that.

Br
Tulip

Br
Tulip
#32

[eluser]toopay[/eluser]
Fiddler is debugger tool, which provide more information to see whats happening.

Try this
Code:
<?php
    $url     =  'http://localhost/KSMS/index.php/messages/setInBox';
    $options = array(
        CURLOPT_PORT           => 8080,
        CURLOPT_RETURNTRANSFER => true,    
        CURLOPT_HEADER         => false,  
        CURLOPT_FOLLOWLOCATION => true,    
        CURLOPT_ENCODING       => "",    
        CURLOPT_USERAGENT      => "curl",
        CURLOPT_AUTOREFERER    => true,    
        CURLOPT_CONNECTTIMEOUT => 120,    
        CURLOPT_TIMEOUT        => 120,    
        CURLOPT_MAXREDIRS      => 10,      
    );

    $ch      = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

    $header['errno']   = $err;
    $header['errmsg']  = $errmsg;
    $header['content'] = $content;
    var_dump($header);
?>
#33

[eluser]tulipneo[/eluser]
Hi
Thanks again for ur patience and time.
the output i get is as bellow.

Code:
array(24)
{
["url"]=> string(42) "http://localhost:8080/KSMS/index.php/login"
["content_type"]=> string(9) "text/html"
["http_code"]=> int(200)
["header_size"]=> int(1654)
["request_size"]=> int(318)
["filetime"]=> int(-1)
["ssl_verify_result"]=> int(0)
["redirect_count"]=> int(1)
["total_time"]=> float(2.86)
["namelookup_time"]=> float(0)
["connect_time"]=> float(0)
["pretransfer_time"]=> float(0)
["size_upload"]=> float(0)
["size_download"]=> float(1685)
["speed_download"]=> float(589)
["speed_upload"]=> float(0)
["download_content_length"]=> float(1685)
["upload_content_length"]=> float(0)
["starttransfer_time"]=> float(0.985)
["redirect_time"]=> float(1.875)
["certinfo"]=> array(0) { }
["errno"]=> int(0)
["errmsg"]=> string(0) "" ["content"]=> string(1685) "

and surprisingly i see login page appears.does it need username and pass in curl.?

Br
Torand
#34

[eluser]toopay[/eluser]
Above code is follow redirection process, just like the browser did. As i expected, you put redirect() function somewhere in your controller(maybe in MY_Controller), thats why you accept 302 in your past attemp, and see the login form right now. Now you should know how to deal with your problems (working on it with 'POST'). My suggestion still same, build an API for that! Its more safe and apropriate to share resource to external script!
#35

[eluser]tulipneo[/eluser]
Hi
I understand and respect ur suggestion and advice and the way u have been helping and guiding me but as i m new to this so building an api seems to be pretty difficult for me.
i did a search on my source code and found that the bellow line is present in My_Controller.

Code:
if($this->session->userdata('loggedin')==NULL) redirect('login');
.

so now if i use authentication will it solve my problem.

Br
Tulip
#36

[eluser]toopay[/eluser]
[quote author="tulipneo" date="1303760774"]
so now if i use authentication will it solve my problem.
[/quote]
You can, send some $_POST params (username and password) via cURL 'POST' method, set Cookies, and so on. Googling on some good cURL resource and working on it, then you'll get what you want.

But, as i said before, i still suggests you to build an API to do that rather than bypassing your authentification process then get some resources via cURL.
#37

[eluser]tulipneo[/eluser]
Thanks for ur reply again. got ur point.but i don't understand what u mean by building an api.can u put some pointers on that where i can learn n try to do that.I think it would be much helpful to me.

Br
tulip
#38

[eluser]tulipneo[/eluser]
Hi friend,
Would it be possible on ur part to share with me any of ur personal id like yahoo,gtalk or skype so that i take less time from u and really learn fast.

sorry if the request is undue.

br
tulip
#39

[eluser]toopay[/eluser]
Basicly, API is a layer between client app to your database.

I already give you a link, good example of how to build an API on CodeIgniter. If you need good introduction, this article should help you, also you can search some resource on Google.
#40

[eluser]tulipneo[/eluser]
Thanks for the link.
Br
Tulip




Theme © iAndrew 2016 - Forum software by © MyBB