'PHP - How to protect the URL after logging in from copy paste

I have created a login script and the user, after entering his username and password, is redirected to the main page of the site named main.php, if of course entering valid data.

I have seen that by copying and paste the URL of this page to another explorer, the page opens succesfully without the need to do the logging process. How can I stop this? Hcan I protect my main.php page so that only users after a registration process can only see it?



Solution 1:[1]

Use session cookies instead of putting the session ID in the URL.

Solution 2:[2]

Use session variables.

Here are some resources:

http://www.w3schools.com/php/php_sessions.asp
http://php.net/manual/en/book.session.php

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Niet the Dark Absol
Solution 2