Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

how can you access this variable

y2kbgy2kbg New
edited December 2006 in Vanilla 1.0 Help
how can you access this variable: $Context->Session->User->Name from a seperate .php file in the same directory as vanilla when someone is logged in?

Comments

  • anyone? is this question confusing, To clarify i just want to be able to get the username.
  • edited December 2006
    include("/path/to/appg/settings.php"); include("/path/to/appg/init_ajax.php"); echo $Context->Session->User->Name;
  • ohh thanks!! ur cool!!!
  • maybe not!! i get a bunmch of similar notices: Notice: Constant MAGIC_QUOTES_ON already defined in /www/110mb.com/z/f/i/l/e/s/_/_/zfiles/htdocs/appg/settings.php on line 226 and then a fatal ERROR: Fatal error: Cannot redeclare class mysql in /www/110mb.com/z/f/i/l/e/s/_/_/zfiles/htdocs/library/Framework/Framework.Class.MySQL.php on line 14 this is in a function that gets call MANY times on the same page.
  • require_once("/path/to/appg/settings.php"); require_once("/path/to/appg/init_ajax.php"); echo $Context->Session->User->Name;
    ?
  • ok i will try that!
  • hmm doest seem to work.
  • MarkMark Vanilla Staff
    Show your entire source so we can see what's wrong.
  • y2kbgy2kbg New
    edited December 2006
    ok actully i didn't write it, I have some code that uses ajax to rate something in stars. It track your IP This will be used alot in a school where many people use the same computer so i want it to log the screen name instead. <code> <?php /* Page: _drawrating.php Created: Aug 2006 The function that draws the rating bar. --------------------------------------------------------- ryan masuga, masugadesign.com ryan@masugadesign.com --------------------------------------------------------- */ function rating_bar($id,$units='') { require('_config-rating.php'); // get the db connection info require_once("appg/settings.php"); require_once("appg/init_ajax.php"); $ip = $Context->Session->User->Name; //$ip = $_SERVER['REMOTE_ADDR']; if (!$units) {$units = 10;} $query=mysql_query("SELECT total_votes, total_value, used_ips FROM $tableName WHERE id='$id' ")or die(" Error: ".mysql_error()); $numbers=mysql_fetch_assoc($query); $count=$numbers['total_votes']; //how many votes total $current_rating=$numbers['total_value']; //total number of rating added together and stored $tense=($count==1) ? "vote" : "votes"; //plural form votes/vote // determine whether the user has voted, so we know how to draw the ul/li $voted=mysql_num_rows(mysql_query("SELECT used_ips FROM $tableName WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' ")); // now draw the rating bar ?> <div class="ratingblock"> <div id="unit_long<?php echo $id ?>"> <ul id="unit_ul<?php echo $id ?>" class="unit-rating" style="width:<?php echo $unitwidth*$units; ?>px;"> <li class="current-rating" style="width:<?php echo @number_format($current_rating/$count,2)*$unitwidth; ?>px;">Currently <?php echo @number_format($current_rating/$count,2); ?>/<?php echo $units ?></li> <?php for ($ncount = 1; $ncount <= $units; $ncount++) { // loop from 1 to the number of units if(!$voted) { // if the user hasn't yet voted, draw the voting stars ?> <li><a href="db.php?j=<?php echo $ncount ?>&q=<?php echo $id ?>&t=<?php echo $ip ?>&c=<?php echo $units ?>" title="<?php echo $ncount ?> out of <?php echo $units ?>" class="r<?php echo $ncount ?>-unit rater"><?php echo $ncount ?></a></li> <?php } } $ncount=0; // resets the count ?> </ul> <p<?php if($voted){?> class="voted"<?php } ?> ><?php echo $id ?>. Rating: <strong> <?php echo @number_format($current_rating/$count,1) ?></strong>/<?php echo $units ?> (<?php echo $count ?> <?php echo $tense ?> cast) </p> </div> </div> <? } ?></code>
  • y2kbgy2kbg New
    edited December 2006
    i get a whole bunch of errors here are the first 3: <code> Notice: Undefined variable: Configuration in /www/110mb.com/z/f/i/l/e/s/_/_/zfiles/htdocs/appg/init_ajax.php on line 13 Notice: Undefined variable: Configuration in /www/110mb.com/z/f/i/l/e/s/_/_/zfiles/htdocs/appg/headers.php on line 20 Notice: Undefined variable: Configuration in /www/110mb.com/z/f/i/l/e/s/_/_/zfiles/htdocs/appg/init_ajax.php on line 14 tell me if you want more of anything. </code> can anyone think of a simple workaround?
  • *bump*?
  • what about a complicated inefficent workaround? I need this.
  • You are including the Vanilla file from inside a function when the whole thing is designed to be global.
    I don't see why it should'nt work as local but give a try at a global include.
  • well this is a function that is called by code in a pagemanager page but the actual function code is in a seperate file. when i try it without adding require i get alotless errors.
  • could this be caused by the absince of a .htaccess ? my host doesnt allow these. Global include?
  • include the vanilla file at the global level, not from inside a function.
    Then in your function
    global $Context; $ip = $Context->Session->User->Name;
    Not sure though, just a clue.
  • well it not work out of funtion .. but when inside it!!!!!!!!!!! yea it works thank you!!!
This discussion has been closed.