Page 1 of 1

Problem with php/html in linux

Posted: Fri Oct 21, 2011 7:54 am
by karlangas79
Hello,

I have an apache installation (ubuntu) that runs php just fine. The problem comes when i run this code:
index.php

Code: Select all

<?php
$machine = check_input($_POST['machine']);
$metric = check_input($_POST['metric']);
$interval1 = check_input($_POST['interval1']);
$interval2 = check_input($_POST['interval2']);
?>

<html>
<body>

Máquina: <?php echo $machine; ?><br />
Métrica: <?php echo $metric; ?><br />
Intervalos de tiempo: <?php echo $interval1; ?> <?php echo $interval1; ?><br />
<br />

</body>
</html>

<?
function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
It only shows the html code and ignores the php.
[text]Máquina:
Métrica:
Intervalos de tiempo: [/text]

Am I doing something wrong?

Thanks!

Re: Problem with php/html in linux

Posted: Fri Oct 21, 2011 7:56 am
by Celauran
Check the source of the HTML page in your browser. Is it displaying the PHP code? Sounds like PHP isn't installed or configured properly. What output, if any, does this produce?

Code: Select all

<?php echo phpinfo(); ?>

Re: Problem with php/html in linux

Posted: Tue Oct 25, 2011 4:07 am
by karlangas79
phpinfo shows:

[text]Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php5/apache2
Loaded Configuration File /etc/php5/apache2/php.ini
Scan this dir for additional .ini files /etc/php5/apache2/conf.d
Additional .ini files parsed /etc/php5/apache2/conf.d/gd.ini, /etc/php5/apache2/conf.d/mysql.ini, /etc/php5/apache2/conf.d/mysqli.ini, /etc/php5/apache2/conf.d/pdo.ini, /etc/php5/apache2/conf.d/pdo_mysql.ini, /etc/php5/apache2/conf.d/snmp.ini
PHP API 20090626
PHP Extension 20090626
Zend Extension 220090626
Zend Extension Build API220090626,NTS
PHP Extension Build API20090626,NTS
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
Zend Multibyte Support disabled
IPv6 Support enabled
Registered PHP Streams https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filters zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk[/text]

Re: Problem with php/html in linux

Posted: Tue Oct 25, 2011 5:23 am
by mikeashfield
I'm still a newbie, but does it have something to do with he fact that you're calling a funtion near the begining (check_input), but the code for the funtion isn't inside a PHP tag

Code: Select all

<?
function check_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
Shouldn't it be:

Code: Select all

<?php
function check_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
And you also seem to be asking the function to trim, stripslashes and htmlspecialchars the $data variable, but this does not have an initial value (unless you're not posting the whole code here?).

Re: Problem with php/html in linux

Posted: Tue Oct 25, 2011 5:44 am
by karlangas79
Hello,

Thanks for the answer, but it didn't work.

I'm posting the whole code here.

Greetings

Re: Problem with php/html in linux

Posted: Tue Oct 25, 2011 6:17 am
by mikeashfield
So where does $data get it's initial value from?

The first statement of your check_input() function is

Code: Select all

$data = trim($data);
but as far as I can see you're not giving the $data variable a value so it's got nothing to do, so it would return nothing which would return the output you're getting. :)

Re: Problem with php/html in linux

Posted: Tue Oct 25, 2011 6:38 am
by Celauran
Have you tried to var_dump($_POST)? There is no form on this page, so where are the values coming from?

Re: Problem with php/html in linux

Posted: Wed Oct 26, 2011 7:13 am
by karlangas79
You are right :oops: :oops:
I didn't have nothing asking for anything so hehe.

Thank you all!