Search code examples
phpconnectionmember-access

How can accept connection from specific page?


I have a web page and I need to accept some of visitors if it is just from a spesific page.

For Example: If visitor goes example.com/member to example.com/specific it will ok. But if user goes any other place or just from address bar of browser, It will say "connection failed"

How can I do this with php? Thanks.


Solution

  • This isn't fool proof though, so don't use it for any authentication or security purpose

    <?php
    if(strtolower($_SERVER['HTTP_REFERER'])=="http://yourallowedurl.com/etc.html")
    {
        echo "OK";
    }
    else
    {
        echo "connection failed";
    }
    ?>
    

    Review This

    And This

    Note: You might want to create a session for the people who are logged in and allow only those with proper session values set to visit that protected page.