/    Sign up×
Community /Pin to ProfileBookmark

looking for help creating cookie popups

I rarely use popups on my site, and suggestions for alternatives would be welcomed, but they seem the best option in this case

what I want to do is make a pop up appear when the user is on the checkout page of my commerce site. the pop up would appear dependant on the pages they have been browsing.

so, for example, they have visited a page which has Nokia 3310 housings on it. This page adds a cookie to their computer. Then when they went to the checkout page, a popup would appear telling them that there was a special offer on housings – buy 2 get 1 free, for example.

this popup would only appear if they’d been on a page which had housings on it (only pages which added cookies to their pc), so would be relevant to the products they were interested in

I’m sure it’s possible to do this from looking at various sites and adaptable scripts but I don’t know where to start with something so specific. if anybody knows any good scripts or resources that I could read up on, that would be appreciated

Thanks

Robert

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@VladdyMay 16.2004 — Pop-up is never the best option. Even though there are special application when pop-up is the only option, yours is not the case.

Use server side scripting to determine if the cookie is set and add the desired message directly to your "Checkout" page.

- no pop-ups

- no dependance on javascript.
Copy linkTweet thisAlerts:
@robii1authorMay 16.2004 — er, ok...so how do i start with that then?!

so first off I need to add cookies to pages. then I want the message to appear on my checkout page using scripting dependant on the cookie being present

how do i go about this?
Copy linkTweet thisAlerts:
@VladdyMay 16.2004 — I would do everything server side.

Implementation will depend on the language you use for your shopping cart
Copy linkTweet thisAlerts:
@robii1authorMay 16.2004 — ok, thanks. the cart is php
Copy linkTweet thisAlerts:
@VladdyMay 16.2004 — Maybe mods can move the post to the PHP forum.

I'm not too good with PHP but it would be something along the lines of:

Setting cookie:
[code=php]setcookie ("CookieName", $cookieValue,time()+durationInSeconds);

[/code]

Make sure it is called before any output is sent to the client (use buffering if needed)

Reading cookie by your "Checkout" page
[code=php]if(array_key_exists("CookieName",$_COOKIE))
{ echo '<p>Your Message here</p>';
} [/code]
Copy linkTweet thisAlerts:
@robii1authorMay 16.2004 — thanks, i'll try it out and see how it goes
Copy linkTweet thisAlerts:
@Khalid_AliMay 16.2004 — [i]Originally posted by Vladdy [/i]

[B]....

Use server side scripting to determine if the cookie is set...[/B]
[/QUOTE]


Just out of curiosity( my lack of PHP programming may be the reason for this question) if the server side programming is available and its PHP then I am 100% sure there is MySQL available as well,now with these tools available why would one want to set a cookie or still use cookies?

wouldn't using DB be a better tool to achieve persistence?
Copy linkTweet thisAlerts:
@MstrBobMay 16.2004 — Because if one was to use a database, they'd have to add a new row of data for each visitor, set a method for identifying each row and such. Now although it may be easier if you already have a username system running, you can save space and bandwith by storing temporary, non-important data on user's computer and thus will make sure it is user-specific.
Copy linkTweet thisAlerts:
@Khalid_AliMay 16.2004 — make sense..:-)

however, would setting cookies using PHP still work if I have cookies disabled in my browser?
Copy linkTweet thisAlerts:
@ConorMay 16.2004 — ^^nope
Copy linkTweet thisAlerts:
@Khalid_AliMay 16.2004 — [i]Originally posted by RefreshF5 [/i]

[B]^^nope [/B][/QUOTE]


Thats too bad then..:-(

And if I am not mistaken,one can not even use PHP session if the cookies are diabled.

And if my understanding is correct,then I'd not use any browser dependent solution for a good solution for persitence dependant data.
Copy linkTweet thisAlerts:
@robii1authorMay 16.2004 — khalid, if you have an alternative, please let me know

at the moment i have added the following script to the shopping cart page (which is not in the root folder if it makes any difference)

<?php

if (isset($_COOKIE["fasciaoffer"]))

echo "<b>Special offers available</b> - buy any 3 covers & get your 4th choice free! " . $_
COOKIE["fasciaoffer"] . "!<br />";

else

echo "<b>Special offers available</b> - none available on current order<br />";

?>

and i have added the following code to set the cookie to the following page just to test it out:

<?php

setcookie("fasciaoffer", $name, time()+36000);

?>

http://www.formymobile.co.uk/test2100fascias.shtml

BUT even though the cookie is on my pc, the message which is supposed to come up does not come up. The script seems correct as the other message does come up so it appears that the cookie can't be found

Could the fact that the cart uses includes which are not in the local folder be causing the problem? If so, how can it be addressed?
Copy linkTweet thisAlerts:
@Khalid_AliMay 16.2004 — I am afraid the solution I may have is probably serious over kill for a shopping cart project,in your case you are probably better of just using cookies with php or JavaScript wouldn't make much diff,however it will run your app.
×

Success!

Help @robii1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...