Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    cub
    cub is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    visitor welcome message

    Hi all new guy on the block here,

    I've got a website, and I want to add a welcoming message which hovers on a certain part of the page which only loads for the visitor for the first time they login, and won't again(presumably cookies used). And says something like "adjust your settings here.." I don't want it to be an external popup but something that loads on the page in a certain area, defined by me (PX-pixle reference)

    I think i nutted something out in a bit of PHP, this is what i've got so far
    PHP Code:
    <?php
        
    if (firstLogin()){
            
    genSpecial(***load jquerie or css etc***);
        }
        else{
            
    genRegular();
        }
    ?>
    can anyone help me figure out how to make this all work and load a box from jquerie or something similar? thanks
    David
    Last edited by cub; 01-08-2012 at 05:56 AM. Reason: not clear enough

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Here you are:-

    Code:
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function createCookie(name,value,days) {
    if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
    else {var expires = ""}
    document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }
    
    function eraseCookie(name) {
    createCookie(name,"",-1);
    }
    </script>
    </head>
    
    <body>
    <div id = "message"></div>
    
    <script type="text/javascript">
    if(!readCookie('beenHereBefore')) {
    document.getElementById("message").innerHTML = "You have not visited this site before.";
    createCookie('beenHereBefore', 'beenHereBefore', 365);  // 365 days persistence
    }
    else {
    document.getElementById("message").innerHTML = "You have visited this site before.";
    }
    
    </script>
    
    </body>
    </html>
    You could as an alternative have a <div> containing the message which is initially set to style="display:none", changed to style.display="block" if the cookie is not found (or vice-versa). You will need to position and style the <div> using css, and include a way of dismissing the message after it has been displayed (user clicks something). What are the settings to be adjusted?

    Bear in mind that many people erase their cookies at frequent intervals - sometimes daily, so you cannot be sure that the user is in fact a new visitor.

    That's the kind of song all young kids know, even if they have not heard it before. Steve Wright Show, BBC Radio2.
    Last edited by Philip M; 01-08-2012 at 10:36 AM. Reason: Typo

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    cub (01-08-2012)

  • #3
    cub
    cub is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    wow thanks for that hmm Ideally I don't want to use cookies because the user may login on another computer etc, and so on. Thats where I was thinking of using PHP for this part ans loading some jquerie or CSS so the user can also dismiss it after, any tips?

    Thanks in advance
    Dave

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    If you do not want to use Javascript cookies, then you must employ server-side scripting (PHP, ASP etc.) So ask in the PHP forum.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    cub
    cub is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Okey dokey, thanks for all the help,
    David


  •  

    Tags for this Thread

    Posting Permissions

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