SimplePortal

Support => English Support => Topic started by: Xandar on May 15, 2009, 10:58:19 AM

Title: Custom PHP block not reading ini file
Post by: Xandar on May 15, 2009, 10:58:19 AM
In my custom PHP block, I put the following:

<?php include('rotator.php'); ?>

<?php showImage(); ?>


---

The information that is displayed when I go look at it is as follows:


Unable to read ini file.

This error actually shows up and takes over all blocks so that there is no display. http://www.hcvc.us is fine as a guest, but as soon as I log in (it's only administrator view currently), all of the home page blocks vanish and the php block is the only one that exists.

---

The rotator script information is located at http://www.alistapart.com/articles/betterrotator/.

---

Anyone have a suggestion?  The ini file is in the same directory and is chmod 666 (rw-rw-rw-).  Is there a different directory that should be used? 



Thank you,
 X

PS:

 I'm also open to other rotator code suggestions. What I'm trying to accomplish is an image with a link that can be used for affiliates or sponsors.
Title: Re: Custom PHP block not reading ini file
Post by: Eliana Tamerin on May 15, 2009, 12:40:00 PM
You do not need to include the opening and closing php tags in the php box, these are prepended and appended by the code automatically. You should use this code instead:

Code: [Select]
include('rotator.php');

showImage();
Title: Re: Custom PHP block not reading ini file
Post by: Xandar on May 15, 2009, 01:25:14 PM
Thank you. I have made that change, however it has not fixed the issue.

I still only see one block that has the Name of "Test" and the contents of "Unable to read ini file".  All other blocks are missing from the main portal page.
Title: Re: Custom PHP block not reading ini file
Post by: ccbtimewiz on May 16, 2009, 01:23:34 AM
What version of PHP are you using?
Title: Re: Custom PHP block not reading ini file
Post by: [SiNaN] on May 16, 2009, 03:17:12 AM
Try using relative path to the file for the include. Like:

Code: [Select]
include('home/www/my_scripts/rotator.php');
If it is in your forum root, you can use:

Code: [Select]
global $boarddir;

include($boarddir . '/rotator.php');
Title: Re: Custom PHP block not reading ini file
Post by: Xandar on May 16, 2009, 10:02:27 AM
PHP Version 5.2.8-pl2-gentoo

The relative path didn't work nor did global. 

I'll keep trying to figure it out. The weird thing is you pull it out of SimplePortal and it works fine, but as soon as you add it into the Custom php block, it returns the can not read the .ini file.

I've tried relative path for the ini file too.

Based on the php code, the error is driven by:

    # read the config file into an array or die trying
    $images = @parse_ini_file($ini_file,true);
    if (! $images) {
      die('Unable to read ini file.');

- X
Title: Re: Custom PHP block not reading ini file
Post by: [SiNaN] on May 16, 2009, 10:08:42 AM
If it is your script, that gives the error; than I can't see why this would be related to SimplePortal itself. Would you post all your codes here?
Title: Re: Custom PHP block not reading ini file
Post by: Xandar on May 16, 2009, 10:13:08 AM
The code (http://www.alistapart.com/articles/betterrotator/) is included below.  The only reason I'm saying that it has to do with the portal is because http://www.hcvc.us/test.php works (ignore the images, they should be broken right now -- the links refresh as I was expecting in SimplePortal). 

All that I have in test.php is:



Code: [Select]
  <?php include('rotator.php'); ?>

  <?php showImage(); ?>








rotater.php

Code: [Select]
<?php

/*

  Author: Dan Benjamin - http://hivelogic.com/

  Copyright (c) 2004 Automatic, Ltd. All Rights Reserved.

  THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF 
  ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY 
  IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR 
  PURPOSE OR NONINFRINGEMENT.  

  IN NO EVENT SHALL DAN BENJAMIN, A LIST APART, OR AUTOMATIC, LTD. BE LIABLE
  FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR
  LOST PROFITS ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER
  ARISING, INCLUDING NEGLIGENCE), EVEN IF DAN BENJAMIN, A LIST APART, OR
  AUTOMATIC, LTD. IS AWARE OF THE POSSIBILITY OF SUCH DAMAGES.

*/



  # file containg your image descriptions

  
$IMG_CONFIG_FILE 'images.ini';



  
# You shouldn't need to change anything below this point

  
function showImage$ini=null ) {
    global 
$IMG_CONFIG_FILE;
    
# if no custom ini file has been specified, use the default
    
$ini_file $ini $ini $IMG_CONFIG_FILE;
    
# read the config file into an array or die trying
    
$images = @parse_ini_file($ini_file,true);
    if (! 
$images) {
      die(
'Unable to read ini file.');
    }
    
# pick a random image from the parsed config file
    
$img array_rand($images);
    
# get the selected image's css id if one exists
    
$id $images[$img]['id'] ?
      
sprintf' id="%s" '$images[$img]['id'] ) :
      
'';
    
# get the selected image's css class if one exists
    
$class $images[$img]['class'] ?
      
sprintf' class="%s" '$images[$img]['class'] ) :
      
