I’m building a simple website with few pages such as index.php, about.php etc. I’ve included navigation file and I want it to automatically choose current page and use different styling. It can be done with one variable. The easiest way is to use GET method but I want to have shorter URL. So is there any other way? Because as far as I know POST refers only to forms. Maybe I should use cookies?
I’m building a simple website with few pages such as index.php, about.php etc. I’ve
Share
Use a session. It will keep a set of values stored in the
$_SESSIONsuperglobal as long as the client’s session cookie is still set.Example:
page1.php
page2.php
If you visit page2.php first, you’ll get no output. Once you visit page1.php, it will set the ‘test’ session variable. When you view page2.php again, it will show the result. This session is server-side, and is accessed by the session ID stored in a cookie by the browser. Session cookies are usually deleted when the browsing session ends (i.e. the user closes the browser) or when the session cookie timeout expires. Most sites use this as a mechanism to handle logins, by setting session variables relating to the logged in user (e.g. user id) when a login completes successfully.
See the PHP sessions reference: http://www.php.net/manual/en/book.session.php