Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • hiepdang Friend
    #191529

    Im not sure if this is right place to post, im sorry if it’s not.
    I have studying ja nex in my localhost, and im writing my own script. ANd now i want to using CURL to login to users database from joomla site. I want to make a single sign on for my site (joomla and my own script)
    This is my code:
    login.php (in http://localhost/management/login.php)

    [PHP]<?php
    $uname = ‘admin’;
    $upswd = ‘admin123456’;
    $url = “http://localhost/joomla/index.php”;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE );
    curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE );
    curl_setopt($ch, CURLOPT_COOKIEJAR, realpath(‘./cookie.txt’));
    curl_setopt($ch, CURLOPT_COOKIEFILE, realpath(‘./cookie.txt’));
    curl_setopt($ch, CURLOPT_HEADER, TRUE );
    $ret = curl_exec($ch);
    if (!preg_match(‘/name=”({32})”/’, $ret, $spoof)) {
    preg_match(“/name='({32})’/”, $ret, $spoof);
    }
    // POST fields
    $postfields = array();
    $postfields[‘username’] = urlencode($uname);
    $postfields[‘passwd’] = urlencode($upswd);
    $postfields[‘option’] = ‘com_user’;
    $postfields[‘task’] = ‘login’;
    $postfields[$spoof[1]] = ‘1’;
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    echo $ret = curl_exec($ch);
    // Get logged in cookie and pass it to the browser
    preg_match(‘/^Set-Cookie: (.*?);/m’, $ret, $m);
    $cookie=explode(‘=’,$m[1]);
    setcookie($cookie[0], $cookie[1]);
    ?>[/PHP]

    But when i run, it show me that component not found. And it show
    [PHP]
    HTTP/1.1 100 Continue HTTP/1.1 404 Component not found Date: Sat, 18 Oct 2013 04:01:29 GMT [/PHP]

    So, could you please help me to understand, what am i wrong?
    do i miss the form token and how can i insert the form token?

    Thank you so much for your attention and help. :-*

    Ninja Lead Moderator
    #509845

    Hi hiepdang,

    Please try to check the following:

    1) Check the curl_init is enabling on your site by Go to Admin site -> Site ->System Information, see the screenshot

    2) Use sample on this link and test CURL lib: http://php.net/manual/en/book.curl.php


    1. curl
    hiepdang Friend
    #509978

    <em>@Ninja Lead 394723 wrote:</em><blockquote>Hi hiepdang,

    Please try to check the following:

    1) Check the curl_init is enabling on your site by Go to Admin site -> Site ->System Information, see the screenshot

    2) Use sample on this link and test CURL lib: http://php.net/manual/en/book.curl.php</blockquote>

    Thanks for your reply. I’m running on CentOS server with apache + mysql, and Curl is enable (check attached files)

    I also testing my Curl by running this code:

    [PHP]<?php
    $ch = curl_init(“http://www.google.com/”);
    $fp = fopen(“google.txt”, “w”);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    ?>[/PHP]

    And this is what i got (It’s big size file so i attached it.

    That mean Curl is running fine.

    (Im sorry but google.txt cannot attached because of limit size for txt file.)

    I think something wrong when send data to my joomla site.
    Could you please help me?


    1. curl
    Ninja Lead Moderator
    #510390

    From your above script, you can try to change with my below suggestion

    function download($file_source, $file_target) {
    $rh = fopen($file_source, 'rb');
    $wh = fopen($file_target, 'w+b');
    if (!$rh || !$wh) {
    return false;
    }

    while (!feof($rh)) {
    if (fwrite($wh, fread($rh, 4096)) === FALSE) {
    return false;
    }
    echo ' ';
    flush();
    }

    fclose($rh);
    fclose($wh);

    return true;
    }

    Usage:

    <blockquote>$result = download(‘http://url’,’path/local/file’);</blockquote>
    You can then check if everything is ok with:

    <blockquote> if (!$result)
    throw new Exception(‘Download error…’);</blockquote>

    + Or you can user other way


    <?php
    set_time_limit(0);
    $fp = fopen (dirname(__FILE__) . '/localfile.tmp', 'w+');//This is the file where we save the information
    $ch = curl_init(str_replace(" ","%20",$url));//Here is the file we are downloading, replace spaces with %20
    curl_setopt($ch, CURLOPT_TIMEOUT, 50);
    curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch); // get curl response
    curl_close($ch);
    fclose($fp);
    ?>

    hiepdang Friend
    #511401

    <em>@Ninja Lead 395464 wrote:</em><blockquote>From your above script, you can try to change with my below suggestion </blockquote>

    Thank for you reply, but i guest you miss my point.
    My main point is i want to login to a joomla 2.5 site using Curl.
    As my first post, i have joomla 2.5 at localhost/joomla and my own script at:
    login.php (in http://localhost/management/login.php)

    I try to login to joomla using Curl but cannot.
    Could you please check it again and suggest any solution? :-*

    Ninja Lead Moderator
    #511431

    For now, I have no idea with this but hope these references can help you:

    Joomla 2.5 login with curl and CURL login by script to a Joomla website

Viewing 6 posts - 1 through 6 (of 6 total)

This topic contains 6 replies, has 2 voices, and was last updated by  Ninja Lead 11 years ago.

We moved to new unified forum. Please post all new support queries in our New Forum