Solved

Cookies in javascript or PHP, which is better?

Posted on 2007-03-27
6
299 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
Industry Leaders: 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Glitching Slide Show 19 27
Validating number not work with decimal 4 24
What is the correct way to check for empty value in input field 2 16
Find RGB colors from a screen. 2 17
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

749 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