How to automatically log in as an affiliate

You can do it using our API:
<?php
/* *************** CONFIGURATION PART ****************** */
$papURL = 'https://URL_TO_PostAaffiliatePro/'; //URL of Post Affiliate Pro installation
$mUsername = 'merchant@username.com'; //replace it with your merchant username
$mPassword = '123456'; //replace it with your merchant password


//username of the affiliate you want to log in with
$usernameOfAffiliate = 'affiliate@example.com';
/* *************** /CONFIGURATION PART ***************** */

//The API file PapApi.class.php can be downloaded in the merchant panel: Tools> Integration> API Integration
include_once('PapApi.class.php'); //This include assumes the API file is in the same directory as this script

$session = new Pap_Api_Session($papURL.'scripts/server.php');
if (!@$session->login($mUsername, $mPassword)) {
    die('Cannot login. Message: '.$session->getMessage());
}

// load the affiliate to make sure they exist and to be able to use the needed userId
$affiliate = new Pap_Api_Affiliate($session);
$affiliate->setUsername($usernameOfAffiliate);
try {
    $affiliate->load();
} catch (Exception $e) {
    die('Can not load affiliate: '.$e->getMessage());
}

$request = new Gpf_Rpc_FormRequest('Pap_Auth_LoginKeyService', 'getLoginKey', $session);
$request->addParam('userId', $affiliate->getUserid());

try {
    $request->sendNow();
} catch(Exception $e) {
    die('API FormRequest error: '.$e->getMessage());
}

$response = $request->getStdResponse();

if ($response->success == 'Y') {
    $loginKey = $request->getForm()->getFieldValue('LoginKey');
} else {
    die('Error loading login keys. '.$response->message);
}

//redirecting to the affiliate login page and logging in
header('Location: '.$papURL.'affiliates/login.php?LoginKey='.$loginKey);      
?>
 
NOTE: You have to replace the URL_TO_PostAffiliatePro with the real URL of your Post Affiliate Pro installation