Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How do I run a script (ie, $viewcount += 1;) when a session starts in PHP? I'm trying to make a view counter script for my website which currently works, assuming I include('view_counter.php') in every page to add something to my text file of views. Unfortunately, people can reload the page and so add up the view count really quickly. What I'd like to do is add to the view count every time somebody opens a new session on the site. It should be obvious, but how do I do it?
Just check if the Session object exists or not yet using an IF statement, and if it doesn't, it means it's a new session in which you can run your counter code.
More info on working with sessions: Check whether a session is new in PHP
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have an admin page where some users can have access to but I want that whenever they leave the site or close the tab for about an hour or a day the session should be destroyed so as not to allow someone else.
The thing you are searching for is $_COOKIE. There you can define how long the Variable is saved etc. The only thing you will have to consider is that the values are stored locally and not on the server. If you want to achieve that, you can create a Cookie-Key system similar to the one PHP uses to save the Session data on the Server. In that Case the User would get a key, saved as a cookie and the data is stored on the server under that key.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Someone asked me to cache the XML call im pulling in to prevent server trouble. But now my question is, what exactly is caching, and how do i do it?
Hope to find some answers here.
Is it a way to save the XML output to a file, and then use that file? But how do i check if there are any updates than, or when somebody closes the browser? Or do i store the XML in a SESSION or COOKIE?
Caching is the action to remember your calls during a limited time in order to prevent unnecessary calls.
For exemple, it can be like this :
You check if there is something already cached.
There is nothing, so you make your call.
You save the answer of your call for a limited time.
Next time you will check the cache, you won't call, but just user the saved answer.
You can be inspired by this script : http://www.finalwebsites.com/snippets.php?id=49
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a scenario here in which I am confused to solve. So here is the matter,
I have a PHP page with the project selector that gives the value into monitorIndex.php
And in the monitorIndex.php im using that given value with this
if(isset( $_POST['cd-dropdown'])) $_SESSION['cd-dropdown'] = $_POST['cd-dropdown'];
in which I use $_POST['cd-dropdown'] as the value used everywhere
now my question is, when user click on the navigation menu to go to a page called monitorTable.php, how do I still use the $_POST['cd-dropdown'] ? and how to make variable alive when user navigate out from that page and go back to monitorIndex.php and keeping the $_POST['cd-dropdown'] alive
thank you so much
You can use the
$_SESSION['cd-dropdown']
since it was assigned.
it will only destroy if session_destroy is invoke.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i want to know how much time a visitor stays on my website..??? can it be done with any online services ??..Any help would be appreciated..
Use Google analytics http://www.google.com.au/analytics/
A session can only change every time you call set or reset it.
But if you wanted to, you could use jQuery ajax, to run a script every X seconds or mins. Then in the file that you are ajax'ing in. Change your session data.
You will find analytics make a new request every time the user does something. Like moves the mouse, clicks on something, etc. So you would have to set up some js to do that as well.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How does it possible to get variable modificated values, after script ended? im going to make a small and very simple caching system, for start to cache just needs to put "cache" commented where need to start cache and same when ends, only problem is to emulate all script and, as i said, get each changed instance of var.
Usually there is more simpler, just integrate the caching in your script, the process would be
verify there is some cache and it's not expired
if there is some not expired cache use it, end
render the page and capture it using ob_* functions
build the cache
This way you don't have to emulate anything, just to wait that some people visit the page, plus you don't built cache for page that are never visited.