?
Solved

Cookies in javascript or PHP, which is better?

Posted on 2007-03-27
6
Medium Priority
?
304 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

770 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