Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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.

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

        $appInfo = new DropboxAppInfo($dKey,$dSecret);

        //store csrf token
        $tokenStore = new  DropboxArrayEntryStore($_SESSION,'dropbox-auth-csrf-token');
        //define auth details
        $this->webAuth = new DropboxWebAuth($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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...