I am trying to read a JSON file (approx 8KB) using the file_get_contents()
method but the browser gives an error saying can't reach the site
. I don't think that the file size is a problem because I can read larger (e.g. 10KB) HTML or other files using the same function. My JSON file contains comments and I have a function that removes all the comments in order to give valid json to json_decode()
. I've even tried to rename the JSON file (currently names config.json) but it didn't worked. It seems like the contents are the problem but I don't know how to solve this issue. I am using WAMP in Windows. Below is the error screen my browser is showing.
Following is the code to read and var_dump()
JSON:
<?php
function clear($data) {
return preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $data);
}
$data = file_get_contents('login/config.json');
$data = clear($data);
var_dump($data);
?>
And the JSON file is below:
{
/*
This is the main configuration file. Some of the below fields are optional.
MAKE SURE THAT THIS CONFIG FILE IS OUT OF REACH OF THE OUTSIDE WORLD
---------------------------------------------------------------------------------
This file will contain some sensitive data that you must not be sharing with
others. For example: your app_secret code, database username or/and password
Make sure that this file is not stored in public_html or directory where
you usually store files that your users have access to.
---------------------------------------------------------------------------------
*/
/*
-------------------------------------------------------------------------------
REQUIRED
You get the app_id after creating a Facebook application.
If not have one, visit https://developers.facebook.com/apps
and click on the button saying 'Add a new App'
-------------------------------------------------------------------------------
*/
"app_id" : "",
/*
-------------------------------------------------------------------------------
REQUIRED
You get an app_secret code after creating a Facebook app.
DON'T SHARE THE app_secret with anyone. Whenever an API request call
requires this field as a parameter, the script makes a server-to-server
call. This field is never meant to be public.
-------------------------------------------------------------------------------
*/
"app_secret" : "",
/*
-------------------------------------------------------------------------------
REQUIRED
This is the path to the file to which users are redirected after logging in.
It's up to you which script do you want this field to refer to but don't
forget to include the Verify.php class file becuase the script reffered by
this field captures the response from login dialog and performs some actions.
-------------------------------------------------------------------------------
*/
"redirect_uri" : "",
/*
-------------------------------------------------------------------------------
REQUIRED
This field determines what data do you want from Facebook after logging
users in. To know more about available permissions, refer to below link
https://developers.facebook.com/docs/facebook-login/permissions/
-------------------------------------------------------------------------------
*/
"scope" : ["public_profile", "email"],
/*
-------------------------------------------------------------------------------
REQUIRED
This is an encrypted string unique to each login request. Options other than
"code" are also available but "code" is best suited for calls from servers.
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
Note: Manipulations in the Verify.php file may be reuired if this field
is manually set to value other than "code".
-------------------------------------------------------------------------------
*/
"response_type" : "code",
/*
-------------------------------------------------------------------------------
REQUIRED
If you gonna generate a CSRF token yourself, then set this to false.
By default, the script automatically generates one for you.
-------------------------------------------------------------------------------
*/
"generate_token" : true,
/*
-------------------------------------------------------------------------------
REQUIRED
If you want some data to be saved in database, then set this to true and
set up database credentials in below fields.
-------------------------------------------------------------------------------
*/
"save_to_db" : false,
/*
-------------------------------------------------------------------------------
OPTIONAL
This field is only required if "save_to_database" is set to true. If you
want to save data in a database, type in the database name here.
-------------------------------------------------------------------------------
*/
"db_name" : "",
/*
-------------------------------------------------------------------------------
OPTIONAL
This field is only required if "save_to_database" is set to true.
Give your database username here.
-------------------------------------------------------------------------------
*/
"db_username" : "",
/*
-------------------------------------------------------------------------------
OPTIONAL
This field is only required if "save_to_database" is set to true.
Give your database password here.
-------------------------------------------------------------------------------
*/
"db_password" : "",
/*
-------------------------------------------------------------------------------
OPTIONAL
This field is only required if "save_to_database" is set to true.
Give the table name where you want to save user information.
-------------------------------------------------------------------------------
*/
"db_table" : "",
/*
-------------------------------------------------------------------------------
OPTIONAL
This field is only required if "save_to_database" is set to true.
Populate the array with the data fields that you want to save in the database.
fields are: user_first_name, user_last_name, user_id, user_gender, user_age,
user_timezone, user_verified, user_friends, user_email, user_about_me,
user_actions_books, user_actions_fitness, user_actions_music, user_actions_news,
user_actions_video, user_birthday, user_education_history, user_events,
user_game_activity, user_groups, user_hometown, user_likes, user_location,
user_managed_groups, user_photos, user_posts, user_relationships, user_relationship_details,
user_religion_politics, user_status, user_tagged_places, user_videos, user_website,
user_work_history, user_custom_friendlists, user_insights, user_audience_network_insights,
user_mailbox, user_page_mailboxes, user_stream, user_notifications, user_pages,
Note: Choose what do you want to save wisely. You may never want to save a
user's Facebook notifications.
Note: Make sure you have given appropriate permissions (in the "scope" field)
Without permissions, your app can't pull data from Facebook.
-------------------------------------------------------------------------------
*/
"db_save" : ["user_id", "user_first_name", "user_last_name"],
/*
-------------------------------------------------------------------------------
OPTIONAL
If this field is not set, the script will find out the version your server
is running by manually calling some functions.
-------------------------------------------------------------------------------
*/
"php_version" : "",
/*
-------------------------------------------------------------------------------
REQUIRED
The duration (in minutes) you want the user session be saved for. When a
user logs in, the script flags it by setting user_id as a session veriable.
By default, this variable will only be saved for 60 minutes. That means,
the user will be logged in to the browser for 60 minutes if not requested to
log out. You can extend or lower the duration of this session storage here.
-------------------------------------------------------------------------------
*/
"session_lifetime" : "60"
}