Slim PHP Framework causing 'Fail to open page' - php

I have set up a REST API using the Slim PHP framework, which works perfectly when using requests i.e http://mysite.com/class/id.
But when I navigate to http://mysite.com/, I get the following error in Safari:
Safari can’t open the page “http://mysite.com/”.
The error is: “cannot decode raw data” (NSURLErrorDomain:-1015)
Please choose Safari > Report Bugs to Apple, note the error number,
and describe what you did before you saw this message.
Please can you tell me where I am going wrong?
include_once('config.php');
require 'Slim/Slim.php';
$app = new Slim();
$app->post('/user/create', 'create_user');
$app->get('/user/:id', 'info_user');
$app->post('/user/:id', 'update_user');
$app->delete('/user/:id', 'delete_user');
$app->post('/user/validate', 'validate_user');
$app->get('/user/:id/venues', 'venues_user');
$app->get('/user/:id/queues', 'queues_user');
$app->post('/venue', 'create_venue');
$app->post('/venue/:id', 'update_venue');
$app->delete('/venue/:id', 'delete_venue');
$app->get('/venue/:id', 'info_venue');
$app->get('/venue/:id/queues', 'queues_venue');
$app->post('/queue', 'create_queue');
$app->post('/queue/:id', 'update_queue');
$app->delete('/queue/:id', 'delete_queue');
$app->get('/queue/:id', 'info_queue');
$app->run();

When using PHPFog and Slim, you have to set the HTTP Version to 1.0 rather than 1.1.
You can do this by adding a parameter to the variable:
$app = new Slim(array('http.version' => '1.0'));
This was solved thanks to the help of the Slim framework creator!
Hope this helps someone else!

Perhaps you need an entry such as:
$app->get('/', 'index_page');

Related

Issue with third party Google Analytics sdk

I have code which works above the php 5
its actually GA Library, here is its github project.
I have cloned the project theiconic/php-ga-measurement-protocol
Since I am new to PHP, I have no idea where to put this code, Please help me here this project should be installed via composer via code
{
"require": {
"theiconic/php-ga-measurement-protocol": "^2.0"
}
}
After this step I need to create a file something.php and I need to put the code below, I am having problem on locating autoload.php on my server, Please look at the code below to understand what i am saying.
<?php
//grab the data that Calendly sent in the webhook and store it in a variable called $objCalendlySubmission...
$objCalendlySubmission = json_decode(file_get_contents('php://input'));
//We've passed the Google client_id in Calendly's placeholder for utm_term. Feel free to pass it differently, this is just an example
if(property_exists($objCalendlySubmission->payload->tracking, 'utm_term') && !empty($objCalendlySubmission->payload->tracking->utm_term)) {
$strPageViewed = 'calendly_conversion.html'; // We use different page names depending on what type of event was scheduled via Calendly
sendGoogleAnalyticsPageView($objCalendlySubmission->payload->tracking->utm_term, $strPageViewed);
}
function sendGoogleAnalyticsPageView($strGAClientId, $strURL) {
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol” **I dont know where is it located exactly on my xampp server, Please guide me here**
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup **please help me here**
$analytics
->setProtocolVersion('1')
->setTrackingId('YOUR-GA-UA-ID-GOES-HERE')
->setClientId($strGAClientId)
->setDocumentLocationUrl($strURL);
$analytics->sendPageview();
}
?>
In the above code towards middle line
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol”
I dont know where is it located exactly on my xampp server, Please guide me here
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup
Here is the image of Project folder
Project structure Part 2

Google Calendar API causing HTTP Error 500

I'm using the new Google Calendar API v3. I'm trying to obtain the users calendar list using the PHP library. If I make the request directly using CURL then it works fine, but for some reason when I try and use the PHP library it fails and throws a 500 error.
Here's the (abbreviated) code:
$this->calendarAPI = new apiCalendarService($this->client);
$calendar_list = $this->calendarAPI->calendarList->list();
If I var_dump the contents of $this->calendarAPI->calendarList then I get an object as I would expect. It's only when I call the list method that everything goes wrong.
Can anyone help or am I going to have to write my own library and interact with the API protocol directly?
Ok, so it turns out this is a mistake in the docs. Instead of calling a method called list() you have to call listCalendarList() so the second line should be:
$calendar_list = $this->calendarAPI->calendarList->listCalendarList();

Slim PHP Framework Help

I just added the Slim framework to my website in order to create a rest API. But I currently have a problem. I wrote this code as a test to check to see if a get request would work, but whenever I try calling the url, http://mysite.com/api/rest/hello/max, I get a website not found error. Please can you tell me what is going wrong?
Slim::init();
Slim::get('/hello/:name', 'hello');
function hello($name) {
echo "Hello, $name!";
}
Slim::run();
You have propably forgotten to put the .htaccess file provided with Slim in the same directory as your index.php.

PHP Facebook App Problem

I am working on my second Facebook App and seem to have run into a problem. On my first App, I used
$user_id = $facebook->require_login();
to get the ID of the user that was using my app. It worked great, and still does. However, on my second App, I used the same thing but keep getting the old 500 Internal Server Error. ( Using Opera as browser ) Not sure why, since the exact same code works on the other App. Here it is:
<?php
require_once('facebook.php');
$appapikey = 'APIKEYHERE';
$appsecret = 'SECRETKEYHERE';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
echo $user_id;
echo "Hello!";
?>
I have checked the server and PHP logs, none of them report any errors.
500 internal server error ussually comes from an error in your code, not browser related anyway.
Also, the API should work just fine. Try replacing
include 'facebook.php';
with
require_once('facebook.php');
Also, is this everything you have in the code?
How long ago did you write your first app? Facebook has got rid of the old APIs (although left them there for old apps to continue to work), but all new apps have to use the Graph API instead.
Take a look here for more information.
http://developers.facebook.com/docs/guides/canvas/
Also, take a look at this documentation.
http://developers.facebook.com/docs/api

Ambigious PHP Web Service error message

did anyone ever encounter the following error message
Extra content at the end of the document
when trying to consume a PHP web service from a client
that runs on php 5.3?
I guess soembody did. ^^
Anyways, I don't seem to find an error in the server code which
works for several clients of mine for quite some time now.
Is this possibly a php problem in the recent version?
My client code looks like this:
try
{
$client = new SoapClient("http://someserver/server.php?wsdl", array('trace' => 1, 'feature' => SOAP_SINGLE_ELEMENT_ARRAYS));
}
catch(Exception $e)
{$this->handleException($e);}
Any thoughts on this would be highly appreciated.
TIA
K
Sounds like the XML is not well formatted. Is the WSDL generated or created manually?

Categories