422,754 Members | 2,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,754 IT Pros & Developers. It's quick & easy.

How to keep a session or cookie alive after visiting and leaving a page

P: 1
Ok so am trying to build a referral system using the OAuth system, am working with the laravel framework. So when a user vist the registration page with a referral link it create a cookie and a session. for to register all that is provided is the social button. so whenever the user clicks on the register with google or facebook. Once the user comes back to the site the session and cookie disappear. Why is that? below are the files i think may be helpful

Where I created the session and cookie base on the ref

Expand|Select|Wrap|Line Numbers
  1. if ($request->has('ref')){
  2.                 $referral = ReferralLink::whereCode($request->get('ref'))->first();
  3.                 $response->cookie('ref', $referral->user_id, $referral->program->lifetime_minutes);
  4.                 $_SESSION['ref'] = $referral->user_id;
  5.                 request()->session()->put('ref', $referral->user_id);
  6.     }
Where I retrive the session and cookie base on the ref

Expand|Select|Wrap|Line Numbers
  1.   $session = request()->session()->get('ref');
  2.             dd(request());
  3.             $referral = \App\User\ReferralLink::where('user_id', $event->referralId)->orWhere('user_id', $session)->first();
  4.             // dd($event->user, $event->referralId, $referral);
  5.                 if (!is_null($referral)){
  6.                     $provider = $referral->user;
  7.                     \App\User\ReferralRelationship::create([
  8.                         'referral_link_id' => $referral->id, 
  9.                         'user_id' => $event->user->id,
  10.                         'referree_user_id' =>  $provider->id,
  11.                         'reward'    => 'no',
  12.                         ]);
  13.             }

the
Expand|Select|Wrap|Line Numbers
  1. `dd(request())`
returns session and cookies but without my own cookies and session
Mar 9 '18 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.