Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Remote login

Hi,
I have an application and i want to integrate it with osTicket.

I have a list of articles, and when rejecting one of them, i need to create a new ticket.

Im trying using CURL.
I try directly sending the info to /scp/tickets.php but a login form was the answer.

I try doing the login.
In /scp/login.php the login its ok. The $_SESSION is ok.
But then, when redirecting to tickets.php the user info in $_SESSION is gone.

Whats the problem ?

Thanks

Comments

  • Hi Innatia,
    Apologies, I know this does not answer your question, but could you possibly explain a little more about how you've done this? I'm trying to get my system to automatically log a user into osTicket by submitting the user information and password through a POST header command to /scp/login.php and im getting stuck!

    Cheers

  • $ch = curl_init('http://DOMAIN/scp/login.php');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=USERNAME&passwd=PASSWORD');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL
    $data = curl_exec($ch);
    curl_close($ch);

    var_dump($data);


    parsing the code, i do the login.
    But when redirecting, the session is not save.
  • you should try to get your session id out off the response a normal browser wille get this with as a cookie so you need to strip the headers and find your id
    and them you have to pass it to the site using:CURLOPT_COOKIE than the site will recognize you and you will be logged in

    CURLOPT_COOKIESESSION has to be false.
  • Thank you. That work :)
    Here is the code.

    <?php
    $ch = curl_init('http://DOMAIN/scp/login.php');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=USERNAME&passwd=PASSWORD');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1); // DO NOT RETURN HTTP HEADERS
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL
    $data = curl_exec($ch);
    curl_close($ch);

    $pattern = \"#Set-Cookie: (.*); path=(.*)\n#\";
    preg_match_all($pattern, $data, $matches);
    $cookie = str_replace('Set-Cookie: ', '', trim($matches[0][0]));

    $ch = curl_init('http://DOMAIN/scp/tickets.php');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'a=open&email=EMAIL&name=NAME&source=Email&deptId=4&subject=SUBJECT&issue=CONTENT&alertuser=1');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL
    $data = curl_exec($ch);
    curl_close($ch);
    ?>
Sign In or Register to comment.