SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Good morning/good evening PHP function

    How can I get php coding of good morning/good evening script when a user enter the site then it is show greeting.
    Last edited by ralph.m; Jan 28, 2013 at 01:08. Reason: removed link

  2. #2
    SitePoint Member bit101010's Avatar
    Join Date
    Jan 2013
    Posts
    5
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    A very simple solution, but a solution nonetheless. Take into account the different time zones of people around the world though. You might be looking for a more advanced solution if you want to change the timezone for each user, but this will give you an idea.
    Code:
    <?php
    
    function greeting(){
    
        $timeOfDay = date('a');
        if($timeOfDay == 'am'){
            return 'Good morning, welcome to our site';
        }else{
            return 'Good afternoon, welcome to our site';
        }
    
    }
    
    echo $timeOfDay;
    
    ?>

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Like bit10101 says, do you want to say "Good morning" depending on where the server is or where the user is?

    This tut might help you grapple with some of the issues: http://www.onlineaspect.com/2007/06/...th-javascript/

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Cups View Post
    Like bit10101 says, do you want to say "Good morning" depending on where the server is or where the user is?

    This tut might help you grapple with some of the issues: http://www.onlineaspect.com/2007/06/...th-javascript/
    I'm always a sucker for GeoIP: http://php.net/manual/en/book.geoip.php

  5. #5
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    996
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    GeoIP won't be as accurate as javascript which uses the user's system clock and seems like overkill for this!

  6. #6
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by TomB View Post
    GeoIP won't be as accurate as javascript which uses the user's system clock and seems like overkill for this!
    I don't feel that's overkill at all. Javascript can be just as inaccurate as GeoIP. Your counting on their clock to be set correctly, as well as the fact that Javascript can be turned off. All depends on its application and the necessity of the data.

  7. #7
    SitePoint Zealot 2ndmouse's Avatar
    Join Date
    Jan 2007
    Location
    West London
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On my shared server, geoIP functions don't work, presumably they need activating somewhere, but I don't have that kind of access. So, I would be restricted to javascript, in which case this might be helpful:

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <title></title>
    
    <script>
    function getTime() {
        var dd = new Date();
        var hh = dd.getHours();
    
        if(hh > 11){
        document.write("Good afternoon");
        }else{
        document.write("Good morning");    
        }
        
    }
     </script>
      </head>
      <body>
      <p><button onclick ="getTime()">Click for greeting based on time of local machine</button></p>
      </body>
    </html>
    Detect file changes remotely. SimpleSiteAudit is an early
    warning anti-hacker system which sends an alert on detection.

    PHP Find Orphan Files - Finds all the unreferenced files on your site.

  8. #8
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by 2ndmouse View Post
    On my shared server, geoIP functions don't work, presumably they need activating somewhere, but I don't have that kind of access. So, I would be restricted to javascript, in which case this might be helpful:

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <title></title>
    
    <script>
    function getTime() {
        var dd = new Date();
        var hh = dd.getHours();
    
        if(hh > 11){
        document.write("Good afternoon");
        }else{
        document.write("Good morning");    
        }
        
    }
     </script>
      </head>
      <body>
      <p><button onclick ="getTime()">Click for greeting based on time of local machine</button></p>
      </body>
    </html>
    GeoIP is a PECL extension, so yes it would need installed on the server running it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •