error/debug log question - array intersect

Discussion in 'Troubleshooting' started by jcary, May 23, 2010.

  1. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Hello... A little bit ago, I added the following custom code to my amember pages:

    PHP:
    session_start();
    $need_one_from = array(3,4); 
    if (
    array_intersect($need_one_from$_SESSION['_amember_product_ids'])){
       print 
    "User is subscribed to product #3 or product #4";
    } else {
       print 
    "User is not subscribed nor to product #3, nor to product #4";
    }
    It seems to be doing the trick, but I looked into my amember error/debug log, and see a lot of these errors:

    PHP:
    <b>WARNING:</barray_intersect() [<a href='function.array-intersect'>function.array-intersect</a>]: Argument #2 is not an array in line 99 of file /home/website/public_html/members/index.php
    Now, I do have a few different chunks of code on my page that look like this:

    PHP:
    <?php
          $need_one_from 
    = array(1);
          if (
    array_intersect($need_one_from$_SESSION['_amember_product_ids'])){
             print 
    "<li><a href=\"/members/upgrade-premium.php\">Upgrade to Premium?</a></li>
          <li><a href=\"/members/upgrade-platinum.php\">Upgrade to Platinum?</a></li>"
    ;
          }
          
    ?>


          <?php
          $need_one_from 
    = array(2,4);
          if (
    array_intersect($need_one_from$_SESSION['_amember_product_ids'])){
             print 
    "<li style=\"background:#b2ffb9;\"><a class=\"upgrade\" href=\"/members/premium/\">Access Premium Content</a></li>
             <li><a href=\"/members/upgrade-platinum.php\">Upgrade to Platinum?</a></li>"
    ;
          }
          
    ?>

          <?php
          $need_one_from 
    = array(3,5,7);
          if (
    array_intersect($need_one_from$_SESSION['_amember_product_ids'])){
             print 
    "<li style=\"background:#b2ffb9;\"><a class=\"upgrade\" href=\"/members/platinum/\">Access Platinum Content</a></li>";
          }
          
    ?>
    Is this a big issue, or can I safely ignore the errors in the log? Thanks.
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Modify your code and change:
    PHP:
    array_intersect($need_one_from$_SESSION['_amember_product_ids'])
    to

    PHP:
    array_intersect($need_one_from, (array)$_SESSION['_amember_product_ids'])
    Errors generated when user does not have active subscriptions so $_SESSION['_amember_product_ids'] will be empty.
  3. jcary

    jcary Member

    Joined:
    Aug 29, 2006
    Messages:
    87
    Thanks a bunch, Alex.

Share This Page