Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

How do I get a visitor's local time using php?


  • Please log in to reply
2 replies to this topic

#1 Allen

Allen

  • Members
  • 337 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Canada
  • Local time:06:13 AM

Posted 06 September 2014 - 03:06 PM

I'm trying to figure this out and so far I have this

 

 
<Script>
document.title = "Service Status";
</script>
       <section id="about" class="padding-bottom bg-light">
 
<div class="container">
 
<div class="section-header scrollimation fade-up">
        <h1 class="text-center">Service Status</h1>
        <h1 class="text-center">As of <?php
        echo date("h:i:s A T F jS l Y ") ?></h1>
        <center>
            <div class="text-center content">
                <?php require "./utils/check.php"; ?>
            </div>
            </center>
            </div>
            </div>
            </section>
 
it display's the machine's local time not the visitor's local time 

Hey everyone I'm Allen I am a young web developer/designer/programmer I also help people with computer issues including hardware problems, malware/viruses infections and software conflicts. I am a kind and easy to get along with person so if you need help feel free to ask.

BC AdBot (Login to Remove)

 


#2 neilbuddy

neilbuddy

  • Members
  • 42 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Rochester MN
  • Local time:04:13 AM

Posted 06 September 2014 - 06:24 PM

You would have to use Javascript to send the users timezone to your PHP script.

 

Using jquery and PHP:

$(document).ready(function() {
        if("<?php echo $timezone; ?>".length==0){
            var visitortime = new Date();
            var visitortimezone = "GMT " + -visitortime.getTimezoneOffset()/60;
            $.ajax({
                type: "GET",
                url: "timezone.php",
                data: 'time='+ visitortimezone,
                success: function(){
                    location.reload();
                }
            });
        }
});

In timezone.php:

<?php
    session_start();
    $_SESSION['time'] = $_GET['time'];
?>


#3 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:13 AM

Posted 08 September 2014 - 08:52 PM

Most likely you don't actually want to do that. If you want to display the user's local time on the page, use JavaScript to do that. If you want to record the user's semantic time when they did something, then again, use JavaScript to do that. Note that if you were going to use this for any sort of contest or similar that you're entirely trusting the client here and they could say their time zone was UTC+1234 hours to the server, so you still need server-side validation.

 

If you want to tell the user how long ago something occurred or similar (e.g. "user posted X 10 minutes ago") consider using a plugin specifically designed for this purpose, such as TimeAgo.

 

Billy3


Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users