Passing value from one view to another view - PHP

Asked

Viewed 383 times

1

Guys, I need to pass a value from one View to another View, in case an ID. For example:

In the Main View I have a list of vacancies, when I click on one of the vacancies will load the second View where it will be possible to edit this vacancy. My doubt is how to pass the ID value in a correct way, without the user being able to modify the value in the link inspecting by the browser.

  • The ideal would be to store this in $_SESSION. Are you using any framework?

  • No, no framework, only MVC @Andréribeiro

  • get_defined_vars() within the view structure would return all variables declared there. Perhaps, you could do something with this

1 answer

1


In this case there is no way, what you can do is create a lock before generating the link.

For example, a hash that allows access to that id or directly to the wave, and instead of passing the id to the generated url you pass the hash.

The page you receive finds the id of the wave through the hash.

Example url:

?vagahash=202cb962ac59075b964b07152d234b70

Sample code:

// Recebe o hash enviado, neste caso por GET
$hash = $_GET['vaga'];

// Instancia o Dao para funcoes de busca no banco de dados relacionadas a vaga
$vagaDao = new VagaDao();

// Seleciona a vaga atravez do hash
$vaga = $vagaDao->selectByHash($hash);

This way with the hash generated by you, it is difficult for the user to modify successfully.

I hope you helped him.

Browser other questions tagged

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