Is it possible to hide URL parameters with PHP? [duplicate]

0

I have a project in php with codeigniter that gets dominio.com/?id=212454&survey=complete and after I save this data in a variable, I wanted to remove it from the url, getting only dominio.com

My current controller looks like this:

    <?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    public function index()
    {
        $parameters = $this->input->get();
        if(isset($parameters['id'])){
            if(filter_var($parameters['id'], FILTER_VALIDATE_EMAIL) || (preg_match("/\(?\d{2}\)?\s?\d{5}\-?\d{4}/", $parameters['id']))){
                //o email ou telefone é valido
                $this->load->view('index',[
                    'survey'=>$parameters['survey'],
                ]); 
            }else{
                $this->load->view('semvariavel');
            };

        }else{
            $this->load->view('semvariavel');
        };

    }
}

I'm using the following solution on the front end:

    <script>    
    if(typeof window.history.pushState == 'function') {
        window.history.pushState({}, "Hide", '<?php echo $_SERVER['PHP_SELF'];?>');
    }
</script>
    
asked by anonymous 12.04.2018 / 18:58

1 answer

1

You can not make changes in the browser by PHP, because PHP is processed on the server, not on the browser.

What you can do is to run a javascript script in this view that does this, since javascript does run on the client side.

One way to do this is with the history.pushState command, but only in browsers that have support for this action. Example:

history.pushState({},"URL Rewrite Example","https://stackoverflow.com/example")

You can learn more about the pushState () method at: Mozilla Developer

    
12.04.2018 / 19:04