PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a site with a main feature page. People are linking directly to this page and I am not getting visitors on my home page.
I wanted to create a session that lasted 24 hours and if expired and the link click it would redirect to the homepage where the session could be started for a further 24 hours.
I don't want any messages to appear and I don't want to use a login.
Is this possible?
I am pretty new to PHP and kind of struggling with this one.
Let me make sure I understand: You want to make it so if user hasn't been to your home page in 24 hours, the second page will redirect them to it? Well if that's the case, you can do it without a login, but cookies would have to be enabled, so there is no way to strictly ENFORCE it without a login
I want to maximise the number of visits to the homepage and this is the one way I can think of doing it.
Could there be a hidden login where php will automatically fill in details?
No... that would require cookies too. I wouldn't go that route anyway. Redirecting your users to your home page when they are used to being able to simply go to a page they are already familiar with is probably not the best idea. If a site I went to often did that I would be irritated. But, if you really want to do it.... just use cookies. If you aren't familiar with the use of Sessions and Cookies, read the information at the links provided. Once you are done with that, if you still have questions, I'd be happy to answer them!
A messy way is to use (PHP's own) session ID's and set the session exipry time to 24hours.
A 'better' way, would be to use your own form of session ID's in a DB table, along with a timestamp - then a simple check and redirect if necessary, like so: