ManiaConnect doesn't work (bis)

Maniaplanet public API, ManiaConnect system and the open source PHP SDK.

Moderator: NADEO

User avatar
Boss-Bravo
Posts: 241
Joined: 10 Jan 2011, 18:26
Location: Devant mon PC :D
Contact:

Re: ManiaConnect doesn't work (bis)

Post by Boss-Bravo »

Hello all !

I still have an error on my script for Maniaconnect, and still don't understand why. Kimi and me tried a lot of things !

Code: Select all

<?php session_start();
			
			$api_username='*****|********';
			$api_password='*******';
			
			require_once __DIR__ . '/maniaplanet-ws-sdk/libraries/autoload.php';
			define('API_USERNAME', $api_username);
			define('API_PASSWORD', $api_password);
			define('SCOPE', '');

			try
			{
				$trackmania = new \Maniaplanet\WebServices\ManiaConnect\Player(API_USERNAME, API_PASSWORD);
			
				// URLs to log in and out
				$loginURL = $trackmania->getLoginURL(SCOPE);
				$logoutURL = $trackmania->getLogoutURL();
				
				if(isset($_POST['logout'])) {
					$trackmania->logout();
					header('Location: '.$logoutURL);
					exit;
				}

				// Retrive player information. If the user is not logged in, it will return false
				$player = $trackmania->getPlayer();

			}
			catch(\Maniaplanet\WebServices\Exception $e)
			{
				$player = null;
			}
			if ($player) {
				$_SESSION['player_login']=$player->login;
				$_SESSION['player_nickname']=$player->nickname;
				$_SESSION['player_path']=$player->path;
				$_SESSION['player_id']=$player->id;
			}
			else {
				$_SESSION['player_login'] = 'BUG';
			}
			
		header("Content-type: application/xhtml+xml"); echo "<?xml version='1.0' encoding='utf-8'?>\n";
		echo '<manialink>';
		
		echo '<label posn="0 0 5" text="' . $_SESSION['player_login'] . '"/>';
		echo '<timeout>0</timeout>';
		echo '</manialink>';
		
?>
We don't see the window to allow player to identify. $_SESSION['player_login'] return BUG.
Do you have an idea ?

Thanks.
User avatar
gouxim
Nadeo
Nadeo
Posts: 1186
Joined: 14 Jun 2010, 17:20

Re: ManiaConnect doesn't work (bis)

Post by gouxim »

You never use $loginURL, hence the player is never authentified, so $player is always null.

You either have to put a "login" link that points to $loginURL or to make a redirection to login $URL whenever $player is false (you should be careful about infinite redirect loop though).
Please do not PM for support. Instead, create a thread so that everyone can contribute or benefit from the answer! 8-)
User avatar
Kimi3
Posts: 510
Joined: 15 Jun 2010, 11:56
Location: France - Seine-et-marne (77)
Contact:

Re: ManiaConnect doesn't work (bis)

Post by Kimi3 »

Okay I think I understood why we have to put htmlentities($loginURL).

Thanks for your help again :)
Image
User avatar
gouxim
Nadeo
Nadeo
Posts: 1186
Joined: 14 Jun 2010, 17:20

Re: ManiaConnect doesn't work (bis)

Post by gouxim »

Just a quick note about htmlentities, since I had a bug with it a couple days ago.

You want to use htmlentities to encode your data inside the xml attributes and tags. For example let's say your nickname is "<manialink>". If you put your data in the XML (or HTML) without encoding it you might end up with:

Code: Select all

<manialink>
    <label text="<manialink>" />
</manialink>
This is invalid XML, but I think the Manialink browser will still display it. However if your nickname is ""</manialink>" (note the double quote) your page will be messed up:

Code: Select all

<manialink>
    <label text=""</manialink>" />
</manialink>
So you want to use htmlentities to safely encode all data and avoid XML errors.

However, htmlentites uses ISO8859-1 charset by default, and that will fail with most special characters (that, let's be honest, are found in most Maniaplanet nicknames, including mine :lol: ).

So be sure to force htmlentities() to use UTF-8, like that:

Code: Select all

htmlentities($some_data, ENT_COMPAT, 'UTF-8');
All in all, here's a little example:

Code: Select all

<?php $nickname = 'g๐uxim ツ$o$3c0︽$z$c3fnAdeo$o$3c0︾'; ?>
<manialink>
    <label text="<?php echo htmlentities($nickname, ENT_COMPAT, 'UTF-8'); ?>" />
</manialink>
Hope it helps
Please do not PM for support. Instead, create a thread so that everyone can contribute or benefit from the answer! 8-)
Post Reply

Return to “Maniaplanet Web Services”

Who is online

Users browsing this forum: No registered users and 1 guest