PHP - Make An Array Global Available
Hey,
I've been developing a browsergame. In this you are able to produce something ("weed"). Now I've got some kind of trouble with the function that is responsible for updating the "weed" on the user accounts. Im going to explain, how my script is working First step: Loading the datas from "worlds". In this case id, weed_factor, weed_basis. What this is required for you will see in the next steps <?php include 'includes/settings/mysql.php'; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbbase); $time = time(); $update_weed_world_data_sql = "SELECT id, weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_id = $update_weed_world_data_while['id']; $update_weed_world_basis[$update_weed_world_id] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[$update_weed_world_id] = $update_weed_world_data_while['weed_factor']; global $update_weed_world_basis; } Second step: This is the function which is editing each account by the data given as parameters. function do_update_weed($profile_id,$world,$update,$level,$time){ $update_weed_period = $time - $update; $update_weed_add = ($update_weed_period / 3600 * $update_weed_world_basis[$world] * pow($update_weed_world_factor[$world],$level)) +1; echo $update_weed_world_basis[$world]; echo "<br>"; mysql_query("UPDATE profiles SET weed = weed +$update_weed_add, weed_update = $time WHERE id = $profile_id LIMIT 1"); } Note: echo $update_weed_world_basis[$world]; doesnt result an output. In step three, the accounts are loaded: function todo_update_weed($time){ $todo_update_weed_sql = "SELECT * FROM profiles WHERE weed_update < $time"; $todo_update_weed_res = mysql_query($todo_update_weed_sql) or die (mysql_error()); while($todo_update_weed_while = mysql_fetch_assoc($todo_update_weed_res)){ do_update_weed( $todo_update_weed_while['id'], $todo_update_weed_while['world_id'], $todo_update_weed_while['weed_update'], $todo_update_weed_while['level_farm'], $time ); } } And the last step is calling function "todo_update_weed" with the time. todo_update_weed($time); I script calculate the time between the last update and the current time. This make a difference in time. With this value I calculate something else. And then the update time has to be saved. The script has just working fine, when I set the variable "$update_weed_add" with a fix value. But by now the script doesn't work, because I don't know how to make the array available inside functions. I considered whether I put the database-function for the world_data inside the function that updates the profiles. But if I do this, the database will be called thousands of times... Hope anybody has a nice idea to fix the problem Similar TutorialsHi, As the title suggests I am unsure on how to first run a query which stores values into an array. I then need to run a function multiple times but use the array within the function. How is this possible? I have had no luck figuring it out yet. 1. RUN QUERY 2. BUILD ARRAY USING QUERY RESULTS 3. RUN FUNCTION MULTIPLE TIMES 4. WITHIN FUNCTION I NEED TO USE ARRAY Many thanks Simon Hiya! I was wondering if this is possible. Here is my example. This is a example class; <?php class a { public function __construct() { } public function returnValue() { include 'files/lang.php'; $this->lang = new lang(); return $this->lang->displayLang('10'); } } ?> This is the second class file; <?php class b { public function __construct() { } public function returnValue() { include 'files/lang.php'; $this->lang = new lang(); return $this->lang->displayLang('10'); } } ?> This is the main file; <?php include 'test/a.php'; $test = new a(); $test->returnValue(); include 'test/a.php'; $test2 = new b(); $test2->returnValue(); ?> With this I'm getting an error stating I cannot redeclare the function lang. I have found a way around this by using require_once but I was wondering if remove the include and $this->lang var from class 2 and I put this as the $this->lang var declaration in class 1; global $this->lang = new lang(); will class 1 and class 2 be able to use it from only the one declaration made in class 1. If so, would this be the way to do it or is there a better/working way to do it? Many many thanks, James. Hi All, For the last post,I m very happy that i found out so many great mind who are watching my problem and solving online. anyway great thanks for all, just now i m making a project and i m facing problem in the below code "i need to know how can make this code easy or how can i make rdata variable accessible for the download button" generatecv.php file <?php if(isset($_REQUEST['submit'])) { $name=$_REQUEST['pname']; $pin=$_REQUEST['pin']; $mnumb=$_REQUEST['mnumber']; $tnumb=$_REQUEST['telenumber']; $email=$_REQUEST['email']; $obj=$_REQUEST['obj']; $title=$_REQUEST['jobt']; $activity=$_REQUEST['activity']; //$file=fopen('test.doc','a+'); //echo @fwrite($file,$name); //fclose($file); $rdata=""; $rdata.="<table id='cvtbl' border='0' align='center' > <th>Resume</th> <tr><td>".$name.":</td></tr><tr><td>Objective:</td></tr>"; $rdata.="<tr><td>".$obj."</td></tr>"; $rdata.="<tr><td>Email:".$email."</td></tr>"; $rdata.="</table>"; echo $rdata; echo "<style>#cv{display:none;}</style>"; echo "<form><input type='submit' name='dwnld' id='dwnld' value='Download'/></form>"; } if(isset($_REQUEST['dwnld'])) { header("Content-type:application/msword"); header("Content-disposition:attachment;filename=test.doc"); $fp=fopen("test.doc","r") or die("try again"); $data=fread($fp,filesize('test.doc')); fwrite($fp,$rdata); echo $data; fclose($fp); //echo $rdata."<br />".$rdata; } ?> this is the html file <html> <title>User details</title> <body> <form name='cv' id='cv' method="post" enctype="multipart/form-data" action='generatecv.php'> Enter your name<input type=text name=pname id=pname /> Zip Code<input type=text name=pin id=pin /> Mobile number<input type=text name=mnumber id=mnumber /> <br />Telephone number <input type=text name=telenumber id=telenumber /> Email address<input type=text name=email id=email /> <br />Enter your objective<br /><textarea name=obj id=obj cols=30 rows=5 ></textarea> <!--University Name <input type=text name=university id=university /> --> <br /><!--uni, city ,state ,type of degree ,full degree name,date--> <br /><!--Experience<br /><textarea name=exp id=exp cols=30 rows=5 ></textarea> --> Select type of resume <select name='type' id='type' onChange=''> <option value='0'>Graduate</option> <option value='1'>Post Graduate</option> <option value='2'>Non Graguate</option> <option value='3'>Other</option> </select> Job title<input type='text' name='jobt' id='jobt' /> <br /><!--company name,city ,state ,office number ,job description ,date of employment--> <br />Activity <input type=text name=activity id=activity size=100 /> <br />Honors/Awards<input type=text name=honor id=honor size=100 /> <input type='submit' name='submit' id='submit' value='Generate CV' /> <input type='reset' name='Reset' id='submit' value='Reset' /> </form> </body> </html> Many thanks in advance I need $row['con_id'] outside the function so I can put it into a query, but simply putting global in front of it won't work. What would be the right way to do? This portion of code is INSIDE a function: //Loop through the array of data while ($row = mysqli_fetch_array ($data)) { echo "<table padding='0' margin='0' class='knuffixTable'>"; echo "<input type='hidden' name='con_id' value='<?php echo " . $row['con_id'] . "; ?>' />"; echo "<tr><td width='65px' height='64px' class='avatar_bg' rowspan='2' colpan='2'><img src='$avatar_path' alt='avatar' /></td><td class='knuffix_username'><strong>" . $user_name; echo "</strong><br />" . $row['category'] . " | " . date('M d, Y', strtotime($row['contributed_date'])) . "</td></tr><tr><td>"; echo "<form action='' method='post'> <input type='submit' name='plusVote' value='Y' /> <input type='submit' name='minusVote' value='N' /> </form></td><td class='votes'>Y[ - ] | N[ - ]</td></tr>"; echo "<tr><td class='knuffix_name' colspan='3'><strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td colspan='2' class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "</table>"; The PHP documentation does not show any examples how to GLOBALIZE a mysqli function. I'd need a way to use $row['con_id'] outside the function for the voting script I'm writing. Thanks for the suggestions. I know there is a function for this, but for some reason my google-fu is off and I cannot remember it for the life of me. What is the function to export an array into the global namespace? Such that: $var=array('key'=>'val'); somefunc($var); echo $key; Would work? Hey all, I'm well aware of associative arrays (key/value pairs) and how you can index them in an array like this: $character = array (name=>"John", occupation=>"Programmer", age=>22, "Learned language "=>"PHP" ); Then it makes sense to iterate through the key/value pairs of the array using foreach: foreach ( $character as $key=>$val ){ print "$key = $val<br>"; } However, I was watching a video tutorial where he created a $_SESSION array and then created an array associative array: $_SESSION['cart'] = array(); [/PHP] Then he added a function add_to_cart: function add_to_cart($id){ if(isset($_SESSION['cart'][$id])){ $_SESSION['cart'][$id]++; return true; } else { $_SESSION['cart'][$id] = 1; return true; } return false; } Now that $id variable holds an id converted to integer from the dataabse. So if first item is clicked, id holds a value of integer 1. When I see this: $_SESSION['cart'][$id] I see an array that holds two indexes, each index containing an associative array: [[array() => ''], [1 => '']]. So at index 0 of $_SESSION is [array() => '']. But then he uses the foreach iterator like this: function total_items($cart){ $items = 0; if(is_array($cart)){ foreach($cart as $id => $qty){ $items += $qty; d } } return $items; } Now I'm very confused. As you can see in that foreach method, it says that $id (and its corresponding value) is an associative array of $cart array, not $_SESSION array. I don't see how that happened. I thought $cart and id$ were distinct indexes of $_SESSION. I don't see how $id is a key of the $cart array. Thanks for any explanation to clear my confusion. Given array Code: [Select] Array ( [Post] => Array ( [title] => new with has many through for tags [body] => hello tags [category_id] => 11 [tags] => one two three [mark] => 1 ) ) I need to make an array something like this: Code: [Select] Array ( [Post] => Array ( [title] => new with has many through for tags [body] => hello tags [category_id] => 11 [mark] => 1 ) [Tag] => Array ( [0] => Array( [name] => one ) [1] => Array( [name] => two ) [2] => Array( [name] => three ) ) ) How can i make it? $looponce = 1; foreach ($this->info as $k => $v) { if ( (($k == 'subject') && ($v['required'])) && (!$this->settings['customSubject'])) { for ($i = 0; $i <= 0; $i++) { $output[] = $this->display_errors('error_system_subject'); } } if ( (($k == 'name') && (!$v['required'])) || ((!array_key_exists("name", $this->info)) && ($looponce == 1)) ) { $output[] = $this->display_errors('error_system_name'); $looponce++; } } That is my loop that i check things in. What i'm more interested in is the name if statement. If currently checks for a name key in an array(below) and makes sure that it is set to required. If it's not set to required, print out a system error and die()'s. I'm looking for ways to remove the need for program errors and just change them to what is needed to run. What i know how to do is, get into the inner array, what i don't know is how to edit the data and put it back exactly as it was given to me. The inner array data can be put back in any order, but the outer array must be in exact order as it was given. above code $this->info = $formdata; $formdata = array( 'name' => array('name'=>"Full Name", 'required'=>false, 'type'=>'text'), # This needs to be required=>true, but i can't trust the user, which is why i have the error. 'telephone' => array('name'=>"Telephone", 'required'=>false, 'type'=>'phone'), ); Any help is greatly appreciated, also am i doing the foreach loop in the code above in an efficient manner or is there another way?
This is the cart array: I want the key to be "id" and the value to be "quantity" like it is for the cart array. How do I define my cart_items array using variables? Ok, so this seems kinda vague, cus normally thats what you do, however I am talking about a differnt kinds of output from a query... Here is what i am a talking about: My Query Code: $query = "SELECT * FROM settings WHERE storeid='store350' "; $which = $handle_db2; $result = mysql_query($query,$which); $num = mysql_num_rows ($result); $id = mysql_result($result,$i,"id"); $storeid = mysql_result($result,$i,"storeid"); $tinypass = mysql_result($result,$i,"tinypass"); $taxsetting = mysql_result($result,$i,"taxsetting"); $gst = mysql_result($result,$i,"gst"); $pst = mysql_result($result,$i,"pst"); $hst = mysql_result($result,$i,"hst"); $canpar = mysql_result($result,$i,"canpar"); $cp_fuelcharge = mysql_result($result,$i,"cp_fuelcharge"); $cp_markup = mysql_result($result,$i,"cp_markup"); $fedex = mysql_result($result,$i,"fedex"); $fe_fuelcharge = mysql_result($result,$i,"fe_fuelcharge"); $fe_markup = mysql_result($result,$i,"fe_markup"); $dhl = mysql_result($result,$i,"dhl"); $dh_fuelcharge = mysql_result($result,$i,"dh_fuelcharge"); $dh_markup = mysql_result($result,$i,"dh_markup"); $tnt = mysql_result($result,$i,"tnt"); $tn_fuelcharge = mysql_result($result,$i,"tn_fuelcharge"); $tn_markup = mysql_result($result,$i,"tn_markup"); As you can see, my variables are the same as my table column names... now if this "project" goes thorugh I could have hundreds of columns, I would hate to have to define each one making my file even larger. Is there a way to make it dynamically create the variables via an array or something Theoriticaly something like this: $query = "SELECT * FROM settings WHERE storeid='store350' "; $which = $handle_db2; $result = mysql_query($query,$which); $num = mysql_num_rows ($result); (While loop here) $Table_name_var = mysql_result($result,$i,"table_name"); (end while loop) Possible? Hello, everyone: I'm using PHP and Mysql. I've got a table of that has 30 fields that I need to add together. I've got to do this for each record, and there are about 10,000 records. Which would be more efficient? SELECT SUM( field1 + field2...) or to make an array for the fields and then use array_sum() Thanks. If I have a db with these fields: displayname, title and I run a successful query on the db, will this code: if (mysql_num_rows($results) == 0) { return "!fail"; } else { while ($row = mysql_fetch_assoc($results)) { extract($row); } return $row; } create an associative array of $var = array(array('displayname' => value, 'title' => value), array('displayname' => value, 'title' => value)...) If not, is there a way to do so, especially when I will not know the names or number of fields in a db table? I have the following code: Code: [Select] private function buildJSResponse(){ $data = ""; $i = 0; $arr = array(); while($this->db->row()){ $arr[] = (int)$this->db->field("average"); } $this->max = max($arr); $this->min = min($arr); $this->mid = round(($this->max + $this->min) / 2); foreach($arr as $val){ $nTime = ($val / $this->max) * 100; $data .= "data[$i] = ".$nTime.";"; $i++; } return $data; } It takes an array, finds the max/min and number halfway between the min/max. The next part I am not sure what to do. I am making a line graph using the canvas, so I am building a javascript array, which will contain the point on the chart. The problem I am having, is location. Lets say $max = 110, and $min = 95. the y position on the graph should be 0 for $max, and 100 for $min, then all the other points need to fall into their place as well. $nTime is supposed to do that, but it doesn't any suggestions? The attachment is the result I am getting from my above code. As you can see the lowest number is 49, so the value with 49 should touch the bottom, which it doesn't. ok .. so I have this object and I want to make a tab delimited text file from it. here's what I have so far. function create_tab_file_from_object($the_object) { $string = ''; foreach($the_object as $val) { $string .= $val.'\t'; } //drop last tab $string = substr($string,0,-2); filename = 'test_file_pickup.txt'; $fp = fopen('/filepath/'.$filename,'w'); fwrite($fp,$string); fclose($fp); } when i run this i get a text file that looks something like this field1\tfield2\tfield3\t ... and so on. How do I get php to make an actual tab delimited file I can open in notepad or excel or whatever.. Thanks in advance, C hi friends, I am using one API in which i need to make request for flight search, i am using soapclient to connect with the server to fetch available flights, below is the xml in which request format will be. SOAP 1.1 The following is a sample SOAP 1.1 request. The placeholders shown need to be replaced with actual values. POST /tws_mind/Ws_TravelPortal.asmx HTTP/1.1 Host: 125.16.62.119 Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/Ws_fnAirAvail" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Ws_fnAirAvail xmlns="http://tempuri.org/"> <objReq> <destination> <string>string</string> <string>string</string> </destination> <domestic>boolean</domestic> <journeydate> <dateTime>dateTime</dateTime> <dateTime>dateTime</dateTime> </journeydate> <journeytype>string</journeytype> <Noofadults>int</Noofadults> <Noofchild>int</Noofchild> <Noofinfant>int</Noofinfant> <preferedairlines> <string>string</string> <string>string</string> </preferedairlines> <preferredclass>string</preferredclass> <returndate>dateTime</returndate> <source> <string>string</string> <string>string</string> </source> <strPreferredCarrierType>string</strPreferredCarrierType> <GetCachedData>boolean</GetCachedData> </objReq> <objSecurity> <strLoginId>string</strLoginId> <strPassword>string</strPassword> </objSecurity> </Ws_fnAirAvail> </soap:Body> </soap:Envelope> and below is the request which is made by me. $request=array( 'objReq'=>array('destination' => "DEL", 'domestic' => 1, 'journeydate'=>"25/10/2011", 'journeytype'=>"R", 'Noofadults'=>2, 'Noofchild'=>0, 'Noofinfant'=>0, 'preferedairlines'=>"", 'preferredclass'=>"Y", 'returndate'=>"28/10/2011", 'source'=>"BLR", 'strPreferredCarrierType'=>"ANY", 'GetCachedData'=>false ) 'objSecurity'=>array('strLoginId'=>"loginid", 'strPassword'=>"password" ) ); $wsdl="http://*/*/?wsdl"; try{ $cliente=new SoapClient($wsdl); $vem=$cliente->Ws_fnAirAvail($request); } catch (Exception $e) { echo $e->getMessage(); exit; } echo "<pre>"; print_r($vem); My problem is i am getting below response, if i change the request in anyway i always get the same response. Please correct my request in case i made bad request for the server. stdClass Object ( [Ws_fnAirAvailResult] => stdClass Object ( [objclsException] => stdClass Object ( [errorcode] => GEN0E0006 [errortype] => E [errordesc] => Please provide Security object. ) [strMessage] => ) ) I am using a WordPress theme that uses some of its own functions besides WP functions. Let me make clear from the start that when I say "Multiple Checkboxes" in the paragraphs below I am NOT talking about checkboxes that each hold a single value. I am talking about one Checkbox field that allows multiple values to be selected and puts those values into an array with one Name value and stores the output in a string in a single mysql table field. Right up front, what I need during the Edit Ad functions is the inbuilt function that will Delete the previous Array of values in any multiple checkbox when the ad is updated. Right now updating the ad works for every situation except NO values selected or for Unchecking all previously selected values in a Multiple Checkbox. If I have, for example, 4 checkboxes selected and unselect all of them before submitting the edited ad it will return the last saved array of values but not an Empty array with no checkboxes selected. This theme has a Form Builder with a Custom fields builder used by the admin to create forms for a classified ads website. According to which category of ad the Ad creation procedure will show different forms, with different fields. I had to manually create the capability to generate multiple checkboxes...so that the different multiple checkboxes when selected and updated to the mysql table might hold a variety of values in a comma-delimited array. That works fine. When the Ad is edited on its own page, (outside of the Wordpress admin dashboard) the problem is that if a user would uncheck all checkboxes in a particular multiple checkbox then the unselected state does not overwrite the previous array of values. What returns after editing is the previous selected values. I have tried jquery functions but none of them are working the way I had hoped. so one type of checkbox might have a hypothetical value like this "name="cp_checkbox_help[]" and if three options are selected then on submit the value could be--- name="cp_checkbox_help[Sunday,Monday,Tuesday]" I use implode and explode to store the array as comma separated and retrieve the array for editing or display. I guess I need to create a Null or empty value as a default that only changes when selections are made. But, since I use implode and explode to make the array "pretty" I don't know if simply specifying nothing will erase a whole array on update. Here is some of the code used to see how I get what I get-- This displays the checkboxes that I create and name and fill with different values-- case 'checkbox': ?> <?php $options = explode(',', $result->field_values); echo '<div id="checkboxes"><table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <th colspan="2" scope="col">' . $result->field_label. '</th> </tr>'; $myvals= explode(',', $post_meta_val); foreach ($options as $option) { { ?> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="<?php echo $result->field_type; ?>" name="<?php echo $result->field_name; ?>[]" class="checkbox<?php if($result->field_req) echo ' required'?>" id="<?php echo $field_label; ?>" value="<?php echo $option; ?>" <?php foreach ($myvals as $myval) { if (in_array($myval, array($option), true)) {echo 'checked="yes"';}}?>/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" ><?php echo $option . '</td> </tr> ' ?> <?php } } echo ' </tr> </table></div><div class="clr"></div>'; break; Following is the main part of the code that updates the Ad form-- // update the ad and return the ad id $post_id = wp_update_post($update_ad); if($post_id) { // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) $meta_value= implode(',', $_POST['cp_checkbox_charley']); if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) $meta_value = implode(',', $_POST['cp_checkbox_help']); if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) $meta_value= implode(',', $_POST['cp_checkbox_hello']); //echo $meta_key . ' <--metakey <br/>' . $meta_value . ' <--metavalue<br/><br/>'; // for debugging update_post_meta($post_id, $meta_key, $meta_value); } $errmsg = '<div class="box-yellow"><b>' . __('Your ad has been successfully updated.','cp') . '</b> <a href="' . CP_DASHBOARD_URL . '">' . __('Return to my dashboard','cp') . '</a></div>'; } else { // the ad wasn't updated so throw an error $errmsg = '<div class="box-red"><b>' . __('There was an error trying to update your ad.','cp') . '</b></div>'; } return $errmsg; } Back on the Edit Ad page this is the Submit <p class="submit center"> <input type="button" class="btn_orange" onclick="window.location.href='<?php echo CP_DASHBOARD_URL ?>'" value="<?php _e('Cancel', 'cp')?>" /> <input type="submit" class="btn_orange" value="<?php _e('Update Ad »','cp') ?>" name="submit" /> I have a feeling what I need is just a couple of lines to detect no posted values and then... but if one checkbox array has 6 values in it and another checkbox array has only 3 values, for example, do I need to count each specific checkbox for number of values and then overwrite or will one function completely delete the previous array and its commas? I would really appreciate some expert assistance here! This question may sound very lame... ... But I have never able to know how to define a variable that I can use in different functions in a same file. There is no class structure just a PHP file with some functions. Is it possible to use some type of variable that can be share by all functions and that variable should not be a session variable . Something like: <?php $my_global_var; function A() { // use $my_global_var here } function B() { // use $my_global_var here and should retain the last value } ?> Something like in VB6.... Thanks Just wanted to know if $_Session was a global thing or does php require cookies setup?
I assumed that I could do something like this:
PAGE: A.php session_start(); $_Session['Cat'] = 'Meow'; // ----------------------- PAGE: B.php if (isset($_Session['Cat']) && !empty($_Session['Cat'])){ echo $_Session['Cat']; } OUTPUT: Meow // ----------------------- PAGE: C.php if (isset($_Session['Cat']) && !empty($_Session['Cat'])){ echo $_Session['Cat']; } OUTPUT: MeowI can't seem to get this to work. Page: Handler.inc // ========================================================= Session Log in / out public function logon($username, $password){ if ($username == "admin" && $password == "coffee"){ session_start(); $_SESSION['USER_STATUS'] = '1'; echo 'IN SESSION LOGIN HANDLER'; echo $_SESSION['UserLogged']; } } public function logout(){ $_SESSION['USER_STATUS'] = '0'; echo 'IN SESSION LOGOUT HANDLER'; session_destroy(); //session_unset(); }Page: index.php if (!isset($_SESSION['USER_STATUS']) && empty($_SESSION['USER_STATUS']) || $_SESSION['USER_STATUS'] == 0){ if (isset($_POST['username']) && !empty($_POST['username']) && isset($_POST['password']) && !empty($_POST['password'])){ $username = $_POST['username']; $password = $_POST['password']; echo $handler->logon($username, $password); } <LOGIN FORM CODE> }else{ if (isset($_SESSION['USER_STATUS']) && !empty($_SESSION['USER_STATUS']) || $_SESSION['USER_STATUS'] == 1){ echo 'Session name: '. $_SESSION['USER_STATUS']; } if (isset($_POST['btn_logout']) && !empty($_POST['btn_logout'])){ $handler->logout(); echo '<br />Logged out<br />'; } <LOGOUT FORM BUTTON CODE> }Could someone point me in the right direction please. It does not seem to hold its session. I have some variables that I have set with the global command but they don't seem to be working correctly. It's probably my order of operation but not sure. Here's the stripped down version of whats going on: locator() //functions function geoip() global $zip, $city, $areacode, $metrocode, $state, $country, $latitude, $longitude; function locator() geoip() use globals from geoip pass to- ad_display() function ad_display() does some work stat_tracking() function stat_tracking() access global $zip, $city, $areacode, $metrocode, $state, $country, $latitude, $longitude; The problem is once I call stat_tracking() and try to access the global variables, they are all empty. Just to clarify the chain of events is: page loads, calls locator(), locator() calls function geoip() fine then passes work to ad_display(), ad_display() calls stat_tracking(), stat_tracking() now tries to access the globals I made but all variables are blank if I echo them. Any ideas? It's a function=> Code: [Select] function _wp_call_all_hook($args) { global $wp_filter; //var_dump($wp_filter); //exit(); reset( $wp_filter['all'] ); do { foreach( (array) current($wp_filter['all']) as $the_ ) if ( !is_null($the_['function']) ) call_user_func_array($the_['function'], $args); } while ( next($wp_filter['all']) !== false ); } Why is $wp_filter variable declared as global ? Was $wp_filter assigned before ? |