Get session token

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blud731
    Junior Member
    • Jan 2014
    • 1

    #1

    Get session token

    Hi, all
    Who can say me about session token. How i can make it in script. In example PHP.
    What is request i need make?
  • gus
    Senior Member
    • Jan 2009
    • 134

    #2
    Assuming you have openssl and curl enabled in your php.ini file here's how I do it.
    There are prpbably better ways (there always are!)

    Code:
    <?php
    
    ob_start();
    $sessionToken = getACookie();
    ob_end_clean();
    
    echo $sessionToken;
    
    function getACookie(){
    	
    	$loginEndpoint= "https://identitysso.betfair.com/api/login";
    	
    	$cookie = "";
    	
    	$username = "XXXXX";
    	$password = "ZZZZZZ";
    
    	
    	$login = "true";
    	$redirectmethod = "POST";
    	$product = "home.betfair.int";
    	$url = "https://www.betfair.com/";
    
    	$fields = array
    		(
    			'username' => urlencode($username),
    			'password' => urlencode($password),
    			'login' => urlencode($login),
    			'redirectmethod' => urlencode($redirectmethod),
    			'product' => urlencode($product),
    			'url' => urlencode($url)
    		);
    
    	//open connection
    	$ch = curl_init($loginEndpoint);
    	//url-ify the data for the POST
    	$counter = 0;
    	$fields_string = "&";
    	
    	foreach($fields as $key=>$value) 
    		{ 
    			if ($counter > 0) 
    				{
    					$fields_string .= '&';
    				}
    			$fields_string .= $key.'='.$value; 
    			$counter++;
    		}
    
    	rtrim($fields_string,'&');
    
    	curl_setopt($ch, CURLOPT_URL, $loginEndpoint);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    	curl_setopt($ch, CURLOPT_POST, true);
    	curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
    	curl_setopt($ch, CURLOPT_HEADER, true);  // DO  RETURN HTTP HEADERS
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  // DO RETURN THE CONTENTS OF THE CALL
    
    	//execute post
    
    	$result = curl_exec($ch);
    
    
    	echo $result;
    
    	if($result == false) 
    		{
       	 		echo 'Curl error: ' . curl_error($ch);
    		} 
    	
    	else 
    		{
    			$temp = explode(";", $result);
    			$result = $temp[0];
    			
    			$end = strlen($result);
    			$start = strpos($result, 'ssoid=');
    			$start = $start + 6;
    		
    			$cookie = substr($result, $start, $end);
                            
    		}
    	curl_close($ch);
    	
    	return $cookie;
    }
    ?>
    Last edited by gus; 11-01-2014, 01:13 PM.

    Comment

    Working...
    X