How to redirect to another page if it is accessed directly?

How to redirect a page to the homepage if it is accessed directly (Without a variable)?
Suppose we have a link “$_GET[variable]” if it is accessed like this then it is OKAY! but if someone tries to access it directly using this link “” Then it should redirect to the Homepage.
How to do it?

Check if the variable is set, and if not, redirect.

if(!isset($_GET['variable'])) { header("location: /" ); exit(); }

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.