1
I have a login form running with Jquery + PHP, I’m implying the option to redirect based on the url I want to receive via GET, as below:
https://pt-br.example.com/?redirect=https://blog.example.com/
Problem is that I do not receive via GET the redirect variable
Login method
private function Login() {
$Session -> session_token = (string) $Functions -> ClearVariable($_POST['tokenForm']);
$Session -> CheckSessionTokenForm();
$this->Email = (string) mb_strtolower($Functions -> ClearVariable($_POST['loginEmail']));
$this->Password = (string) $Functions -> ClearVariable($_POST['loginPsw']);
if(isset($_GET['redirect']))
{
$this->Location = $Functions -> ClearVariable($_GET['redirect']);
}
else
{
$this->Location = 'dashboard/';
}
... }
Jquery Post
$('button[type="submit"]').click(function(event){
event.preventDefault();
var url = $(this).closest('form').attr('data-url');
var formId = $(this).closest('form').attr('id');
var iBtn = $(this).children('i').attr('id');
$.ajax({
url: url,
data: $('#'+formId).serialize(),
dataType:"json",
type:"post",
success: function(data){
switch(data.status) {
case 'location':
window.location.href = data.flag;
break;
}
}
});
});
PHP usage with Jquery post, may be because of Jquery post?
What appears when doing the
echo
? You are handling all the characters in the value ofredirect
? 'Cause it should be something likeredirect=https%3A%2F%2Fblog.example.com%2F
– Woss
Nothing appears, the $this->Location attribute is empty
– RRV
You can put the JS code and the full PHP in the question then?
– Woss
$this->Location
is always equal todashboard/
then?– Woss
No, I have other pages that the user can click on the login link and be directed to the login page with the origin url, when the user access the direct login page will be directed to Dashboard/
– RRV
But if you do not receive the data with the
$_GET
, theisset($_GET['redirect'])
would always returnFalse
. Then you must be receiving the value correctly, but treating it wrong. What is$Functions -> ClearVariable
?– Woss
I removed the isset condition to check if I was getting any value, and yet I received nothing. Clearvariable is to clear user input, avoid attack.
– RRV
What happens if you put
echo json_encode($_GET)
and in JS, instead of doing thewindow.location
, doconsole.log(data)
. Remember to finish running PHP after thisecho
, withreturn
orexit()
.– Woss
I will test the way you put it.. I just created it like this: $Location = $_SERVER['REQUEST_URI']; if($Location !== '/') { $Location = str_replace("/?redirect=","",$Location); } Else { $Location = 'Dashboard/'; } and created an Hidden input in the form with Location.. and I’ll test.. Working or not I’ll be the way you put it, it’s for knowledge. :)
– RRV