Do PHP variables ever get deleted when the user navigates to a new page. For example if I use PHP redirect command will that reset all the $variables or is there a way I can get them? And can I delete them?
Use Sessions if you want a certain variable to be passed on one page to another. use the unset() function to delete variable and sessions.
What Ryantetek means is: Variables will never be 'deleted' from the actual code unless you physically delete them yourself; the unset(); function will 'temporarily delete' a variable, assuming that it exists As far as passing variables from one page to the other, you use sessions: sesssion_start(); // At the very start of the files that you are using sessions on PHP: then you just: Page one <?php session_start(); $_SESSION['username'] = 'Marshton'; ?> PHP: Page two: <?php session_start(); echo $_SESSION['username']; //If you went to page one before visiting this page, the output is 'Marshton' ?> PHP: Hope this helps!
Yes, use sessions, or you can even use cookies to keep the variables after the user exit the page and return few days later
Yes also there is one function in php that delete all session variables that is session_destroy() Thanks,
Cookies are better at storing data for longer periods of time; however, I would suggest NOT using Cookies because they can easily be manipulated. If you need to keep data for more than 5 days on a user, personally I'd store the information in a database. Just a thought.