0

I am creating a test backend for my app using the Parse.com PHP SDK. Seems that when I deploy the PHP code on localhost using MAMP and got perfect results in JSON strings but when I tried to deploy the php code on a free hosting site (in my case UltimateFreeHost.in which has capability to host php 5.4 and above codes) I don't get a JSON response instead I get HTML strings.

following is my php code

<?php
// define location of Parse PHP SDK, e.g. location in "Parse" folder
// Defaults to ./Parse/ folder. Add trailing slash
define( 'PARSE_SDK_DIR', './Parse/' );

// include Parse SDK autoloader
require_once( 'autoload.php' );

// Add the "use" declarations where you'll be using the classes
use Parse\ParseClient;
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;

// Init parse: app_id, rest_key, master_key
ParseClient::initialize('OgSGF8N3zcXrDcfRfu0Kiek4WU9yewWstnP4dw9Z', 'bFAWDmGEzN9c9iiMYocWiQtO4IeOTNLdRjWlr52a', 'a4WjNhTCXycNQ6r1vasWTdIRjAvmRFEi1teGATY6');

// save something to class TestObject
$testObject = ParseObject::create("TestObject");
$testObject->set("foo", "Carva");
$testObject->save();
$response["success"] = 1;
$response["message"] = "Product successfully created.";
// echoing JSON response
echo json_encode($response);
?>

this is my response on localhost enter image description here

This is my response when deployed on free host on internet

enter image description here

I also would like to mention that when I hit the URL of the PHP file in chrome I get the desired JSON response.

Please help me I am new to backend development help me clear my basics

0

1 Answer 1

2

Assuming that you aren't hosting any HTML or JavaScript with your free host, it appears as though the host is wrapping your website's content with their own content for ads.

Many free hosts take your website's content and add their own HTML and/or Javascript to display advertisements. If your host is doing this, it will not be a suitable host for a JSON API.

Sign up to request clarification or add additional context in comments.

6 Comments

can you suggest me some decent host for this purpose then... and also when i decoded the HTML response I found out that the php code never runs when I hosted it on internet...HTML response simply said that "This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support"
My recommendation would be to use a paid host, as this will provide some guarantee of support and you will never have ads like this on your site. I have personally used Dreamhost and 1&1 before, but there are hundreds of them to choose from. Google App Engine offers free hosting, though it isn't a LAMP server so it may not fit your needs.
But the main thing is I never get such response when I hit the URL using a web-browser.... no ad is shown and the php code also runs and uploads data to Parse.com
It may not be an add, but if you have not HTML or JavaScript files on your host, then they are injecting something (even if it is just tracking).
I have no problem with them tracking my things but why isn't the PHP code not being executed ...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.