How to assign the following into a ?name=john&lname=doe into a variable?

superaff1984

Senior Member
Premium Member
Joined
Jun 16, 2010
Messages
992
Reaction score
131
Hi, I am trying to get assign the URL string into a variable because I am doing a location direct.

The url looks like this https://www.example.com/?name=john&lname=doe

BUT I want to assign everything after the / into a variable to pass it into the redirect, how can I do this?
 
I can help you. But I don't understand what you want to achieve. Can you explain with an example?
 
@superaff1984, here's the code you asked for. If it's not what you wanted, let me know.

const urlParams = new URLSearchParams(window.location.search);
var redirectUrl = window.location.href;
var redirectUrlWithParams = redirectUrl + "?" + urlParams;
window.location = redirectUrlWithParams;
 
Last edited:
Thanks, but I found an easier way of doing by using $querystring = '?' . $_SERVER['QUERY_STRING']; then adding the $querystring into the PHP redirect.
 
Very good where are you from?

Are you a developer for a living?
 
Back
Top