User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,451 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,730 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1553 | Replies: 5
Reply
Join Date: Aug 2006
Posts: 6
Reputation: kibanga is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kibanga kibanga is offline Offline
Newbie Poster

Setting up a cookie and saving the result in mySQL database

  #1  
Aug 24th, 2006
I am learning to set up a cookie and assign a user_Id to whoever visits my website. I want to keep a record of all user IDs in mySQL database. I tried something like this:
[PHP]if(!isset($HTTP_COOKIE_VARS['user_id']))
{ $cart_id = md5(uniqid(rand()));
$COOKIE=setcookie("cart_id", $user_id, time() + 14400);
if (!$COOKIE)
{
echo "To complete your order your browser must be set to accept cookies";
}
}
else
{
$user_id = $HTTP_COOKIE_VARS['user_id'];
}[/PHP]

I believe the results I got did not seem to be convincing because verytime I refreshed my browser, the value of the user_id changed. Then I tried this

[PHP]session_start();
$user_id=session_id();
[/PHP]
which I believe also did not work well.


For both methods, whenver I tried to save the $user_id variable in mySQL database, the string was always truncated even after increasing the field width to 250.

Any ideas on these two linked problems are highly appreciated.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Posts: 21
Reputation: msvinaykumar is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
msvinaykumar msvinaykumar is offline Offline
Newbie Poster

Please don't use cookie

  #2  
Aug 24th, 2006
Hi,
Please dont use cookie, Lot of problem will occur
Cookie is something which we can't handle in client machine.
Some client machine will allow us to create cookie and some don't

If you really want I have some other solution to keep track of user


Vinay
Reply With Quote  
Join Date: Aug 2006
Posts: 6
Reputation: kibanga is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kibanga kibanga is offline Offline
Newbie Poster

Re: Please don't use cookie

  #3  
Aug 24th, 2006
Originally Posted by msvinaykumar View Post
Hi,
Please dont use cookie, Lot of problem will occur
Cookie is something which we can't handle in client machine.
Some client machine will allow us to create cookie and some don't

If you really want I have some other solution to keep track of user


Vinay


Thank you for the advise on cookies. Could you please show me how to keep track of users per session. I mean even if they refresh their browsers, their identification should remain the same until they turn their browsers off.
Reply With Quote  
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation: Puckdropper is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 20
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: Setting up a cookie and saving the result in mySQL database

  #4  
Aug 25th, 2006
Use their IP address. It's probably the simplist (but not 100%) way to keep track of users for anonymous data gathering.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote  
Join Date: Aug 2006
Posts: 6
Reputation: kibanga is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kibanga kibanga is offline Offline
Newbie Poster

Re: Setting up a cookie and saving the result in mySQL database

  #5  
Aug 25th, 2006
But if there are two or three users sharing a router then you will track both as one user instead of two different users. I am I correct?
Reply With Quote  
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation: Puckdropper is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 20
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: Setting up a cookie and saving the result in mySQL database

  #6  
Aug 27th, 2006
The real answer here is "It depends." While it's certainly true that those behind a router (or firewall even) will have the same external IP, it may not make much difference to the purpose of the script.

About cookies: Go ahead and use them. If a user turns off cookies he will not be able to access your login-required sections of the site. It's not worth the trouble to code around them just for the people that don't understand why cookies exist in the first place.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC