I'm making a page for submitting some info about user and after that data is inserted in database.
How can I know if current user has changed?
I'm using CodeIgniter and I can get users id but it's the always active one. How do I know if session has changed after page load?
Right now other user could log in another tab and submit on first tab would post session id from latest user.
Use tokens therefore sessions will be stored in the users browser not in tabs. Check the PHP documentation or YouTube videos they have good tutorials on how to do this effectively.
Related
I'm trying to build an orderform which others can use within an Iframe on their website. Later I want to add this form to facebook.
My current form uses a session to bind the ordered products to the user, but if I disable third party cookies in Internet Explorer I can't order anything. The session ID is changing.
During last steps I ask the user to login and bind an email address to the current session.
I prefer to keep using sessions, so when someone leaves my page, the ordered items are still in their chart. What is best approach to still use sessions inside my iframe?
Thanks for everyones help...
A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.
Sessions: Introduction
So this means that if cookies are disabled, you need to propagate a session id into the URL. For example:
Checkout
Now the session id will be passed along even if the user has cookies disabled. It is up to you save the users cart into a database or something for when they completely leave your website. Afaik, sessions are always completely destroyed when a user leaves.
More info on passing the session id can be found here: Passing the Session ID
I am working on add to favorites add-on (where posts will be added to favorites by signed in users), but then I saw that craigslist lets anyone add favorites without them being signed in. How do they do that? Is there a unique $_SESSION id for a browser? Sorry if it's a silly question.
As an example: http://orlando.craigslist.org/search/jjj (Click on any star to add to favorites. May not be available in IE 11).
They are just using a session, you should be able to check this by looking what cookies they are storing on your computer.
Everything in $_SESSION persist only for the current session. If the users closes the browser and reopen it a new session is generated. So $_SESSION is not the right place for your answer.
There is $_ENV where you can get the clients ip address and general browser data from. In most cases this is enough to identify a single user. If you keep track of these data you can prevent users from giving multiple votes.
I have a url shortener that I created to track incoming links. Currently the php sets a cookie and inserts visitor information into the database. It attaches an id to the redirect url and redirects the user to the website.
The website has javascript on the page that takes the id and tries to set a cookie on the front end. If cookies are disabled, the javascript attempts other things to store that id. The reason I am setting the id is due to the javascript sending random pieces of information to the backend.
Is there a way for php to have a fallback if the person doesn't have cookies enabled? I don't want to create a new database entry for someone who visits the same link multiple times who doesn't have cookies enabled. Don't want to be tracking the same person as 2 or more people.
Edit
If I can't prompt the user that their cookies are disabled, are there any alternatives?
2nd Edit
One of the comments brought this up, so I thought I'd post the link here: User recognition without cookies or local storage
i have data from database and i need to count the views for every click,
i need to count only unique click for the current hour.
saving it in database is not in my options. and for the user to know that he/she already click that data
should i use cookie for every data that users clicked or session?
thanks.
I would store it in a session, there is no need to send it back and forth with every page request, that would only slow things down, especially if the site is big and the internet connection of your visitor slow.
However, note that you can only display this information to your visitor if you use sessions or cookies, there is nothing that you can actually do with it unless you store in in a database or a text file.
What I would like to do is essentially check whether or not a user has clicked a certain link on a page. The idea behind the functionality is that a user can click "Thanks!" on a post created on the website, but they can only submit one "Thanks!" per post.
I have no problem creating a simple click counter for the "Thanks!" button, and save the count to a database using PDO, but I am not sure how I can assign a click to the user who's session is active.Also, posts are constantly being added to the site, so I would need a system which would scale to more posts automatically.
Any guidance is appreciated, thanks!
Note: I know I have not put any example code, but I believe this is simple enough for a good programmer to grasp quickly.
EDIT
On further thought, the IP can not be used to distinguish users, as this website will be used by many people on the same IP.
Are the users logged in or anonymous? If they are logged in just save their user id in a session variable and upload it with their vote to a table in your database.
I do something similar using an Ajax request to a .php page that inserts a row with the session user ID and the vote.
If they are anonymous you can save their ip but that leads to problems with users who share the same ip address. Another (bad) option is to use cookies but users can obviously just clear their cookies and vote again.