Page 1 of 2

[Solved] Error 500 :S

Posted: 11 Nov 2011, 18:09
by .HD.
Hi all! I am kinda new to the Maniaplanet SDK, so I wanted to start with the example files, but it does not work! :S

This is how my files look:

index.php

Code: Select all

<?php
/**
 * Maniaplanet Web Services SDK for PHP
 *
 * @copyright   Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL License 3
 * @author      $Author: maximeraoust $:
 * @version     $Revision: 10 $:
 * @date        $Date: 2011-09-27 15:21:52 +0200 (mar., 27 sept. 2011) $:
 */
require_once __DIR__.'autoload.php';

define('API_USERNAME', '.hd.|____');
define('API_PASSWORD', '_____');
define('SCOPE', 'basic');

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;
	// Uncomment to debug...
	//var_dump($e);
}
?>
<?php if(array_key_exists('HTTP_USER_AGENT', $_SERVER) && substr($_SERVER['HTTP_USER_AGENT'],
		0, 11) == 'ManiaPlanet'): ?>
<manialink version="0">
	<timeout>0</timeout>
	<frame posn="0 25 0">
		<label sizen="70 3"  halign="center" 
			   text="$o$ff0ManiaConnect example" />
		<?php if($player): ?>
		<label sizen="70 3" posn="0 -5 0"  halign="center" text="Hello <?php echo $player->login ?>" />
		<label sizen="70 70" posn="0 -10 0" autonewline="1" halign="center" 
			   text="<?php echo print_r($player, true) ?>" />
		<?php else: ?>
			<label sizen="40 3" posn="0 -5 0"  halign="center" text="Login" manialink="<?php echo htmlentities($loginURL) ?>"/>
		<?php endif ?>
	</frame>
</manialink>
<?php else: ?>
	<html> 
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>ManiaConnect example</title>
		</head>
		<body>
			<h1>ManiaConnect example</h1>

			<?php if($player): ?>
				<h3>Hello <?php echo $player->login ?></h3>
				<p>You are connected with your Maniaplanet account.</p>
				<pre><?php print_r($player) ?></pre>
				<p>
					<form action="" method="post">
						<input type="hidden" name="logout" value="1" />
						<input type="submit" name="submit" value="Logout" />
					</form>
				</p>
			<?php else: ?>
				<p>
					<a href="<?php echo $loginURL ?>">Login with your Maniaplanet account</a>
				</p>
			<?php endif ?>

		</body>
	</html>
<?php endif ?>
With that I end up with error 500....

Foobar.php

Code: Select all

<?php
/**
 * Maniaplanet Web Services SDK for PHP
 *
 * @copyright   Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL License 3
 * @author      $Author: maximeraoust $:
 * @version     $Revision: 2 $:
 * @date        $Date: 2011-09-08 18:03:11 +0200 (jeu., 08 sept. 2011) $:
 */
require_once __DIR__.'/../libraries/autoload.php';

try
{
	$foobar = new Maniaplanet\WebServices\Foobar();
	print_r($foobar->get());
	echo "\n";
	print_r($foobar->delete());
	echo "\n";
}
catch(\Maniaplanet\WebServices\Exception $e)
{
	echo "Error!\n";
	printf('HTTP Response: %d %s', $e->getHTTPStatusCode(),
		$e->getHTTPStatusMessage());
	echo "\n";
	printf('API Response: %s (%d)', $e->getMessage(), $e->getCode());
	echo "\n";
}
echo "\n";
?>
With that I end up with:

Code: Select all

HTTP Response: 0 API Response: (0)
I haven't edited anything except define('API_USERNAME', ''); and
define('API_PASSWORD', '');

I just don't understand why not the examples work... :/

Re: Error 500 :S

Posted: 11 Nov 2011, 21:18
by jonthekiller
Can you try with my example file ?

Code: Select all

<?php
require_once 'libraries/autoload.php';

define('API_USERNAME', 'jonthekiller|***');
define('API_PASSWORD', '***');
define('SCOPE', 'basic');

$maniaconnect = new \Maniaplanet\WebServices\ManiaConnect\Player(API_USERNAME, API_PASSWORD);
$player = $maniaconnect->getPlayer();

$loginURL = $maniaconnect->getLoginURL(SCOPE);
$logoutURL = 'http://www.bczteam.com/~jonthekiller/test.php';


if($player){

    $infos = $maniaconnect->getPlayer();
}


   if(isset($_POST['logout']))
   {
      $maniaconnect->logout();  
	  ?>
	  <html>
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>ManiaConnect example</title>
      </head>
      <body>
	           <h1>ManiaConnect example</h1>
			   <a href="<?php echo $logoutURL ?>">Click here to continue</a>
      </body>
   </html> 
<?php
	exit;
   }
	?>

<html>
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
         <title>ManiaConnect example</title>
      </head>
      <body>
         <h1>ManiaConnect example</h1>

         <?php if($player): ?>
            <h3>Hello <?php echo $player->login ?></h3>
            <p>You are connected with your Maniaplanet account.</p>
            <pre><?php print_r($player) ?></pre>
            <p>
               <form action="" method="post">
                  <input type="hidden" name="logout" value="1" />
                  <input type="submit" name="submit" value="Logout" />
               </form>
            </p>
         <?php else: ?>
            <p>
               <a href="<?php echo $loginURL ?>">Login with your Maniaplanet account</a>
            </p>
         <?php endif ?>

      </body>
   </html> 

You can see the result here : http://www.bczteam.com/~jonthekiller/test.php

It's not the best for disconnect but it works.

Don't forget the libraries folder.

Re: Error 500 :S

Posted: 12 Nov 2011, 13:30
by .HD.
It works! :D

I have no idea what you did, but now I am going to make my ML out from your code.


Thank you so much for your help :) :thumbsup:

Re: Error 500 :S

Posted: 12 Nov 2011, 14:11
by .HD.
Stupid me, didnt check it completely...

When I press Login, I get error 500, again....

The URL includes the code.

Re: Error 500 :S

Posted: 12 Nov 2011, 14:17
by jonthekiller
Have you create an API account in http://developers.maniaplanet.com ?

And after an ManiaConnect application with URL....?

Re: Error 500 :S

Posted: 12 Nov 2011, 14:38
by .HD.
jonthekiller wrote:Have you create an API account in http://developers.maniaplanet.com ?

And after an ManiaConnect application with URL....?
Yes


When I open index.php in my browser, I press login and it redirects me to: http://nytt1.no/(the_folder_I_use)/inde ... some_code)

And I get 500...

Re: Error 500 :S

Posted: 12 Nov 2011, 14:48
by .HD.
If you want, you can check it out here:
http://nytt1.no/slot/index.php

Re: Error 500 :S

Posted: 12 Nov 2011, 14:50
by jonthekiller
Have you the requirements?

- PHP 5.3 or newer
- cURL extension (http://php.net/manual/en/book.curl.php)
- JSON extension (http://php.net/manual/en/book.json.php)
- You must be able to make HTTPS requests on ws.maniaplanet.com

Re: Error 500 :S

Posted: 12 Nov 2011, 14:53
by .HD.
I have:
PHP 5.3.8
cURL
JSON

I am currently not sure about that https connection... Is it a way to check it? I am checking it out right now

Re: Error 500 :S

Posted: 13 Nov 2011, 19:27
by Boss-Bravo
Errors 500 are due to a bad configuration of your site. The origins are multiples.
I've got the error 500 last month, it's because the chmod of one of my folder is not on 705 but on 604, this create an error 500.
Are you in OVH ?