2
I wonder if it is better, for example, to have a form in which the action is set to another page, or if it is recommended to send the data to the page itself with the action="<?php echo $_SERVER['PHP_SELF']?>"
.
If you have not understood, it would be more or less like this, I must use which of these two methods:
Send to same page:
<form name="login_form" action="<?php echo $_SERVER['PHP_SELF']?>" method="post" id="login_form">
And then at the top I do a check:
if(isset($_POST['logar'])):
//Código
endif;
Or should I:
Send to another page:
<form name="login_form" action="checarLogin.php" method="post" id="login_form">
And do the validation and sanitization on that specific page.
With better, I ask about safety, speed, and feasibility as well.
I believe that in terms of performance, it would be the same, security as well. But in matters of code organization it would be much better for you to separate, to make your code more readable.
– Jhonathan
Never use
action="<?php echo $_SERVER['PHP_SELF']?>"
, this is creates a vulnerability by XSS, if it is on the same page specify it for example "login.php" and not$_SERVER['PHP_SELF']
or if you still want to use thePHP_SELF
utilizehtmlspecialchars($_SERVER["PHP_SELF"], ENT_QUOTES, "utf-8");
!– Inkeliz
Thanks for the personal tips
– UzumakiArtanis