PHP Function for get a session using TASK API with IIS

Hello there!

I’ve created a PHP function to help you create a session using TASK API for PHP with IIS.

Here is the code:

<?php

function authenticationMSTR($server, $project, $user, $pass, $documentId, $dashboardMode) {
$projectUrl = str_replace(" ","%20",$project);
$projectTask = str_replace(" ","+",$project);
$username = 'username';
$password = 'password';

$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
));

$url = file_get_contents("http://$server/MicroStrategy/asp/TaskAdmin.aspx?
taskId=getSessionState&taskEnv=xml&taskContentType=xml&server=$server&project=$
projectTask&uid=$user&pwd=$pass");

$data=simplexml_load_string($url);

foreach($data->children() as $child) {
foreach($child->children() as $child1) {
$sessionmstr = $child1;
break;
}
}

echo "http://$server/MicroStrategy/asp/Main.aspx?evt=2048001&src=Main.aspx.2048001&visMode=0&currentViewMedia=$dashboardMode&documentID=$documentId&server=$server&Project=$projectUrl&port=0&share=1&hiddensections=header,path,dockTop,dockLeft,footer&usrSmgr=$sessionmstr";
}
}
?>

Where:

$server: is your server ip/dns
$project: Name of the project
$user: MicroStrategy Username
$pass: MicroStrategy Username Password 
$documentId: Document ID
$dashboardMode: View media. Example: Use 8 for flash and 2 for DHTML.
$username = Put the Username for login in your TaskAdmin page. 
$password = Put the password for the Username used to login in TaskAdmin page.

Just save this in a file as Authentication.php. Now create another file like this:

<?php
include "Authentication.php";
?>
<html>
<head>
<title>Title</title>
<?php header("Content-Type: text/html; charset=ISO-8859-1",true);?>
</head>

</html>

Just use your own info in those above parameters.

Save this file as test.php in the same folder that you saved your Authentication.php.
Those files must be saved inside your Apache PHP folder. If you use Xampp, is must be saved inside the htdocs folder.

Open test.php in your browser and you will see your dashboard!

 

Hope it helps!

God bless you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s