I started a thread elsewhere, but realized I should put this here. http://drupal.org/node/1783732
I have noticed that when I am not an authenticated user, the php code is not being executed. To test that this is the case, I am writing to a temp file. As an authenticated user, the file is written to... When I view the site without being logged in, the file is not written to.
Any thoughts?
Here is my code:
// set node id
$nid = $row->field_ss_slide;
// create an array to store node ids
$nids = array();
// populate node ids
$nids[] = $data->nid;
// open a temp file to test if code is being executed
$fh=fopen('/tmp/anon','a');
fwrite($fh, "works");
fclose($fh);
// get list of image files from the database
$result = db_query("SELECT field_ss_slide_fid FROM {field_data_field_ss_slide} WHERE entity_id = :nid", array(':nid' => $nid));
// loop through the list
foreach($result as $record){
// grab uri of individual image
$file = db_query("SELECT uri FROM {file_managed} WHERE fid= :fid", array(':fid' => $record->field_ss_slide_fid ));
$x=0;
// store uris
foreach($file as $filename){
$uri = $filename->uri;
$uris[$nid][] = $filename->uri;
$x++;
}
}
$cnt = count($uris[$nid]);
$num = rand(0, $cnt-1);
$uri = $uris[$nid][$num];
$file = file_create_url($uri);
Comments
Comment #1
fender177 commentedDrupal was caching the view for anonymous users. I added the following code to my PHP to prevent caching: