Fork me on GitHub

pnUserGetVar returns blanks  Bottom

  • I have searched around the forums and couldn't find an answer to this.

    I have a little module that needs to get the user_from data from the logged in user. Here is the debugging code I use.

    Code

    if (!pnUserLoggedIn()) {
            $location = pnUserGetVar('pn_user_from');
            echo "location = $location<BR>";
        }


    No matter who I log in with, it always displays

    location =

    does anyone know why this is happening or how to fix it?
    Thanks.
  • Are you sure that variable name is correct?
  • Yes, i have used many variable names and none work.
    For example:

    Code

    $location = pnUserGetVar('pn_user_from');
    $location2 = pnUserGetVar('user_from');
    $uname = pnUserGetVar('uname');
    $uid = pnUserGetVar('uid');


    will all return blanks. But if I force the uid like

    Code

    $location = pnUserGetVar('user_from', '2');


    It will return the correct data.
  • Your logic above says if the user is NOT logged in and thus the anonymous user won't have this variable set.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • I tried removing the ! and then when I'm logged in, it doesnt echo anything. I removed the whole if statement for a test and still nothing. I have this in a block on my front page. This shouldn't be a problem right? Do I need to include some file in order for it to work?
  • It is looking like pnUserLoggedIn() doesnt return anything which is leading me to believe is has something to do with the session vars. I am using this in a PHP block. Should I have this script in something else in order to read the session vars?
  • Nope - should work as is, you must have a syntax error in there somewhere. When creating a PHP block, be sure not to include the opening/closing PHP tags.

    Why not paste the code you are using in this post & someone might be able to see the problem.

    --
    Get PhotoGallery, PayPalCart, Dynamenu, Enhanced Blocks & other mods

    Cape Cod Travel Info...
  • Code

    $flag = 0;
    $values = (array) null;

    function contents($parser, $data) {
            global $flag;
            global $values;
            static $i = 0;
            if( $flag == 1 ) {
               $values[$i] = $data;
               $i++;
            }
    }
    function startTag($parser , $data) {
            global $flag;
            switch ($data) {
               case "OBST" :
                    $flag = 1;
                    break;
               case "TMP"  :
                    $flag = 1;
                    break;
               case "FLIK" :
                    $flag = 1;
                    break;
               case "ICON" :
                    $flag = 1;
                    break;
               case "UT"   :
                    $flag = 1;
                    break;
               default     :
                    $flag = 0;
                    break;
            }
    }

    function endTag($parser, $data) {
            global $flag;
            if( $flag == 1 ) {
               $flag = 0;
            }
    }

       $zipcode = "14623";
       if(pnUserLoggedIn()) {
            echo "Holy crap, you are logged in!!<BR>";
            $location = pnUserGetVar('_ZIPCODE');
            $uid = pnUserGetVar('uid');
            echo "location = $location<BR>uid = $uid<BR>";
            if($location == "") {
               $zipcode = "14623";
            }
            else
               $zipcode = $location;
       }

       $file = "http://xoap.weather.com/weather/local/$zipcode?cc=*&dayf=0&prod=xoap&par=1004226390&key=00def04448287412";
       $xml_parser = xml_parser_create();
       xml_set_element_handler($xml_parser, "startTag", "endTag");
       xml_set_character_data_handler($xml_parser, "contents");
       $fp = fopen($file, "r");
       $data = fread($fp, 80000);
       if(!(xml_parse($xml_parser, $data, feof($fp)))){
            die("Error on line " . xml_get_current_line_number($xml_parser));
       }

       echo "<center>\n";
       echo "<tr>\n";
       echo "<td bgcolor=\"CBD3D7\">\n";
       echo "<center>\n";
       echo "Weather for $values[1]<BR>\n";
       echo "<img src=\"/modules/Weather/medium/$values[4].png\" border=\"0\"><BR>\n";
       echo "<b>$values[2]º $values[0]</b><BR>\nFeels like <b>$values[3]º $values[0]</b>\n";
       echo "</center>\n";
       echo "</td>\n";
       echo "</tr>\n";
       echo "</center>\n";

       xml_parser_free($xml_parser);
       fclose($fp);


    I used to put

    Code

    include("http://iamabigdummy.com/modules.php?op=modload&name=Weather&file=weather");

    into the PHP block. I think that is why the pnUserGetVar didnt work. After I put the code straight into the PHP block, pnUserGetVar works now but the array $values doesn't get out of the 'contents' function anymore.
  • I figured it out,

    I put the bottom echo's in their own block with a global $values; in it as well.

This list is based on users active over the last 60 minutes.