1

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?

2
  • Can you explain little bit about "Since I have query parameters in source url too, I couldn't use that url as redirect_url. How can I do this?" Commented Jun 27, 2016 at 10:05
  • In source url I have this query param: referenceId=123. If I put all together it is coming like http://example.com/login?redirect_url=http://example.com/payment?referenceId=123. And if we access that we are losing referenceId and browser redirecting it to http://example.com/login?redirect_url=http://example.com/payment. But I need referenceId too Commented Jun 27, 2016 at 10:08

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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
}

Comments

0

For URL http://example.com/login?redirect_url=http://example.com/payment?referenceId=12‌​3

Use $redirect_url = $_GET['redirect_url']; // $redirect_url contains http://example.com/payment?referenceId=12‌​3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.