View Full Version : visitor welcome message

01-08-2012, 05:16 AM
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

if (firstLogin()){
genSpecial(***load jquerie or css etc***);

can anyone help me figure out how to make this all work and load a box from jquerie or something similar? thanks

Philip M
01-08-2012, 10:12 AM
Here you are:-

<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();
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) {

<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.";



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.

01-08-2012, 11:43 AM
wow thanks for that :thumbsup: 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

Philip M
01-08-2012, 12:12 PM
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.

01-08-2012, 12:52 PM
Okey dokey, thanks for all the help,