•
•
•
•
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
![]() |
•
•
Join Date: Aug 2006
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
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.
[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.
•
•
Join Date: Aug 2006
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation:
Rep Power: 5
Solved Threads: 20
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.
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.
•
•
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation:
Rep Power: 5
Solved Threads: 20
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.
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- retrieving image from mysql database using php (PHP)
- URGENT: UBBThreads MySQL database merge (MySQL)
- Backing up a MySQL database (MySQL)
- Update entire Mysql DataBase with PhP (PHP)
Other Threads in the PHP Forum
- Previous Thread: Help Guys!
- Next Thread: Couple of questions


Linear Mode