Wordpress encodes GET parameter - wordpress

I need to pass base64 encoded string as a GET parameter, yes, I know that's a bad idea, but it is necessary. The problem is that I need it like so:
http://example.com/?data=c29tZXRoaW5nQA==
But it changed the URL to:
http://example.com/?data=c29tZXRoaW5nQA%3D%3D
Is there a way to do it? Adding this parameter via the query_vars filter fixed the URL, but then always returns the blog page not frontpage.

you can urldecode() your parameter, which will turn it back into the normal one, when you get it. –
So
$returnValue = urldecode('c29tZXRoaW5nQA%3D%3D');
Will return
$returnValue = "c29tZXRoaW5nQA==";
In short :
$theImage = urldecode($_GET['data']);
Should give you your disired string

Related

Get the full QueryString from URL in ASP.NET

I have an URL with the following format:
http://www.mysite.com/login.aspx?ref=~/Module/MyPage.aspx?par=1&par2=hello&par3=7
I use the content of the QueryString it to Redirect the user back to the page he was before logging in. In order to keep also the status of the page I need the parameters in the QueryString. The number of parameters changes depending on the Page calling the Login and its status.
Let's say I want to store everything in the URL after ref in the redirectURL variable. I tried:
redirectURL = Request.QueryString("ref") // "~/Module/MyPage.aspx?par=1"
it gets everything after ref but ignores everything after the &(included). If I use:
redirectURL =Request.Url.Query // "ref=~/Module/MyPage.aspx?par=1&par2=hello&par3=7"
it gets everything, ref included. In order to achieve my goal I need just to remove the first 4 characters from the redirectURL. But I think this solution is a bit "forced" and I am sure there should be some ASP.NET function that accomplish this task.
The &s in your URL are creating additional querystring arguments.
You need to escape the value of the ref parameter before putting it in the querystring.
This will replace the &s with %26.
To do this, call Uri.EscapeDataString().
When you fetch the property from Request.QueryString, it will automatically decode it.
Consider Encoding "~/Module/MyPage.aspx?par=1&par2=hello&par3=7" before passing it to the url.
Eg.:
String MyURL = "http://www.mysite.com/login.aspx?ref=" +
Server.UrlEncode("~/Module/MyPage.aspx?par=1&par2=hello&par3=7");
And then, you can get the redirectURL using:
String redirectURL = Request.QueryString("ref");

Decode and RequestQueryString

My URL is
www.domainname.com/default.aspx?l=en&t=32600483-1618-4f09-9a86-c12de4dafc7b
I would love to read the QueryString value of t. So i can parse it as GUID.
Unfortunatelly that & thing, seems to mess things up.
How can i parse the value of the t Query string?
My URL is
I hope you realize that this is not a valid URL. This is a HTML encoded string. Do not confuse with an URL. URLs should be properly URL encoded, not HTML encoded. And since you start with something invalid your only chance is to use some ugly string parsing/regex to extract the necessary information. Since this looks like an HTML encoded string you could HTML decode it first:
var myUrl = "http://www.domainname.com/default.aspx?l=en&t=32600483-1618-4f09-9a86-c12de4dafc7b";
myUrl = HttpUtility.HtmlDecode(myUrl);
var values = HttpUtility.ParseQueryString(myUrl);
var t = values["t"];
But I repeat once again: don't do this: tackle the problem at its root. And the root of your problem is the origin of this URL. So if you have control over the generation of this URL then fix it so that you can have a valid URL that you could easily work with with the built-in methods. If you don't have control over the generation of the URL then notify the author of the code that he has a bug in it and ask him to fix it because he has provided you a non-properly encoded URL and you are obliged to use some ugly string parsing mechanisms to extract the information from it.

Nesting HTTP GET parameters (request within a request)

I want to call a JSP with GET parameters within the GET parameter of a parent JSP. The URL for this would be http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90
getName.jsp will return a string that goes in the name parameter of getMap.jsp.
I think the problem here is that &lon1=-90 at the end of the URL will be given to getMap.jsp instead of getName.jsp. Is there a way to distinguish which GET parameter goes to which URL?
One idea I had was to encode the second URL (e.g. = -> %3D and & -> %26) but that didn't work out well. My best idea so far is to allow only one parameter in the second URL, comma-delimited. So I'll have http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?params=30,-90 and leave it up to getName.jsp to parse its variables. This way I leave the & alone.
NOTE - I know I can approach this problem from a completely different angle and avoid nested URLs altogether, but I still wonder (for the sake of knowledge!) if this is possible or if anyone has done it...
This has been done a lot, especially with ad serving technologies and URL redirects
But an encoded URL should just work fine. You need to completely encode it tho. A generator can be found here
So this:
http://server/getMap.jsp?lat=30&lon=-90&name=http://server/getName.jsp?lat1=30&lon1=-90
becomes this: http://server/getMap.jsp?lat=30&lon=-90&name=http%3A%2F%2Fserver%2FgetName.jsp%3Flat1%3D30%26lon1%3D-90
I am sure that jsp has a function for this. Look for "urlencode". Your JSP will see the contents of the GET-Variable "name" as the unencoded string: "http://server/getName.jsp?lat1=30&lon1=-90"

MVC3 Stripping Query String from my Parameter

I have an MVC3 Action that takes a parameter (a URL) that may have a query string in it. My action signature looks like this:
GetUrl(string url)
I expect to be able to send it urls, and it works every time unless there is a query string in the url. For example, if I navigate to:
MyController/GetUrl/www.google.com
the url parameter comes accross as "www.google.com" -Perfect. However, if I send
MyController/GetUrl/www.google.com/?id=3
the url parameter comes accross as "www.google.com/" How do I get MVC3 to give me the whole URL in that parameter? -Including the query string?
It's simple enough to just URL.Encode the passed in URL on the page but you're opening your self to some possible security problems.
I would suggest you encrypt the url then encode it then pass that as your value, the protects you from having people just passing in anything into your app.
That's because system considers id=3 as its own query string. When you construct the link in the view, you need to use #Url.Encode to convert raw url string to encoded string to be accepted as parameter of the controller.

How do I identify the referrer page in ASP.NET?

In VS2003, I am trying to find out the particular page where the request is coming from. I want to identify the exact aspx page name.
Is there a way to only get the page name or some how strip the page name?
Currently I am using the following instruction...
string referencepage = HttpContext.Current.Request.UrlReferrer.ToString();
and I get the following result...
"http://localhost/MyPage123.aspx?myval1=3333&myval2=4444;
I want to get the result back with out any query string parameters and be able to identify the page MyPage123.aspx accurately...
How do I do that??
Instead of calling .ToString on the Uri, use the AbsolutePath property instead:
string referencepage = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
This should get you "/MyPage123.aspx" in your case.
Edit: Had LocalPath instead of AbsolutePath by mistake
Look at the Segments property of the URI class (which is what HttpContext.Current.Request.UrlReferrer returns).
Something like HttpContext.Current.Request.UrlReferrer.Segments[1] (changing the 1 indexer to get the correct segment you require).

Resources