Problem with php/html in linux

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
karlangas79
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:42 am

Problem with php/html in linux

Post 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!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem with php/html in linux

Post 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(); ?>
karlangas79
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:42 am

Re: Problem with php/html in linux

Post 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]
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: Problem with php/html in linux

Post 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?).
karlangas79
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:42 am

Re: Problem with php/html in linux

Post by karlangas79 »

Hello,

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

I'm posting the whole code here.

Greetings
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: Problem with php/html in linux

Post 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. :)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problem with php/html in linux

Post by Celauran »

Have you tried to var_dump($_POST)? There is no form on this page, so where are the values coming from?
karlangas79
Forum Newbie
Posts: 6
Joined: Fri Oct 21, 2011 7:42 am

Re: Problem with php/html in linux

Post by karlangas79 »

You are right :oops: :oops:
I didn't have nothing asking for anything so hehe.

Thank you all!
Post Reply