How to redirect in the address bar with php ex: /open/? page=?

Asked

Viewed 66 times

-2

example:

community/? subtopic=characters

Dashboard/? page=ng

How do I set my php page to look like this? What is the name of this function ? where there’s a tutorial for this too?

  • url friendlies? would that be?

1 answer

1


I don’t quite understand which part of it is your question, so I’m going to break it down into two answers.

First of all, what happens to this /? is that usually the address of the page itself (index.php, in most cases) is hidden, but the returned page is still the index.php (or another, set on the server). Then the parameters followed by ? are still passed to the page normally.

In other words: community/?subtopic=characters and community/index.php?subtopic=characters are the same thing.

Now, if you are referring to conditioning the content of a page based on the parameters, take a read on the $_GET.

You can use it to do something like:

<?php
    $Pagina = $_GET['pagina'];

    if($Pagina == "perfil") {
        include("Perfil.inc.php");
    } else if($Pagina == "login") {
        include("Login.inc.php");
    }
?>

When the user accesses /index.php?pagina=login (or /?pagina=login), you can display a login screen and etc.

Obs: Never make a include directly from a parameter $_GET, as in the example below:

<?php
    $Pagina = $_GET['pagina'];

    include($Pagina);
?>

or

<?php
    include($_GET['pagina']);
?>

This creates a huge security breach on your site. Always validate the parameters or do it by association, as in the example I passed upstairs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.