duanque19820925 2017-11-06 17:18 采纳率: 0%
浏览 428

Laravel:如何在重定向到获取方法路由URL时设置和获取自定义标头

I am using Laravel 5.3 and trying to redirect to a url with custom headers. But some how I am not getting the header value in redirected page or we can say header value is not getting sent while redirecting.

I am using this code:

return redirect()->route('frontend.seller.signup')->header('referal_code', $referal_code);

and For fetch Header value I use below code but I not recieve header value

$referal_code = Request::header('referal_code');

Please let me know if I'm doing something wrong.

  • 写回答

1条回答 默认 最新

  • dongshun7312 2017-11-06 17:37
    关注

    When you set headers for your response (even redirect is a response), headers are send to the client's browser.

    The browser will process the response and redirect the page to the new URL and make a new request to server, so as you can figure out, your previous custom headers will not be available in the new request.

    You can send any var using with() function to target url:

    redirect()->route('frontend.seller.signup')->with('referral_code', $referral_code);
    

    And get the variable in your target function using session:

    $referral_code = session('referral_code');
    

    By the way you can get the referrer in each request without setting any parameter in the referrer, if this is helpful in your case:

    $referer = $request->headers->get('referer');
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了