...

View Full Version : How do I bypass a splash page if someone has already seen it.



reach100
11-13-2012, 09:51 PM
HI there, we have a splash page set up on http://www.sealfit.com. I would like a visitor to see the splash page a maximum of 3 times. If they fail to sign up for the offer, and click "No Thanks, Take me to the Homepage" 3 times, I would like them to bypass the splash page from then on.

I guess I need to set a cookie or something? Can someone outline the basic steps I need to take to accomplish this?
Thank you,
Rich V

WolfShade
11-13-2012, 09:54 PM
Cookie would be the best solution. Keep track of the number of times the splash screen has been viewed, once the value is "equal to or greater than" 3, stop showing the splash screen.

reach100
11-13-2012, 10:00 PM
Can you point me to a resource or help me set this cookie? I don't know how to set a cookie then forward to an alternate url based on the cookie information.

I ca't easily find an explanantion searhing the web so far.

WolfShade
11-13-2012, 10:08 PM
Here is a pretty good tutorial on cookies in JavaScript (http://www.quirksmode.org/js/cookies.html). Read, set, delete, etc.

Basically, I guess the index page would contain the splash screen. Before the splash screen displays, check for the EXISTENCE of the cookie - if there isn't one, write the cookie (name it "splash") and give it a value of 1, then display the splash. If there IS a cookie, check the value - if it's less than 3, display the splash and add 1 to the value of the splash cookie. If it's greater than 3, don't display the splash (I guess a redirect before the splash displays would prevent it from showing.) A simple "IF" conditional can determine whether to show the splash page or redirect to another URL.

felgall
11-14-2012, 01:21 AM
Note that this is a situation where you need the JavaScript attached in the head of the page rather than at the bottom of the body where most JavaScript goes.

Basically the processing would be

1. set count to zero
2. read the cookie if it exists replace the count with the value from the cookie
3. add 1 to the count
4. save the cookie
5. If the count is greater than 3 then redirect

Labrar
11-14-2012, 09:11 AM
Another question.
Why won't you use PHP instead and use sessions?
What if someone deactivated Javascript?

minder
11-14-2012, 10:09 PM
Labrar is pointing you in the right direction. This should be done server side and forget using javascript for this situation. It's not required at all.

Also, do you mean 3 times per session or 3 times over multiple sessions. If you mean 3 times per session then you don't even need cookies (which labrar alluded to), which can also be turned of by the user and so your counter won't work.

If you forget using javascript and do this server side, you can use both a session variable and cookies so that at least you will have a session counter that works in all browsers and if cookies are enabled in the browser, the counter will work over multiple sessions even if javascript is not available.

If you can do something both server and client side, it's always better to do it server side which means it will work all the time and so not have to worry about users whose browsers have javascript unavailable for some reason.

Finally, the code to read and write cookies using PHP is much less than the code required using jabascript.

AndrewGSW
11-14-2012, 10:39 PM
Just my opinion but I would stick with JavaScript :). If someone disables JavaScript then they will encounter many other issues more significant than having to close a splash screen (assuming they still can..). Besides, the page in question already uses a great deal of JavaScript.


If you can do something both server and client side, it's always better to do it server side
This is a very sweeping statement.. They are different tools and only overlap in certain specific areas (such as cookies).

I agree that coding cookies is easier in PHP, but not enough to make me chose to use PHP in preference to JS.

minder
11-14-2012, 10:45 PM
Just my opinion but I would stick with JavaScript :).

That's fair enough, but what about the case where cookies are disabled?

By doing this using a server side session you will have a counter that works at least for the session in all cases without needing cookies or javascript. If you limit yourself to javascript, there will be occassions where you won't have a working counter at all.

So I guess it boils down to how critical it is for the op to have a working counter and in what situations for their splash screen.

minder
11-14-2012, 11:15 PM
This is a very sweeping statement..

Yes I agree. I suppose I should clarify by saying that if a functionality is critical and must work in all cases and it can be coded both client and server side then it is always better to code it server side because it will work in all cases where coding it client side will most likely result in it not working in all cases.

Old Pedant
11-14-2012, 11:30 PM
Of course, if the user disables cookies, then the PHP developer must enable cookieless-sessions (they are enabled by default in recent versions of PHP) and, as the PHP manual warns, cookieless sessions are subject to attacks.



