Solved

Cookies in javascript or PHP, which is better?

Posted on 2007-03-27
6
300 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 250 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
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…

739 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