WordPress.org

Forums

PHP code stopped rendering properly (7 posts)

  1. BobWP
    Member
    Posted 2 years ago #

    A page that been rendering properly, but now isn't. When I place the source in a file outside of WP, it renders properly.

    -- SOURCE:

    Thanks.
    
    <?php
    
    $ip = getenv(REMOTE_ADDR);
    $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    $ipAddress = gethostbyname($_SERVER['SERVER_NAME']);
    
    print ('<font size="5" COLOR="#DC143C">Your IP address is: '.$ip.'.<p>Your host name is: '.$hostname.'.<p></font>');
    
    ?>

    --OUTPUT:

    Thanks

    $ip = getenv(REMOTE_ADDR);
    $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
    $ipAddress = gethostbyname($_SERVER['SERVER_NAME']);

    print ('Your IP address is: ‘.$ip.’.

    Your host name is: ‘.$hostname.’.

    ‘);

    ?>

  2. linux4me2
    Member
    Posted 2 years ago #

    Your PHP looks good and as you say, it works outside of WordPress, so that's probably not the issue.

    When you say "a page" are you saying you had the PHP directly in the source code for a page in WordPress (which won't work by itself), or did you have it in a custom template that a page was based on?

    Did you change anything between the time it was rendering properly and when I quit rendering?

    Are you getting any PHP errors?

  3. BobWP
    Member
    Posted 2 years ago #

    The code in a Page in WP itself. It worked before, and I'm nearly certain I hadn't modified it .

    I get no PHP error in a browser; do you mean a PHP error in a WP or server log?

    I wasn't aware PHP doesn't work in WP pages.

    Thanks much for your reply.

  4. linux4me2
    Member
    Posted 2 years ago #

    As far as I know, you can't run PHP directly by putting it in the editor of a Page, you would need to create a custom template, put the code in it, then set the Page to that template. It's actually a security feature; you wouldn't want any contributor or editor to be able to execute PHP on your site.

  5. BobWP
    Member
    Posted 2 years ago #

    If I can't use PHP in a default WP Page, I'll have to rethink my strategy. My pages don't allow commenting, but I could understand why WP might disallow PHP code in regular Pages, if doing so is a potential security opening.

  6. BobWP
    Member
    Posted 2 years ago #

    I was reviewing my WP maintenance notes, and discovered I had previously installed a plugin: "Exec-PHP". I apparently had deleted it at some point. I reinstalled, and all is well now. Sorry for not catching that earlier.

  7. linux4me2
    Member
    Posted 2 years ago #

    That would do it. :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags