Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cookies in javascript or PHP, which is better?

Posted on 2007-03-27
6
Medium Priority
?
306 Views
Last Modified: 2008-02-01
I am doubting what the best way is to deal with cookies. My server is already slow sometimes when it's really busy so I don't wanna push it too far. I want to start working with cookies so that I can give specific users specific ads.

I am wondering if I should set and get the cookie through php or javascript. I'm guessing javascript would be easier on the server then php?

The main problem I have with javascript is that I have to sent all the ad codes to the client instead of only sending the one I need with php. I'm not sure if it's worth it.

Can anyone give me more insight about how much effort it takes from the server to deal with cookies from a lot of visitors, or just give an opinion about javascript/php while dealing with cookies. Any websites which have info about server server capacity / cookies would also be helpful.

Thanks.
0
Comment
Question by:bt33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 18798869
If you are calling the php anyhow to load an ad, it is little trouble to add a setcookie call as well in it's response. The cookies are sent with every request through your server for you to read, and there is no reason not to write some back in your response.

If you are thinking of building a single php script just to set a cookie, then it is indeed better to use javascript. For maximum usability however you should consider using a combination of both javascript and php as some users might

-r-
0
 

Author Comment

by:bt33
ID: 18798949
When the visitor requests a page, I read the cookie and from the info in it I decide which ad I wanna place. Hmm, but what is there to gain from javascript then? Javascript could then be useful for if you'd wanna set something into a cookie when the visitor wouldn't make a request to the server? That's not the case for me so javascript wouldn't make me gain functionality?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 18799039
Probably not. But that would depend on the things you wanna store. If you'd wanna store someone clicking an ad such that he/she doesn't see that ad for a while, it wouldn't make sense to store that info serverside and make a php request.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:bt33
ID: 18799077
Can you name an example where javascript could be more useful? I'm kinda thinking that everything that can be done with javascript can also be done with php but I know many people use javascript so there must be something to gain? I just don't understand what exactly.
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 1000 total points
ID: 18799093
In relations to cookies almost everything can be done from php which can be done from javascript.
There are examples of interfaces that require client side storage of information between request. Such as collapsed/uncollapsed state of menu's, positioning of draggable elements and/or form details.
0
 

Author Comment

by:bt33
ID: 18799301
Thank you for your explenations, it's much more clear to me now.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question