Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 550209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:15:52+00:00 2026-05-13T11:15:52+00:00

Can someone help me clean this up and make it more logical? I’m fried

  • 0

Can someone help me clean this up and make it more logical? I’m fried right now and can’t seem to get a good line of code written 🙂

I’m trying to capture affiliate id from urls like ?aid=3056677. The idea is IF aff id is set in GET that takes precedence, the session and finally cookie with least. Also, we don’t want to set an aff id that does not exist.

Do you know of a more tried and true method of doing this?

session_start(); // start session

// affiliate id
$g_aid = (isset($_GET['aid']) && $_GET['aid'] != '') ? trim($_GET['aid']) : false;
$s_aid = (isset($_SESSION['aid']) && $_SESSION['aid'] != '') ? trim($_SESSION['aid']) : false;
$c_aid = (isset($_COOKIE['aid']) && $_COOKIE['aid'] != '') ? trim($_COOKIE['aid']) : false;

if($g_aid !== false) // use get if set
  $aid = $g_aid;
elseif($s_aid !== false) // next use session if get not set
  $aid = $s_aid;
elseif($c_aid !== false) // cookie
  $aid = $c_aid;
else
  $aid = ''; // leave it empty

// if $aid is set is it in the $affiliates array?
//If not use the first key from that array
$aid = (isset($affiliates[$aid])) ? $aid : key($affiliates);

// save it and set it
// (maybe shouldn't be done if already stored?
setcookie('aid', $aid);
$_SESSION['aid'] = $aid;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:15:52+00:00Added an answer on May 13, 2026 at 11:15 am

    Thanks guys this is looking better and better. One point that might clarify for you, is that IF an aff id is given in GET it MUST be a valid one that exists before we possibly wipe out someone else’s aff id. Money is involved with each transaction and we want an affiliate to get credit for as long as possible.

    Regarding empty it’s not too useful since whitespace fools it. So unless you trim before using it, I feel it’s not accurate enough. So I don’t know about the empty for the GET. It’s ok for the others because we’ve already checked them.

    Here’s what I have so far from your help (does the complex ternary here break when it finds true? I don’t want it to keep executing the line):

    session_start(); // start session
    
      $aid = !empty($_GET['aid'])     ? trim($_GET['aid']) :
             !empty($_SESSION['aid']) ? $_SESSION['aid'] : 
             !empty($_COOKIE['aid'])  ? $_COOKIE['aid'] :
             '';
    
      // use first key from array if aid not set
      if(!isset($a[$aid])) $aid = key($a);
    
      if(!isset($_SESSION['aid']) || $aid != $_SESSION['aid'])
      {
        setcookie('aid', $aid);
        $_SESSION['aid'] = $aid;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me clean up this nested regex (re.sub) in python, please? I
Can someone help me identify what the purpose of this unidentified syntax is. It
Can someone help me figure out the following make file? BINS=file1 file2 file3 all:
Can someone help me with this: This is a program to find all the
Can someone help me create an index/count button for a UITableView, like this one?
can someone help with this? I need the following function to do this... $x
Can someone help me on this. I'm made an image uploader and i want
my SQL skills aren't strong enough to figure this out, hope someone can help.
I was wondering if someone could help me to get this method converted to
I hope someone can help with this. I have created a map app that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.