How to get session user id in custome php file I want user session id in my custom ajax file named "ajax_page.php" below is code that i have placed in that file but i am not able to get object array of $user that i'hv defined as Global $user.             &lt;?php                 define('DRUPAL_ROOT', 'C:/xampp/htdocs/taconsultant/');                 require_once(DRUPAL_ROOT.'includes/bootstrap.inc');                 require_once (DRUPAL_ROOT . 'includes/common.inc');                 require_once (DRUPAL_ROOT . 'includes/module.inc');                 require_once (DRUPAL_ROOT . 'includes/unicode.inc');                 require_once (DRUPAL_ROOT . 'includes/file.inc');                 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);                 drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);                  global $user;                  $uid = $user-&gt;uid;    if($_REQUEST['type'] &amp;&amp; $_REQUEST['type'] == 'buy_course'){           $cid = $_REQUEST['cid'];          $course = taxonomy_term_load($cid);           echo "&lt;pre&gt;";           print_r($user);           exit;          $log = db_insert('tbl_user_log')                 -&gt;fields(array(                         'uid' =&gt; $uid,                         'title'=&gt;$course-&gt;name,                         'points'=&gt;$course-&gt;field_payment_amount['und'][0]['value'],                         'type'=&gt;'-',                          'date' =&gt; date('Y-m-d'),                         ))-&gt;execute();      }          ?&gt;  The output i got in console after print_r($user) is   &lt;?php       &lt;pre&gt;stdClass Object          (             [uid] =&gt; 0             [hostname] =&gt; ::1             [roles] =&gt; Array                 (                     [1] =&gt; anonymous user                 )              [cache] =&gt; 0         )  ?&gt;
Properly bootstrap drupal for standalone PHP file? This is what I have right now:  &lt;?php     define('DRUPAL_ROOT', '/var/www/clients/client1/web15/web');     include_once(DRUPAL_ROOT . '/includes/bootstrap.inc');     drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); //  drupal_flush_all_caches();        $users = views_get_view_result('userlist', 'uid_list');     $i = 0;     foreach ($users as $user) {         $filename = 'sites/default/files/generated_pdfs/individual_pdf_report_' . $user-&gt;uid . '.pdf';         generate_employee_pdf($user-&gt;uid, $filename);         error_log('Generated ' . $filepath);         $i++;     }     // create object     $zip = new ZipArchive();     // open archive     if ($zip-&gt;open("sites/default/files/generated_zips/individual-reports.zip", ZIPARCHIVE::CREATE) !== TRUE) {         die ("Could not open archive");     }     // initialize an iterator     // pass it the directory to be processed     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("sites/default/files/generated_pdfs/"));     // iterate over the directory     // add each file found to the archive     foreach ($iterator as $key=&gt;$value) {         $zip-&gt;addFile(realpath($key), $value-&gt;getFilename()) or die ("ERROR: Could not add file: $key");     }     // close and save archive     $zip-&gt;close(); ?&gt;   I'm getting a bunch of errors from the above when run standalone. Works fine in my module. Some of the errors are:  Warning: Invalid argument supplied for foreach() in drupal_depth_first_search() (line 56 of /var/www/clients/client1/web15/web/includes/graph.inc). Warning: Invalid argument supplied for foreach() in _module_build_dependencies() (line 229 of /var/www/clients/client1/web15/web/includes/module.inc). Warning: include_once(sites/all/modules/views_bulk_operations/actions/archive.action.inc): failed to open stream: No such file or directory in views_bulk_operations_load_action_includes() (line 56 of /var/www/clients/client1/web15/web/sites/all/modules/views_bulk_operations/views_bulk_operations.module).
Switching between virtual console and GUI How to switch between virtual console and GUI in Ubuntu? I wanted to see what key functions would allow me to switch between the two. Regular Expression to split on spaces unless in quotes I would like to use the .Net Regex.Split method to split this input string into an array. It must split on whitespace unless it is enclosed in a quote.  Input:  Here is "my string"&nbsp;&nbsp;&nbsp;&nbsp;it has "six&nbsp;&nbsp;matches"  Expected output:   Here is my string it has six&nbsp;&nbsp;matches   What pattern do I need? Also do I need to specify any RegexOptions? Why is Leia okay with being tracked to Yavin? In A New Hope, after Han and Luke fight off the TIE Fighters while escaping from the Death Star, these exchanges happen:             INT. DEATH STAR - CONTROL ROOM             Darth Vader strides into the control room, where Tarkin is             watching the huge view screen. A sea of stars is before him.                                   TARKIN                      Are they away?                                   VADER                      They have just made the jump into                       hyperspace.                                   TARKIN                      You're sure the homing beacon is                       secure aboard their ship? I'm taking                       an awful risk, Vader. This had better                       work.             INT. MILLENNIUM FALCON - COCKPIT             Han, removes his gloves and smiling, is at the controls of             the ship. Chewie moves into the aft section to check the             damage. Leia is seated near Han.                                   HAN                      Not a bad bit of rescuing, huh? You                       know, sometimes I even amaze myself.                                   LEIA                      That doesn't sound too hard. Besides,                       they let us go. It's the only                       explanation for the ease of our                       escape.                                   HAN                      Easy... you call that easy?                                   LEIA                      They're tracking us!                                   HAN                      Not this ship, sister.             Frustrated, Leia shakes her head.                                   LEIA                      At least the information in Artoo is                       still intact.                                   HAN                      What's so important? What's he                       carrying?                                   LEIA                      The technical readouts of that battle                       station. I only hope that when the                       data is analyzed, a weakness can be                       found. It's not over yet!   Leia doesn't even know if there is a weakness, let alone whether they'll find one. If she (correctly) realizes that they're being tracked, why doesn't she suggest that the Millennium Falcon go somewhere besides Yavin 4 instead of just frustratedly shaking her head? I know the plans , but it seems unlikely that continuing to fly to the secret Rebel base in the ship she's certain is being tracked is the only option. They are already in hyperspace when this conversation happens, but they apparently have time to talk for a little while after, so presumably they'd have time to stop and reroute. A reward becomes a penalty if I am working to build a reinforcement agent with DQN. The agent would be able to place buy and sell orders for a day trading purpose. I am facing a little problem with that project. The question is "how to tell the agent to maximize the profit and avoid the transaction where the profit is less than 100$".  I want to maximize the profit inside a trading day and avoid to place the pair (limit buy order, limit sell order) if the profit on that transaction is less than 100$. The idea here is to avoid the little noisy movements. Instead, I prefer long beautiful profitable movements. Be aware that I thought using the "Profit &amp; Loss" as the reward.  "I want the minimal profit per transaction to be 100$" ==> It seems this is not something that is enforceable. I can train the agent to maximize profit per transaction, but how that profit is cannot be ensured.  At the beginning, I wanted to tell the agent, if the profit of a transaction is 50 dollars, I will remove 100 dollars, then It becomes a penalty of 50 dollars for the agent. I thought it was a great way to tell the agent to not place a limit buy order if you are not sure it will give us a minimal profit of 100$. It seems that all I would be doing there is simply shifting the value of the reward. The agent only cares about maximizing the sum of rewards and not taking care of individual transactions.   How to tell the agent to maximize the profit and avoid the transaction where the profit is less than 100$? With that strategy, what guarantee that the agent will never make a buy/sell decision that results in less than 100 dollars profit? Does the sum of reward - # transaction * 100 can be a solution? I would like to insert the below mathematical symbol, it looks like a big Delta but different. Is there command to obtain a similar shape? 64 bit enum in C++? Is there a way to have a 64 bit enum in C++?  Whilst refactoring some code I came across bunch of #defines which would be better as an enum, but being greater than 32 bit causes the compiler to error.  For some reason I thought the following might work:  enum MY_ENUM : unsigned __int64   {       LARGE_VALUE = 0x1000000000000000,   }; I often find  syntax very helpful, e.g. process substitution like in diff &lt;(sort file1) &lt;(sort file2).  Is it possible to use such Bash commands in a Makefile? I'm thinking of something like this:  file-differences:     diff &lt;(sort file1) &lt;(sort file2) &gt; $@   In my GNU Make 3.80 this will give an error since it uses the shell instead of bash to execute the commands. I have rigged up a notch filter from . See below: -     Its the first circuit. Now I am trying to calculate its transfer function. I have calculated two equations, but I need the third one:   (Vin-V2)/(1/SC1) = V2/R3 (Vin-V1)/R1 = (V1-Vo)/(R2+(1/SC2))   V1 and V2 are the potentials at the input of the op-Amp. Better explanation of the common general relativity illustration (stretched sheet of fabric) $n!+1$ being a perfect square One observes that  \begin{equation*} 4!+1 =25=5^{2},~5!+1=121=11^{2}  \end{equation*} is a perfect square. Similarly for $n=7$ also we see that $n!+1$ is a perfect square. So one can ask the truth of this question:   Is $n!+1$ a perfect square for infinitely many $n$? If yes, then how to prove. Where is Ubuntu terminal located? I am trying to add terminal as external tool to compile javascript with node.js. I am following this  which is based on windows , and i am stuck at figuring out location of terminal application.  Where is the terminal located in Ubuntu? remove numbers from filenames in Mac OS X I have a directory full of files with names in this format (with numbers as the start of each filename):  102_file.txt 104_list.txt 242_another_file.txt   I would like to rename them as follows (i.e. removing the numbers):  file.txt list.txt another_file.txt   Can anyone suggest a way to do this (presumably from the terminal)? Finding the number of analytic functions which vanish only on a given set. Let $S = \{0\}\cup \{\frac{1}{4n+7} : n =1,2\ldots\}$. How to find the number of analytic functions which vanish only on $S$?  Options are   a: $\infty$  b: $0$  c: $1$  d: $2$ Why is my ethernet interface called enp0s10 instead of eth0? When I run ifconfig -a, I only get lo and enp0s10 interfaces, not the classical eth0  What does enp0s10 mean? Why is there no eth0? Clearing NSUserDefaults I'm using +[NSUserDefaults standardUserDefaults] to store application settings. This consists of roughly a dozen string values. Is it possible to delete these values permanently instead of just setting them to a default value? How can I move or force a program installation to another location, even when unsupported? I have an SSD as my main Windows drive, with a 640GB 2.5" HDD, partitioned to store programs and user settings, and also to act as backup (it's the only thing I had lying around at the time of building my PC).  The problem is that whenever I install a program, it installs to C:\Program Files [(x86 for the 32 bit programs]\, although I have changed the environment variables. This wouldn't normally be an issue, however every installation program points its shortcut to my 640GB HDD.  The root layout of both drives:   To clarify:   Program files get installed to C:\ Program shortcuts are always pointed to Z:\, my 640GB HDD   Modifying the relevant environment variables doesn't do anything, I looked at , but however it only talks about modifying the registry and environment variables, which I have already done so.  I install to the Z:\ drive if the installation program lets me change the installation path, but however the installation programs sometimes don't let me change this.  Is there a way that I can force every program to install to the relevant location on Z:\, but at the same time move any programs currently installed to the new location? Perhaps I'm missing something here?  My target is to have every program installed on Z:/, with only the core Windows operating system on C:/.  Found ; would it be appropriate to use in my case? I would be able to move the entire Program Files (and its x86 version) to Z:\, without impacting on the performance.* Read MIME data using PHP What is the most efficient way to write the old-school:  StringBuilder sb = new StringBuilder(); if (strings.Count &gt; 0) {     foreach (string s in strings)     {         sb.Append(s + ", ");     }     sb.Remove(sb.Length - 2, 2); } return sb.ToString();   ...in LINQ? Getting full JS autocompletion under Sublime Text How to write permutations as product of disjoint cycles and transpositions