Show/hide website content based upon URL parameters in php

Show/hide website content based upon URL parameters in php

Steps to use the code

  • You must have a domain
  • Copy and paste the below code into the index.php file

What is the purpose of this code?

This code is used to hide/show the website content based upon the passed parameter in the given URL. For example: If you want to show a blank page on your website when visitors visit your domain.com but want to show the content only if a specific parameter is passed inside a website domain. (domain.com/keyfound)

In other words, Blank page on domain.com and show website content on domain.com/keyfound.

Method 1

$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ==='on' ? "https":"http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
 $data = parse_url($url);
//print_r($data);

if(!empty($data['query'])){
    if($data['query'] == '123')
    echo "show website content!";
}else{
    exit();
}

Method 2

if(isset($_GET['key']) && !empty( $_GET['key'])){
    
    if($_GET['key'] == '123')
    echo "website content";
}else{
    exit();
}

  • user

    codelone

    For specific code or video requests, direct message on Instagram https://www.instagram.com/code_lone/?hl=en

    1 year ago