The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Curl login security token invalid

Discussion in 'cPanel Developers' started by shahram mohseni, Mar 7, 2017.

  1. shahram mohseni

    shahram mohseni Registered

    Joined:
    Mar 7, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    tehran
    cPanel Access Level:
    Website Owner
    I try to login usin Curl, everything must be ok but finally it says like security token xyz is invalid and then i have to manually click the login button to continue. bellow is the final link it stops:
    Code:
    http://www.example.ir:2082/cpsess0807585904/frontend/paper_lantern/index.html?login=1&post_login=2531456137975
    my guess is i don't know what real path to save the cookie!
    any idea please how to solve this login using curl ? this is my code:
    Code:
    function createSession() { // Example details
    $ip = "127.0.0.1";
    $cp_user = "myUser";
    $cp_pwd = "myPass";
    $url = "http://www.example.ir:2082/login";
    $cookies = "cookies.txt";
    
    // Create new curl handle
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies );
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies ); // Save cookies to
    curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$cp_user&pass=$cp_pwd");
    curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
    
    $f = curl_exec($ch);
    $h = curl_getinfo($ch);
    curl_close($ch);
    
    $luckyUrl = $h['url'];
    // If we had no issues then try to fetch the cpsess
    if ($f == true and strpos($h['url'],"cpsess"))
    {
        // Get the cpsess part of the url
        $pattern="/.*?(\/cpsess.*?)\/.*?/is";
        $preg_res=preg_match($pattern,$h['url'],$cpsess);
    }
    
    header("Location: ".$luckyUrl);
    // If we have a session then return it otherwise return empty string
    return (isset($cpsess[1])) ? $cpsess[1] : "";
    
    }
    echo createSession();
    
    
     
    #1 shahram mohseni, Mar 7, 2017
    Last edited by a moderator: Mar 7, 2017
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,285
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you open a support ticket using the link in my signature so we can take a closer look? You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
  3. shahram mohseni

    shahram mohseni Registered

    Joined:
    Mar 7, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    tehran
    cPanel Access Level:
    Website Owner
    I am new to this site and understanding this site is really difficult .. i don't understand your words technically , i went to support menu to open a ticket but it did not accept my user pass which i'm using now !! then where is your signature and what is the way to use the link in it to open a support ticket ?? please do it yourself if possible, i just need the answer to main question and not such a long process man! thanks in advance .
     
  4. sktest123

    sktest123 Well-Known Member

    Joined:
    Jan 31, 2017
    Messages:
    69
    Likes Received:
    3
    Trophy Points:
    8
    Location:
    kochin
    cPanel Access Level:
    Root Administrator
  5. shahram mohseni

    shahram mohseni Registered

    Joined:
    Mar 7, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    tehran
    cPanel Access Level:
    Website Owner
    holy God ! the exact user pass i use to login and post here , but can't login to the ticket login ara you gave me !! let's remind I am free user i mean just simply some days ago created this account .. any way if possible please someone on behalf of me do post and do ticket this exact question in the area u need .. i don't understand why not answer here, but if necessary please someone do post and do ticket it . then me and many people will see the answer ..

    question was: with codes on top of this page i try to login to cpanel easily, but finally cpanel tells me '' The security token in your request is invalid.''
    my guess is that i don't know the real path to save the $cookie ! for example is it /home/myusername/cookie or what ?
    on the other hand this could be due to anything else.. is there a simple solution to this please ..?
     
  6. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    15,617
    Likes Received:
    296
    Trophy Points:
    433
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    You'll need to create an account in the ticket system to open a ticket. Your forums account is not associated with the ticket system in any way.
     
  7. shahram mohseni

    shahram mohseni Registered

    Joined:
    Mar 7, 2017
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    tehran
    cPanel Access Level:
    Website Owner
    what ? i logged into ticket panel finnnaly and now what a mess there.. hhhhh are u kidding me /
    i go to stackovechange or somewhere else to find the answer , even if couldn't find the anwer better i take it easy and forget it..
    if sombody knows the answer to this easy question please post it here .. bye .
     
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,285
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    A support ticket allows us the ability to access the system to get a better idea of what's happening. We're happy to help guide you through the ticket creation process. Which particular step are you having trouble with?

    Thank you.
     
Loading...

Share This Page