session.use_only_cookies
specifies whether the module will only use cookies to store the session id on the client side. Enabling this setting prevents attacks involved passing session ids in URLs. This setting was added in PHP 4.3.0. Defaults to 1 (enabled) since PHP 5.3.0.

minder
11-15-2012, 12:53 AM
Of course, if the user disables cookies, then the PHP developer must enable cookieless-sessions

Only if you must support cookieless browsers. Whether having the sessionID in the url is a real security risk or not depends on the type of website and the information displayed on the web page.

Old Pedant
11-15-2012, 05:11 AM
Ummm....you wrote


By doing this using a server side session you will have a counter that works at least for the session in all cases without needing cookies or javascript.

I was only pointing out that *IF* the user disabled cookies that statement is not true. And then noting the consequences if you are forced to use PHP cookie-less sessions.

Anyway, not disagreeing about whether cookieless sessions implies a problem in all cases. Just noting that it *could*. Clearly not applicable to the simple scenario that is the subject of this thread.

minder
11-15-2012, 08:43 AM
I was only pointing out that *IF* the user disabled cookies that statement is not true. And then noting the consequences if you are forced to use PHP cookie-less sessions.


Even in your own statement above you say you can have sessions without a session cookie, so what I said is totally true :)

You don't need cooikies or javascript if you want a counter just for the browser session.

Philip M
11-15-2012, 11:41 AM
The OP wanted the splash screen to be shown 3 times only (over multiple sessions). He asked his question in the Javascript forum, and Javascript can very easily do this using a cookie. It is silly to raise the question of Javascript or cookies being disabled. In that case the user just sees the splash screen each time. Note that many people clear out their cookies at frequent intervals, so the cookie that works initially may be deleted hours/days later by the user.

minder
11-15-2012, 12:02 PM
The OP wanted the splash screen to be shown 3 times only (over multiple sessions). He asked his question in the Javascript forum, and Javascript can very easily do this using a cookie. It is silly to raise the question of Javascript or cookies being disabled.

The op didn't specify if it was over multiple sessions or not, hence the questions from Labrar and I.

Obviously Labrar doesn't think it's silly to ask what the op intends to do if javascript or cookies are disabled either. If you do this server side it will work in at least the cases it would work in javascript but if you do it with javascript it will not work in all browsers where it will still work if coded in php, at least for a single session.

So it's a no brainer, if you want to maximise the possible browsers this will work in then do it server side otherwise javascript is fine if you can accept it working in fewer browsers.

reach100
11-27-2012, 08:29 PM
Thanks for this great discussion. I am the OP and I don't have a problem with cookies being turned off or cleared, that would just give me more exposure to my offer. Currently the splash screen never goes away. I am hoping that someone can give me specific code to use as I am not a programmer, or point me to somewhere I can create it. If someone will do this for a fee I'd be happy to pay. Thaks,
Rich

Philip M
11-27-2012, 08:57 PM
Here you are:-

<script type = "text/javascript">

var visits = getCookie("visitscounter");
if (!visits) {visits = 0}
visits = Number(visits) + 1;
alert (visits); // for testing
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); // cookie expires 365 days ahead
setCookie("visitscounter", visits, expdate);

if (visits <= 3) {
// code to show splash screen here
}

function setCookie(isName,isValue,dExpires) {
document.cookie = isName + "=" + isValue + ";expires=" + dExpires.toGMTString() ; // path not specified so cookie only active for this page
}

function getCookie(isName){
cookieStr = document.cookie;
startSlice = cookieStr.indexOf(isName+"=");
if (startSlice == -1) {return false}
endSlice = cookieStr.indexOf(";",startSlice+1)
if (endSlice == -1){endSlice = cookieStr.length}
isData = cookieStr.substring(startSlice,endSlice)
isValue = isData.substring(isData.indexOf("=")+1,isData.length);
return isValue;
}

</script>

reach100
11-27-2012, 11:16 PM
Thank you for your response. What do I put where is says "// code to show splash screen here." I really appreciate your help.

I did some research and ented this:


if (visits >= 3) {
window.location.href = 'http://www.sealfit.com/hp';
}

Its working, thanks!

Philip M
11-28-2012, 07:35 AM
Thank you for your response. What do I put where is says "// code to show splash screen here." I really appreciate your help.

I did some research and ented this:


if (visits >= 3) {
window.location.href = 'http://www.sealfit.com/hp';
}

Its working, thanks!

Presumably it should be if(visits >3) {

I understand that you are redrecting to another page (without splash screen) if visits value is more than 3.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum