Reputation: 2461
I have this scenario. I am implementing payment for my application and url is like http://example.com/payment?referenceId=123
. And before that I need to check for authentication and need to use redirect_url
concept if the user is not logged in. I have this url for redirect_url: http://example.com/login?redirect_url=URL
Since I have query parameters in source url too, I couldn't use that url as redirect_url. How can I do this?
Upvotes: 1
Views: 62
Reputation: 2177
For URL http://example.com/login?redirect_url=http://example.com/payment?referenceId=123
Use $redirect_url = $_GET['redirect_url'];
// $redirect_url contains http://example.com/payment?referenceId=123
Then use php's inbuild function parse_url to filter out 'referenceId
' from $redirect_url
<?php
$url = '//www.example.com/path?googleguy=googley';
var_dump(parse_url($url));
?>
array(3) {
["host"]=>
string(15) "www.example.com"
["path"]=>
string(5) "/path"
["query"]=>
string(17) "googleguy=googley"
}
Check for more info http://php.net/manual/en/function.parse-url.php
This part googleguy=googley
will actually hold your required data
Upvotes: 0
Reputation: 459
To check authentication store referenceId as a session variable. Start session in your authentication page and check the url-referenceId is equal to the stored userId of that particular session.
session_start();
$_SESSION['referenceId'] = 123;
if((url_ReferenceId)=$_SESSION['referenceId'])
{
//Check for authentication
}
Upvotes: 0
Reputation: 21
One possible way to do this task is to store http://example.com/payment?referenceId=123 in session when redirecting to login page and when login is completed then check if session has value for redirect then redirect to that url from session.
Upvotes: 1