You are not logged in.
I just discovered a problem with the site on hblack.net
On the previous server set up, the home page was displaying a random image in the background. For that I was using a script and was calling it with background: url('<?php include("ri.php");?>');. Now that includes are not accepted I tried using background: url(<?php echo file_get_contents('ri.php');?>); but again, nothing is parsed.
this is the php script
<?php $your_dirname="rando/";$your_alt_tag="hb"; // /**/ p. function displayAaPHPrandomImage($dirname, $alt){ $dirhandle = opendir($dirname); while (false !== ($file = readdir($dirhandle))) { if ($file != "." && $file != ".." && !@is_dir($file)) { $filelist[] = $file; } } closedir($dirhandle);if(sizeof($filelist) ==0) { echo "No file was found in the directory!"; exit; }srand((double)microtime()*1000000); $picnum = @rand(0, sizeof($filelist) - 1); $imageName=$dirname.$filelist[$picnum]; $imageSize = getimagesize($imageName);$result="$imageName"; return $result;} ?> <?=displayAaPHPrandomImage($your_dirname)?>
Can anyone point me as to what might be going wrong?
neme.org | neme-imca.org | hblack.net | LABS
Offline
Sorted :)
Note to self: Don’t use any third party scripts when a combination of native txp tags and a trusted txp plugin can do the job just as well and possibly in a safer way.
neme.org | neme-imca.org | hblack.net | LABS
Offline
colak wrote:
Now that
includes are not accepted
Are not accepted where? Includes are accepted, valid. If you are referring to previous mentions concerning rah_external_output, those where about non-local filesystem files, where actual content where transferred over internet.
file_get_contents
File_get_contents is a file function and just merely reads files. include on the other hand is for evaluating PHP source code. file_get_contents will not evaluate (i.e. execute) any code, it just reads files.
<?php […] ?>
Let’s start with the tags. Use of raw PHP is deprecated, and the support will be removed in the next release, Textpattern v4.5.0. Instead of those, please see and use <txp:php> tags when working with PHP block in page and form templates.
nothing is […] what might be going wrong?
Try to turn Debugging mode on. Potentially one the file paths could be incorrect (using absolute paths might not hurt), or you may not have rights to the directory.
As the random image script goes, you probably could minify it something much more smaller and put it into a single PHP in your page template. For example:
background: url('/rando/<txp:php>
$f = array_filter((array) glob(txpath.'/../rando/*.{png,jpg,gif}', GLOB_NOSORT|GLOB_BRACE), 'is_file');
echo $f ? basename($f[mt_rand(0, count($f)-1)]) : '';
</txp:php>');
Edit. glad you got it sorted. Seems you migrated to Textpattern’s own image management and <txp:images /> tag or similar :)
Last edited by Gocom (2012-05-08 08:34:51)
Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />
Offline
Gocom wrote:
Hi Jukka
Are not accepted where? Includes are accepted, valid. If you are referring to previous mentions concerning rah_external_output, those where about non-local filesystem files, where actual content where transferred over internet.
My new server at joyent does not like includes and it initially broke all my pages which were using the include function
File_get_contents is a file function and just merely reads files. include on the other hand is for evaluating PHP source code.
file_get_contentswill not evaluate (i.e. execute) any code, it just reads files.
It is nevertheless this code which solved my problems a few days ago
Edit. glad you got it sorted. Seems you migrated to Textpattern’s own image management and <txp:images /> tag or similar :)
Yes :) I used <txp:images limit="1" category="random_images" sort="rand()"><txp:image_url /></txp:images> and added body{background: url(<?php echo file_get_contents('path_to_ext_output/?rah_external_output=myextTxpTags');?>); and all was sorted.
Thanks soo much for your intervention nevertheless
neme.org | neme-imca.org | hblack.net | LABS
Offline
OK… :) There are still problems.
On forum.neme.org I have a little file which calls for rah_external_output.
I used to be able to get it by using <?php include($DOCUMENT_ROOT . "http://mysite.tld/?rah_external_output=bar"); ?> but not any more.
// does not work (the whole forum page goes white) <?php include($DOCUMENT_ROOT . "http://mysite.tld/?rah_external_output=bar"); ?>// same as above <?php include 'http://mysite.tld/?rah_external_output=bar'; ?>//same as above <?php include("http://mysite.tld/?rah_external_output=bar"); ?>// semi works as the forum page is rendering but the external output is not fetched <?php echo file_get_contents('http://mysite.tld/?rah_external_output=bar'); ?>
any advice would be appreciated
neme.org | neme-imca.org | hblack.net | LABS
Offline
Maybe I should clarify the difference between my old server up and the new one. In the old server the forum was residing inside the main domain. After Joyend’s advice, now the forum is working like an independent domain. The includes I was using in the previous setup were cross-domain (fetching content from our sites) except the forum as I mentioned earlier and everything was working wonderfully.
<?php echo file_get_contents('http://mysite.tld/?rah_external_output=bar'); ?> works fine for the txp sites but for the forum, it is not parsed.
Can anyone point me to the right direction on how I can display this txp content?
neme.org | neme-imca.org | hblack.net | LABS
Offline
Try using Curl
I had a similar problem a few years ago with get_file_contents and include, both of which had been turned off or something on the server and the admins told me to use Curl…. I did, and it worked.
Not sure on the technicalities though
Offline
Thanks tye
<?php
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, 'http://mysite.tld/?rah_external_output=bar');
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec ($curl);
curl_close ($curl);
?>
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mysite.tld/?rah_external_output=bar');
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$file = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $file !== false && $http == '200' ? $file : 'Error appeared. Sad face.';
?>
neither of which returned any results.
neme.org | neme-imca.org | hblack.net | LABS
Offline
[SOLVED]… I had an include in my rah page which I forgot to change.
neme.org | neme-imca.org | hblack.net | LABS
Offline