Get time zone of current user in php - php

I want to get the timezone of current surfer or user which is using the website. Like (GMT-6). Actually I have to put some check on users of Tulsa Oklahoma so some user in that state is using the website will come under that check.
I think if i become able to get GMT difference like -6 then I can put check. I want to do this thing preferably in php but can consider javascript also.
Thanks in advance.

Related

php dynamic link inquiry

I have a scheduler on my website. This scheduler lets you select a date/time and once you do, it presents you with a form to fill out with your name, email, and message to fill in.
Once you complete the form, it gives the user a thank you message.
However, what I would also like it to do is provide the user with a dynamic link using php.
Here's my problem...
The link that I need generated dynamically is for a url that is different than the website the user is on.
For example, if my website is www.website.com, the dynamic link I need generated needs to point the user to a different web server (that is currently an IP Address).
In a perfect world, I would like the user to be able to:
Schedule an appointment (they can do this now)
Be presented with a form to fill out (They can do this now)
Be presented with a dynamic link that will take them to a different url.
Have the access to the link expire within 30 minutes.
My question is this...
Can the user be presented with a link that masks the IP address of the alternate web server?
Can the dynamic link be set to be active between a time that matches their scheduled request. For example, if the user selects a time to access the content at 11:00am, can the link generated be set to work between those times?
I know this is a lot and I don't expect anyone to work on this solution. I really would like to know if this is something that is possible. Or, if someone out there might have some better suggestions on how this might work?
Thank you all for your time/suggestions!
Yes, it's possible.
A table could be something like this
user_id, appointment_date, url, time_submitted, unique_id
For the dynamic link that is presented to said user, you could display something like www.website.com/getLink/$unique_id
Where $unique_id is a controller/action on your page that does a redirect to the URL in the database.
To determine if it's been 30 minutes, in your controller/action just put some logic:
if( ( $time_submitted + 1800 ) < time() ) { echo "time expired" } else { ... }
This is very basic, but should steer you in the right direction.
How to redirect:
http://php.net/manual/en/function.header.php

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 tell the local time of a web visitor?

I'm building a blog engine in CakePHP and I would like to show the current visitor articles relative to their local time of day.
For visitors where it's currently morning, then I'll show articles related to starting your day and news items that happened overnight.
For visitors where it's currently evening, then I'll show articles that recap the highlights of major events during the day.
The only possible solution I can think of is to send their current timezone via Javascript to the server, but this can only happen after the web page has loaded. How can I did this at the time the CakePHP application renders the pagination view for index action?
Not exactly sure about php, However this will work in all language.
You better store difference in GMT for user using
i copied syntax from internet
var d = new Date()
var n = d.getTimezoneOffset();
now at very first page, run this code on page load and store value of n in DB using ajax or whatever.SO whenever your user login you get the time diff till he/she logout.Use that DB value (store in session for better use) to further process.
Further create function like
addGMTDiff()
{
// fetch stored value for difference and return
}
call this function after every sql query that fetched UTC time.

Expirable links to profile pages

I'm working on a project in core php with mysql for a tutor agency in which i have send mail to people with links to the tutor profile pages matching their required criteria. I want these links to be temporary links and want them to expire in say 72 hours, I'm not sure how to go about it. Any ideas?
originally link is something like this
"http://mysite.com/mysubdirectory/index.php?action=view_credentials&tutorid=".$tutor_id;
Thanks for help.
For anyone looking for the same answer as I was, I followed shadyyx and with a bit of effort i was done!! thanx everyone!
Some solution that bumped into my mind:
Create a DB table for these links where You would save the link, unique identifier (some hash), date it was created and date when it will expire.
Then create a page (script) that will get that link (containing not the full URL but the URL of that script and a unique identifier of the link stored in the DB). This script will try to search for the link identified by the unique hash while conditioning current date and time to the link expiry date.
If the link is found and not expired then You would redirect user to that page otherwise You will end up with a message that the link is expired or not found.
Should be pretty easy to implement.
Hope this idea will help You.
Use a table to store the TIMESTAMP when sending the link and redirect to an error if the link is accessed after TIMESTAMP+<72 hours>
Your tutor_id shall be stored in database before you send it. This would help sending unique id (just in case :), and do some checks if i.e. ID used come with is valid. So when anyone enters the link, your index.php should check if all parameters are valid, query DB agains value of $_GET['tutorid'] and see if it is not expired. And you'd know this because your DB record shall hold TIMESTAMP with creation date. Having creation date you can check how old it is and accept or reject the tutor_id
Protected Links is a PHP Script from codecanyon, it expires links after a fixed time and much more..
It can be used to expire a tutorial link or any other link in 72 hours or any number of hours, by IP address, for single user or mutiple users. A php coder can integrate this in their application with some effort.
http://codecanyon.net/item/protected-links-expiring-download-links/2556861

how to handle online status. guest, users etc

Whats the best way to keep track of how many users and guests are online? Im making a forum for fun and learning
Right Now I have a 2 fields in the users table called is_online and last_access_time.
If current time is 5 minutes or more than last_access_time i set is_online it to zero. And if the signed in user refreshes browser i set it to 1.
But what about guests? I wanna keep track on how many guests are on also
Another thing that would be really cool is to show what page the user is viewing. and on the page, forum thread for example, 5 guests, Homer and Shomer are viewing this page. But how should i structure this? Hmm maybe i should make another question for that.
i dont know what i should do
What do you suggest?
I'd use cookies for this. Set a cookie when the user enters (checking first to make sure one doesnt exist). Easy way to generate a unique id for that user is to hash their IP plus the current time.
$id = md5($_SERVER['REMOTE_ADDR'] . time());
Store that id in your database and use that to reference
You can check what page they are viewing by grabbing either $_SERVER['PHP_SELF'] or $_SERVER['REQUEST_URI'] near the top of your php source. Store that in the table. I'd take a look at php.net's explanation of whats stored in the _SERVER global, as it should help out quite a bit if you find that you need more then just the document they are on (ex index.php). Found here.
You may need to pull apart of the query string that was used to access that page, parse out the variables to determine the page they are requesting. Either way, this could all be done through cookies, or just use a single cookie to store the unique id and use your table for storing everything else.
You cannot know for certain which page a user is viewing, but you can keep track of which page they last viewed. Every time you deliver a page to a user, record that page's path in a database row associated with them. Voila.
To keep the number of guests, I suggest tracking the number of distinct unauthenticated IP/HTTP-User-Agent combinations seen on a certain page in the last X minutes.
I found this article on Web Monkey that might help you.
http://www.webmonkey.com/2010/02/how_many_users_are_on_your_site_right_now/

Categories