Solved

Cookies in javascript or PHP, which is better?

Posted on 2007-03-27
6
294 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
  • 3
  • 3
6 Comments
 
LVL 49

Expert Comment

by:Roonaan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:bt33
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for your explenations, it's much more clear to me now.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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 …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now