php Laravel 5:重定向到本地主机/服务器之外的外部链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29158074/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:16:26  来源:igfitidea点击:

Laravel 5: redirect to an external link outside of localhost/server

phpdropbox-apilaravel-5

提问by She Fu

I want to build an app with laravel 5 & dropbox API in which I want the API allow/cancel-warning to be displayed when you land on the homepage, not when you click a button. I tried different methods but I couldn`t make it work.

我想使用 laravel 5 和 dropbox API 构建一个应用程序,其中我希望在您登陆主页时显示 API 允许/取消警告,而不是在您单击按钮时显示。我尝试了不同的方法,但我无法使它起作用。

public function start(){
        session(['user_id'=>1]);
        $dKey = 'key';
        $dSecret = 'secret';
        $appName = 'app';

        $appInfo = new Dropbox\AppInfo($dKey,$dSecret);

        //store csrf token
        $tokenStore = new  Dropbox\ArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');
        //define auth details
        $this->webAuth = new Dropbox\WebAuth($appInfo,$appName,'http://localhost:8000/dropbox/finish',$tokenStore);
        $this->checkSession();
    }

    public function checkSession(){
        $users = User::where('id','=',session('user_id'))->get();

        if(isset($user[0]->dropbox_token)){

        }
        else{
            $url = $this->webAuth->start();

            //return Redirect::to($url);
            //return Redirect::away($url);
            //header('Location : '.$url);
        }

    }

The link in $url exists and its valid.

$url 中的链接存在且有效。

These(last 3 commented methods) are the methods i tried , including return redirect($url),is it possible to do this or am i wasting my time with this ?please help me out.

这些(最后 3 个评论的方法)是我尝试过的方法,包括返回重定向($url),是否可以这样做,或者我是否在浪费时间?请帮助我。

回答by user94559

This code works for me:

这段代码对我有用:

return redirect()->away('https://www.dropbox.com');

Make sure you also add a return (i.e. return $this->checkSession();) in start().

请确保您还添加回报(即return $this->checkSession();中)start()

回答by Pankaj Makwana

Below code will work

下面的代码将工作

return redirect()->away('http://www.paypal.com');

And this will also work.

这也将起作用。

return redirect('http://www.paypal.com');

回答by Harry Bosh

For https and such use the following

对于 https 等,请使用以下内容

return redirect()->to($refererUrl);

回答by Aruna Perera

Can do this,

可以这样做,

use Redirect;

return Redirect::to('your url');

Or just,

要不就,

return \Redirect::to('your url');