php 重定向到外部 URL,并在 Laravel 中返回
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28642753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Redirect to external URL with return in laravel
提问by manoos
I am trying to send one time password to a user using SMS INDIA HUB API. For that purpose I need to redirect to a URL format:
我正在尝试使用 SMS INDIA HUB API 向用户发送一次性密码。为此,我需要重定向到 URL 格式:
If we load this URL, it will return some message. I need to get that message to.
如果我们加载这个 URL,它会返回一些消息。我需要收到这条消息。
I tried like this
我试过这样
$url = "http://cloud.smsindiahub.in/vendorsms/pushsms.aspx?user=wwww&password=eee&msisdn=9197xxxxx&sid=yyyyy&msg=rrrrr&fl=0&gwid=2";
return Redirect::intended($url);
But it is not directing to that link. It tries to load that URL in localhost.
但它不是指向那个链接。它尝试在本地主机中加载该 URL。
Or is there any plugin to send sms using SMS INDIA HUB?
或者是否有任何插件可以使用 SMS INDIA HUB 发送短信?
Can anyone help??
有人可以帮忙吗??
回答by Laurence
You should be able to redirect to the url like this
您应该能够像这样重定向到网址
return Redirect::to($url);
回答by Sulthan Allaudeen
Define the url you want to redirect in $url
定义要重定向的网址 $url
Then just use
然后只需使用
return Redirect::away($url);
If you want to redirect inside your views use
如果你想在你的视图中重定向使用
return Redirect::to($url);
Read more about Redirect here
Update 1 :
更新 1:
Here is the simple example
这是一个简单的例子
return Redirect::to('http://www.google.com');
Update 2 :
更新2:
As the Questioner wants to return in the same page
由于发问者希望返回同一页面
$triggersms = file_get_contents('http://www.cloud.smsindiahub.in/vendorsms/pushsms.aspx?user=efg&password=abcd&msisdn=9197xxx2&sid=MYID&msg=Hello');
return $triggersms;
回答by Adam
For Laravel 5.x use:
对于 Laravel 5.x 使用:
return redirect()->away('https://www.google.com');
as stated in the docs:
如文档中所述:
Sometimes you may need to redirect to a domain outside of your application. You may do so by calling the away method, which creates a RedirectResponse without any additional URL encoding, validation, or verification:
有时您可能需要重定向到应用程序之外的域。您可以通过调用 away 方法来实现,该方法创建 RedirectResponse 而不需要任何额外的 URL 编码、验证或验证:
回答by sadiq
For Laravel 5.x we can redirect with just
对于 Laravel 5.x,我们可以重定向
return redirect()->to($url);
回答by Vishal Wadhawan
You can use Redirect::away($url)
您可以使用 Redirect::away($url)
回答by Arthur Tsidkilov
Also, adding class
另外,添加类
use Illuminate\Http\RedirectResponse;
and after, like this:
之后,像这样:
public function show($id){
$link = Link::findOrFail($id); // get data from db table Links
return new RedirectResponse($link->url); // and this my external link,
}
or -
或者 -
return new RedirectResponse("http://www.google.com?andParams=yourParams");
For external links have to be used full URL string with 'http' in begin.
对于外部链接,必须使用以“http”开头的完整 URL 字符串。