3

The error:

PHP Notice:  Undefined variable: exec in readings.php on line 3
PHP Fatal error:  Function name must be a string in readings.php on line 3

The code:

<?php
    require('smarty_config.php');
    exec('reading_fetcher.py',$output,$ret_code);
    $smarty->assign('readings',$output);
    $smarty->display('readings.tpl');
?>

I was asked for the code of reading_fetcher.py so here it is:

#!/usr/bin/env python
import urllib2, re

response = urllib2.urlopen('http://it.ctsfw.edu/inc/nc_scriptureframe.php')

html = response.read()

def remove_html_tags(data):
    p = re.compile(r'<.*?>')
    return p.sub(' ', data)

import re
import htmlentitydefs

def convertentity(m):
    if m.group(1)=='#':
        try:
            return unichr(int(m.group(2)))
        except ValueError:
            return '&#%s;' % m.group(2)
        try:
            return htmlentitydefs.entitydefs[m.group(2)]
        except KeyError:
            return '&%s;' % m.group(2)

def converthtml(s):
    return re.sub(r'&(#?)(.+?);',convertentity,s)

readings =  converthtml(str(remove_html_tags(html)))
readings.replace("&nbsp;", " ")

print readings[699:]

I already looked here, here and here. Two of those errors are an extra "$". I don't see an extra "$" on my function name. The third error is having "()" instead of "[]". So I tried replacing them. That didn't work. What else might I try?

20
  • 1
    Does function_exists('exec') return true? (It pretty surely does, but who knows?) Commented Feb 1, 2011 at 5:26
  • @zneak It should do, otherwise he would of got Fatal error: Call to undefined function. (I think.) Commented Feb 1, 2011 at 5:29
  • Do you need to create $output = array() first? Commented Feb 1, 2011 at 5:32
  • 2
    What happens if you comment away smarty_config.php? Do you get a different error? If so, probably that the problem is in the file. Commented Feb 1, 2011 at 5:34
  • 1
    @zneak: Commenting out smarty_config.php has no effect. The error remains the same. Commented Feb 1, 2011 at 5:53

1 Answer 1

1

exec() could have been disabled by the server admin. In this scenario a call to exec would print an E_NOTICE and a E_WARNING. So if you disabled warning printing you can only see the E_NOTICE and potentially miss the more interesting warning saying "exec has been disabled for security reason".

You can add this line to your code

error_reporting(E_ALL);

so that you can have a more verbose execution.

Sign up to request clarification or add additional context in comments.

2 Comments

Good hint, it has most likely been disabled. @OP: If you have access to php.ini, look for disable_functions, this is where the sysop can disable php functions.
@acme: disable_functions is set to nothing. @David: Error reporting is already set to E_ALL in php.ini so adding error_reporting(E_ALL); to my code did nothing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.