How I Can Get The Real Time & Date Of User with php - php

I have an Android App linked to an SQL database,
Now when the user posts a comment from the app, I want to get his real time and date (based on user's timezone).
I've already tried functions like date() and time() but these functions get the remote server time not the user's time.
Is there an api or similar, that I can use to do that - such as get time from IP address ?

Related

How to send FB notification at specific time to different time zones using PHP SDK?

My website is relaying heavily on FB. There is only FB login and all comunication with members happens through facebook. Users are notified using FB api about activities in site that they would care about. Users can choose between three options:
Never notify
Notify once a day(for MVP version I am good with hardcoded time, lets say, 9 in moorning, but probably aiming for possability for user to choose when they want to be notified about everything that has happened in last 24h)
Notify on-the-go
First and third are easy, my concerns lies on second option. Basically its similar to newsletter. Here is my idea of this process so far:
When ever some action that is of concern for user happens, notification about that is saved in database
if user logs into site before scheduled time notification is marked as read
if user does not log into site before scheduled time unread notifications will be included in cron job
every hour cron job is run. It matches the users time zone with current time so that only only users that are awake will recive notification. Users will get basic "there are new things in site" notification.
Problem: From FB I can get only offset as integer, not actual timezone. I have spent some time on reading about timezone and different formats and it strikes me that FB call to get timezone results in offset.
Sending newletter(notification in my case) to different time zones is complex but there are a lot of good resource available. However it seems that best way to do that is save user time zone as TZ database format America/New_York. So my question is dual
Is it possible to somehow get user time zone in TZ from facebook?
If not, what would be my best actions? Whats important is that I dont care if user dont get notification at exact time. With that I mean that I dont care about summer time difference. it would be ok if user could chose between moorning, afternoon and evening(and if for example he chooses moorning, then he would get notification 9:00 +/- 1 hour). I am open to ideas, at given point my main consern is to get MVP running.
$ch = curl_init("https://graph.facebook.com/v2.6/" . $user_id . "?fields=timezone&access_token=" . $fb_access_token);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1
));
$result = curl_exec($ch);
You can get the user timezone from the open graph api.
For converting the offset to an actual timezone see the answer here: Convert UTC offset to timezone or date

Facebook PHP SDK searching for posts within time-frame

I am attempting to fetch all posts and respective comments of a user within a certain time frame and I am having trouble finding the fields for the FB SDK. I see the "until" option but I do not see a usage/explanation of it.
me/posts?fields=object_id,shares,source,story,to,link&limit=10
I want to add a field that only collects posts between two dates. I will then get rid of the limit field. Any suggestions/resources will be great!
Thanks!
The information can be found here: https://developers.facebook.com/docs/graph-api/using-graph-api
A time-paginated edge supports the following parameters:
Until : A Unix timestamp or strtotime data value that points to the end of the range of time-based data
Since : A Unix timestamp or strtotime data value that points to the start of the range of time-based data.

Dealing with localised DateTime in Symfony2

I am working on a Symfony2 based website where client can request users to post at a particular time of the day for exemple from 9pm to 10pm.
Users are coming from all over the world and if a client request a post at 9pm, it s not based on his local time but on the user that will post for him.
Should i request my user what is his timezone and store it and then use it to convert the php DateTime of his post to his time zone and then check if he posted it at 9pm ? Could you show me a little code exemple for that ?
Also, what is the good way to ask a user his timezone ?
Edit : I want to ask the user his timezone and not get it programmatically because its actually his audiance timezone ( people who see his posts ) and not his personnal timezone.
best way is to use js timezone detection with library jsTimezoneDetect
next send via ajax request timezone to save in session
next use timezone in session to set timezone to date, you probably want to make twig extension for that so you can use it easily in twig.
1. all your dates must be in same timezone, for example UTC
you can set it in AppKernel.php
date_default_timezone_set('UTC');
to display date use something like this
$date->setTimezone(new \DateTimeZone($timezone));
where date is \DateTime object
if you want to ask user anyways you can create form with:
you create a form, use http://symfony.com/doc/current/reference/forms/types/timezone.html
field
and send that timezone to controller (AJAX or standard), set session with timezone, and for the rest handle it like like I described above by displaying date via your custom twig extension etc.

plan a effective algorithm to check who is online to the web site, with PHP and AJAX

i need some help to plan an effective algorithm to check who is online to my web site, with PHP and AJAX.
(i dont need you to write any sourse to me!!)
the biggest problem is how to know when the member get off.
in the end, it will be a list of online members that alwayes update, like what facebook have.
You can use a timestamp, with PHP you can do strtotime("now");
You add that timestamp to the user's table in MySQL, or their session info. Then, you update that timestamp whenever the user changes pages or accesses the site. To determine if the user is offline, you can remove the timestamp when the user logs off, and if the user just exits without logging off, you would just compare the timestamp to the current time.
For example, you could look to see if 15 minutes has passed by checking the timestamp variable like this:
if($timestamp <= strtotime("-15 minutes")) echo "User is offline";

How to restrict user from changing current date

My file tracking system deals with application submission. Date of the application is used to track total days taken to process each application. However, event though current date is shown, user able to change it to past date in my system. The system use mvc framework. What should i do to make the date inaccessible by user? Something like static.
Just store the date against the application id in the database when the application is first submitted and then ignore any mention of the date in the submitted form data.

Categories