zend, getting a param that a value of http:// - zend-framework

im trying to get a param from my url.. via $this->_request->getParam('url')
so, /url/http://www.yahoo.com
but the value of param url is h because theres forward slashes in the value..
how can i get the full url... as now, its thinking that the http:// is another param..
public function getUrlToGo(){
$url=$this->_request->getParam('url');
if ($url='http://www.yahoo.com'){
return $this->_forward("findyahoo", "urlclass");
}
}

Usually when urls are passed in the address bar the slashes (and most other characters) are converted into url-safe characters.
<?php
$url = urlencode('http://www.yahoo.com');
echo $url; //http%3A%2F%2Fwww.yahoo.com
You can then use urldecode($url) to get the original url back.

Related

Test Rest API with file_get_contents

I am having issues testing a rest API. I want to trigger it from PHP by doing a file_get_contents.
This is my code so far
<?php
$url = 'http://domain:0000/rest/createUser?u=username&p=password&username=testuser&password=testpassword&email=user#domain.co.uk&';
$encodedUrl = urlencode($url);
$apicall = file_get_contents($url);
?>
This URL works from a browser, but as soon as I use file_get_contents it doesn't work.
Could the end server be blocking the use of file_get_contents? If so how? and how can I begin to test and troubleshoot this?
The issue is that you're using urlencode.
The urlencode function is used specifically for encoding strings inside a portion of a url. For example, you can use it to add data after the ?, and make sure that things like & turns into %26 and spaces turn into %20.
But it's not used to encode the entire url, it just makes the url invalid.
Try to remove the last "&" in your URL and then use the $encodedUrl instead of $url in the file get contents.
So try to turn this :
$apicall = file_get_contents($url);
INTO
$apicall = file_get_contents($encodedUrl);

nginx redirect old site urls and modify 1 language suffix only

I want to redirect old site urls to new site. But new site has different page names and language chars have changed too.
for example:
en/about/info will redirect to en/com/information
but
ge/about/info will go to ka/com/information
map $request_uri $redirect_uri {
<lang>/about/info/ $lang/com/information/
}
any ideas how I would go about this? There are a lot of urls, so I don't want to write these urls hardcoded for each language.
The map directive can capture parts of a regular expression, but cannot use that capture in the mapped result.
So it is possible to create a named capture called lang (for example) and use it after the mapped variable is evaluated. For example:
map $request_uri $redirect_uri {
~*(?<lang>/\w\w/)about/info/ com/information/;
}
And in the server or location block:
if ($redirect_uri) {
return 301 $lang$redirect_uri;
}
Note that $lang is only created after the value of $redirect_uri is evaluated in the if statement.
See this document for details.

Add Page Tab redirect to invalid location

When I've user Add Page Tab Dialog, I've passed redirect_uri like this
http://MYSITE/?r=c/action&token=123456789
when the dialog come back, it strips the token variable, so the url looks like
http://MYSITE/?r=c%2Faction&&tabs_added%5B176281002470701%5D=1#_=_
the token variable lost,
any body have any idea why this happen?
Might be a bug or the forward-slash. Try adding an extra param at the end that you don't care about or removing the forward-slash
http://MYSITE/?r=c/action&token=123456789&t=1
http://MYSITE/?r=caction&token=123456789
One option is to put all your needed variables in a single base64 string and pass that guy over as your single querystring parameter.
Pseudo-code would be:
data = toBase64String("action&token=123456789")
redirect_uri = "http://MYSITE/?data=" + data;
Then you decode it wherever you redirect to.

How to get parameter come after '#' in Perl CGI?

How can we fetch the value of folders from below mentioned url:
http://my.indiamart.com/cgi/​my-enquiries.mp#folders=1
I've tried CGI object, %ENV variable and so many things, but still not been able to get it.
Please suggest..
You can't, the browser interprets the fragment (#folders=1) without sending it to the server. So if http://my.indiamart.com/cgi/​my-enquiries.mp is your script, then it will never see the #folders=1 part of the URL as the browser won't send it. If you need the fragment on the server then you'll have to change it to a CGI parameter:
http://my.indiamart.com/cgi/​my-enquiries.mp?folders=1
or embed it in the URL path, something like one of these:
http://my.indiamart.com/cgi/​my-enquiries.mp/1
http://my.indiamart.com/cgi/​my-enquiries.mp/folders=1
You can't, # is recognized by JavaScript only,
apache will ignore this, that's the reason it does not contains any value in ENV variable.
You can use JavaScript: window.location.hash to capture this hash value.
Only with javascript.
You can use something like that to redirect to another script
<script>
if(window.location.hash) {
var str = window.location.hash.substring(1);
window.location.href = 'http://other_script.pl?param=' + str;
}
</script>

MVC2 Slash char in url

I want to use encrypted strings in MVC2 urls. A typical url in my app looks like this:
http://localhost:29558/Account/PasswordReset/ZKGeDMZikfIsnO8/MEs7SCBlI+MZo1Je8LM5dTEeCt3u91ARPUcavT5UXfVVRfyE
Note that everything after PasswordReset/ is the encrypted string. In the example the encrypted string contains a slash, and this is causing MVC to crash.
I've tried adding a MapRoute in Global.asax.cs as follows:
routes.MapRoute(
"PasswordResetSpecialCase", // Route name
"Account/PasswordReset/*", // URL with parameters
new { controller = "Account", action = "PasswordReset" } // Parameter defaults
);
but MVC2 is still falling over because the encrypted string contains a slash char. If I remove the slash then it works, but obviously that's no good.
How do I get MVC2 to regard everything after the PasswordReset as pure data?
Thanks.
Your maproute contains an error. Replace the * with {*nameOfParameter}