Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

42
Vistas
Change Content of Page Depending on if User Access It via URL Bar vs. a Button on Website

I'm currently developing a website on WordPress

Is there a way, with either the use of JS or PHP, to make it so that when the user clicks an anchor tag within the website, they are taken to another page, but if they decide to go to that same page by typing the URL in the search bar, they are denied and the content displays a 404 message?

Example:

<body>
   <a href="example.com/page/">Go to Page</a>
</body>
<body>

// From URL Bar
   <div class="404">Nothing was found at this location.</div>

// From Anchor Tag
   <div class="content">Page Content</div>

</body>
4 months ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can check if $_SERVER['HTTP_REFERER'] is set in case of a referrer from different page or not (direct access). You can also extend the check of this value to specific page(s), but you can start with:

<?php
if (!isset($_SERVER['HTTP_REFERER'])) {
    echo "error";
    exit();
}
4 months ago · Santiago Trujillo Denunciar

0

This may solve your problem:

Your can also encrypt 'show' parameter then decrypt it's value to achieve your goal.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>


    <?php
    if(isset($_GET['show'])){
    ?>

    // From Anchor Tag
   <div class="content">Page Content</div>

    <?php
        }else{
    ?>
         // From URL Bar
        <div class="404">Nothing was found at this location.</div>
    <?php
        }
    ?>
    

    

    <a href="/index.php?show">Go to Page</a>
</body>
</html>
4 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.