Session ID

justinedwards

New member
Joined
May 12, 2011
Messages
2
I'm sure this is posted elsewhere, but I don't have the patience to search for it. Using the Direct Admin API, I need to get the username that is currently logged in. I am not worried about decoding yet, I just want to see the encoded version right now, I have:

PHP:
<?php
include 'directadmin.php';
$sock = new HTTPSocket;
$visitorip = $_SERVER['REMOTE_ADDR'];
$sessionid = "";

$sock->connect("clicktwicehosting.com", 2222);
$sock->set_login("Username","Password");
$sock->set_method('POST');
$sock->query('/CMD_API_GET_SESSION',
   array(
    'ip' => "$visitorip",
    'session_id' => "$sessionid"
  ));
$result = $sock->fetch_body();
echo $result;
?>

Using this, I get: "error=1&details=no container class for data"

Any suggestions?
 
Because you must get session id from Directadmin, you can't use same session id that you get by session_id();


PHP:
<?php 
include 'directadmin.php'; 
$sock = new HTTPSocket; 
$visitorip = $_SERVER['REMOTE_ADDR']; 
$sessionid = $_COOKIE["session"]; 

$sock->connect("clicktwicehosting.com", 2222); 
$sock->set_login("Username","Password"); 
$sock->set_method('POST'); 
$sock->query('/CMD_API_GET_SESSION', 
   array( 
    'ip' => $visitorip, 
    'session_id' => $sessionid
  )); 
$result = $sock->fetch_body(); 
echo $result; 
?>

I hope it works for you
 
Last edited:
Re:

Thank you so much, that works perfectly. Now I just need to format the results. I wasn't sure what the name of the cookie was, and therefore was unable to pull the results into the variable correctly. I do appreciate your help.
 
Back
Top