Redirect to external URL with return in laravel

2020-05-20 07:04发布

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:

http://cloud.smsindiahub.in/vendorsms/pushsms.aspx?user=abc&password=xyz&msisdn=919898xxxxxx&sid=SenderId&msg=test%20message&fl=0&gwid=2

If we load this URL, it will return some message. I need to get that message to.

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.

Or is there any plugin to send sms using SMS INDIA HUB?

Can anyone help??

6条回答
劳资没心,怎么记你
2楼-- · 2020-05-20 07:41

You should be able to redirect to the url like this

return Redirect::to($url);

You can read about Redirects in the Laravel docs here.

查看更多
Root(大扎)
3楼-- · 2020-05-20 07:42

You can use Redirect::away($url)

查看更多
聊天终结者
4楼-- · 2020-05-20 07:46

For Laravel 5.x use:

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:

查看更多
成全新的幸福
5楼-- · 2020-05-20 07:49

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.

查看更多
仙女界的扛把子
6楼-- · 2020-05-20 07:59

Define the url you want to redirect in $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 :

Here is the simple example

return Redirect::to('http://www.google.com');

Update 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;
查看更多
ら.Afraid
7楼-- · 2020-05-20 07:59

For Laravel 5.x we can redirect with just

return redirect()->to($url);
查看更多
登录 后发表回答