'';
    
# get selected image's dimensions
    
$size = @getimagesize$images[$img]['src'] );
    
# if an url was specified, output the opening A HREF tag
    
if ( $images[$img]['url'] ) {
      
printf(
        
'<a href="%s" title="%s">',
        
$images[$img]['url'],
        
$images[$img]['title']
      );
    }
    
# output the IMG tag
    
printf(
      
'<img src="%s" alt="%s" %s %s%s/>',
      
$images[$img]['src'],
      
$images[$img]['alt'],
      
$size[3],
      
$id,
      
$class
    
);
    
# if an url was specified, output the closing A HREF tag
    
if ( $images[$img]['url'] ) {
      echo(
'</a>');
    }
  }


?>


Image.ini file
Code: [Select]
[TheDonald]
src   = img/trump.jpg
alt   = Donand Trump
url   = http://trump.com/
title = The Donald

[Tony]
src   = img/tony.jpg
alt   = Tony
url   = http://hbo.com/
title = The Sopranos

[Bond]
src   = img/bond.jpg
alt   = James Bond
url   = http://jamesbond.com/
title = James Bond Website

[Doctor]
src   = img/drwho.jpg
alt   = Tom Baker
url   = http://www.bbc.co.uk/cult/doctorwho/
title = Dr. Who

[FightClub]
src   = img/edsoap.jpg
alt   = I Am Jack's Soap
url   = http://www.imdb.com/title/tt0137523/
title = Fight Club

[Kubrick]
src   = img/kubrick.jpg
alt   = Stanley
url   = http://www.kubrick.com/
title = Kubrick

[Serling]
src   = img/rod.jpg
alt   = Rod
url   = http://www.scifi.com/twilightzone/
title = Rod Serling
Title: Re: Custom PHP block not reading ini file
Post by: [SiNaN] on May 17, 2009, 04:24:48 AM
I'm not sure about the reason but $IMG_CONFIG_FILE becomes NULL in showImage() function. This will work:

Code: [Select]
require('rotator.php');
showImage('images.ini');
Title: Re: Custom PHP block not reading ini file
Post by: Xandar on May 18, 2009, 09:23:48 AM
Awesome! Thank you. That fixes it. I really appreciate the help.

- X
Title: Re: Custom PHP block not reading ini file
Post by: cthunders on May 31, 2009, 10:27:50 AM
I was wondering exactly where you added the:

require('rotator.php');
showImage('images.ini');

Title: Re: Custom PHP block not reading ini file
Post by: Eliana Tamerin on May 31, 2009, 10:51:33 AM
In a php block.
Title: Re: Custom PHP block not reading ini file
Post by: jjwinc on September 21, 2009, 06:54:50 PM
I'm not sure about the reason but $IMG_CONFIG_FILE becomes NULL in showImage() function. This will work:

Code: [Select]
require('rotator.php');
showImage('images.ini');


Old thread, but same issue.  I am trying to use the same code on my site BowlThis.com (http://www.bowlthis.com/board) and it works fine as long as I'm previewing the block.  The minute I try to save it, SP returns an error stating Syntax Error in Block Code.  Please check the code.  Unfortunately, I don't see any hints as to where the error may originate.

Any suggestions on where I could start?  Also, of course, I have Disable PHP Validation unchecked on my site.  Not feeling too safe about bypassing the validation until I can try to ferret out what's going on.
SimplePortal 2.3.8 © 2008-2024, SimplePortal