PHP5 not displaying echo commands

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keef
Forum Newbie
Posts: 6
Joined: Sun Aug 28, 2005 2:04 pm

PHP5 not displaying echo commands

Post by keef »

Hello,

I have script that takes a host supplied by the viewer and pings it. This script works fine on two servers I have running PHP4, but will not work at all on another server that is running PHP5. I Have checked all the conf files (php.ini, httpd.conf etc.. etc...). I have installed all the packages for updates for PHP5.

THe code executes, gives no errors, but will not display some of the results from the echo commands. Some echo commands work others do not.

THe problem box is running Fedora core 4, and the code works on other fedora boxes, and centOS.

If anyone has any suggestions on how to get PHP5 to work, or on how to revert back to PHP4 please help.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

What level of error reporting are you using? This sounds like you may not be getting the full error outputs.

Perhaps you could post an example extract of code that isn't working :)
keef
Forum Newbie
Posts: 6
Joined: Sun Aug 28, 2005 2:04 pm

Post by keef »

Here is the code (which works fine on all kinds of other servers just not my new Fedora Core 4 box running php5)




Code: Select all

<?php
 ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL);

        // Address error handling.

        ini_set('display_errors', 1);
        error_reporting(E_ALL ^ E_NOTICE);

        // Obtain POST data.

        $ping_ip_addr = $_POST['ping_ip_addr']; // input
        $ping_count   = $_POST['ping_count'];   // select

        // Remove any slashes if Magic Quotes GPC is enabled.

        if (get_magic_quotes_gpc())
        {
                $ping_ip_addr = stripslashes($ping_ip_addr);
        }

        // Create arrays.

        $ping_count_array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25); // Ping count

?>


<head>
<title>Ping</title>
<style type="text/css">

body
{
        margin: 0;
        padding: 10px;
        background-color: #ffffff;
}

div.output
{
        margin: 0;
        padding: 10px;
        background-color: #eeeeee;
        border-style: solid;
        border-width: 1px;
        border-color: #000000;
}

</style>
</head>

<body>
<h1>Ping</h1>
<a href="show.php">back to show</a><br>
<a href="noc1.html">back to main</a>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><label for="ping_ip_addr">IP address:</label><br />
<input name="ping_ip_addr" id="ping_ip_addr" type="text" value="<?php echo $_POST['submit'] == 'Ping' ? htmlentities($ping_ip_addr, ENT_QUOTES) : $_SERVER['REMOTE_ADDR'];; ?>" size="40" maxlength="15" /></p>
<p><label for="ping_count">Ping count:</label><br />
<select name="ping_count" id="ping_count">
<?php

        foreach ($ping_count_array as $ping_count_item)
        {
                echo '<option' . ($ping_count == $ping_count_item ? ' selected="selected"' : '') . '>' . $ping_count_item . '</option>' . "\n";
        }

?>
</select></p>
<p><input type="submit" name="submit" value="Ping" /></p>
</form>
<p>Ping may take a while, please be patient.</p>
<?php

        if ($_POST['submit'] == 'Ping') // Form has been submitted.
        {
                echo '<div class="output">' . "\n";

                /**************************************************************************/

                // Check for spoofed form submission.

                $illegal = FALSE;

                if (strlen($ping_ip_addr) > 15)
                {
                        $illegal = TRUE;
                }

                if (!in_array($ping_count, $ping_count_array))
                {
                        $illegal = TRUE;
                }

                /**************************************************************************/

                if (!$illegal) // Form submission was not spoofed.
                {
                        if (ereg('^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$', $ping_ip_addr)) // Acquired data contains no problems.
                        {
                                // Display result.

                                echo '<pre>' . "\n" .
                                'ping  ' . $ping_count . ' ' . $ping_ip_addr . "\n\n";

                                system('ping  ' . $ping_count . ' ' . $ping_ip_addr); // Ping IP address.

                                echo '</pre>' . "\n" .
                                '<p>Ping complete.</p>' . "\n";
                        }
                        else // Acquired data contains problems!
                        {
                                echo '<p>Please enter a valid IP address.</p>' . "\n";
                        }
                }
                else // Form submission was spoofed!
                {
                        echo '<p>An illegal operation was encountered.</p>' . "\n";
                }

                echo '</div>' . "\n";
        }

?>
</body>

</html>



What is the best way to turn on error reporting???? I turned it on in the php.ini file, and I checked all the error logs.

No errors are being generated that I can find.


Thanks SO MUCH


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Setting E_ALL for error_reporting and On for display_errors in php.ini is often a start. (Did you remember to restart the Apache?)

Since you're not looking at the return values from ping, could it be that PHP is failing to run it? Which echos work, which don't?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

In your code

error_reporting(E_ALL ^ E_NOTICE);

That's disabling Notices.... not good.

error_reporting(E_ALL);

Hopefully we'll see some errors now.

I already see a double semi-colon in your first <input...> ;)
keef
Forum Newbie
Posts: 6
Joined: Sun Aug 28, 2005 2:04 pm

Post by keef »

Thanks I will try that now and see what happens.
keef
Forum Newbie
Posts: 6
Joined: Sun Aug 28, 2005 2:04 pm

Post by keef »

Well I am at work now and I can't get back into my home network. I had to tighten my firewall because some jerk is running a brute force against one of my servers. So I will try your suggestions when I get home.

Thanks in advance for you help, I worked on this problem for hours over the weekend. I am trying to develop a web base suite of networking tools for our NOC, and I am almost done.

Also would you know of how to install PHP4 with PHP5? Or how to change back to PHP4? After all the issues I am having with PHP5 I am not so sure I want to keep running it.

Thanks again.
keef
Forum Newbie
Posts: 6
Joined: Sun Aug 28, 2005 2:04 pm

Post by keef »

Here is the section of code that is not working.

Everything else works fine:



echo '<pre>' . "\n" .
'ping ' . $ping_count . ' ' . $ping_ip_addr . "\n\n";

system('ping ' . $ping_count . ' ' . $ping_ip_addr); // Ping IP address.

echo '</pre>' . "\n" .
'<p>Ping complete.</p>' . "\n";



Thanks
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

Is there some condition (if) prior to echoing? Have you checked this http://fi.php.net/manual/en/features.sa ... e-exec-dir ?
keef
Forum Newbie
Posts: 6
Joined: Sun Aug 28, 2005 2:04 pm

Post by keef »

I do beleive safe mode is off. I checked the php.ini, but then I removed php5 and tried to reinstall php4. I got php4 installed, but I couldn't get it to work with apache. So I reinstalled php5 and got everything back to how I had it before. However I didn't check the php.ini file after reconfiguring... So I bet it went back to defaults.... I will try that thanks!!!!!!!!!!
Post Reply