LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2018, 09:10 AM   #1
stockton
Member
 
Registered: Jan 2006
Location: Midrand, Gauteng, South Africa
Distribution: Raspbian, Mint 13, Slackware 14, Debian & Ubuntu
Posts: 105

Rep: Reputation: 2
php include failing


I have the following HTML
Code:
<!DOCTYPE HTML>
<html>
<head>
<title>Solar System</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta http-equiv="expires" content="Mon, 22 Jul 2000 11:12:01 GMT">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-d
ensitydpi=device-dpi" />
<link href="css/mobile.css" rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" />
<link href="css/index.css" rel="stylesheet" type="text/css" media="only screen and (min-device-width: 480px)" />
</head>
<body>
<?php echo getcwd(); ?>	
<?php require ('./LastLine.php'); ?>
<center>
<div id="loadingNode"></div>
</center>
</body>
</html>
and I wish to include the following php script into it
Code:
<?php
    $filename = "/media/pi/MyPassport/Axpert/solar.log";       // file to read
    $max_len = 110 + 1;             // define the max length of the line to read
    $buff; // [$max_len + 1];             // define the buffer and allocate the length

    if (($fd = fopen($filename, "rb")) != NULL)
        {
        fseek($fd, -$max_len, SEEK_END);            // set pointer to the end of file minus the length you need.
                                                  //     Presumably there can be more than one new line caracter
        $buff = fread($fd, $max_len-1);            // read the contents of the file starting from where fseek() positioned us
        fclose($fd);                               // close the file
        }
    else
        printf("%s %d FileOpen error\n",__FILE__, __LINE__);
    $last_newline = strstr($buff, 'IGS ');
    sscanf($last_newline, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", $command, $voltage_grid, $freq_grid, $voltage_out, $freq_out, $load_va, $load_watt, $load_percent, $voltage_bus, $voltage_batt, $batt_charge_current, $batt_capacity, $temp_heatsink, $pv1, $pv2, $scc, $batt_discharge_current);
        printf("\tAC Grid voltage: %s\n", $voltage_grid);
        printf("\tAC Grid frequency: %s\n", $freq_grid);
        printf("\tAC out voltage: %s\n", $voltage_out);
        printf("\tAC out frequency: %s\n", $freq_out);
        printf("\tLoad [percent]: %s%%\n", $load_percent);
        printf("\tLoad [W]: %s\n", $load_watt);
        printf("\tLoad [VA]: %s\n", $load_va);
        printf("\tBus voltage: %s\n", $voltage_bus);
        printf("\tHeatsink temperature: %s\n", $temp_heatsink);
        printf("\tBattery capacity [percent]: %s%%\n", $batt_capacity);
        printf("\tBattery voltage: %s\n", $voltage_batt);
        printf("\tBattery charge current [A]: %s\n", $batt_charge_current);
        printf("\tBattery discharge current [A]: %s\n", $batt_discharge_current);
        printf("\tPV Input Current [A]: %s\n", $pv1);
        printf("\tPV Input Voltage [V]: %.s\n", $pv2);
?>
The php works fine from the command line and if I disable the include in the HTML it also works.
A look at apache2 configuration appears to be allowing me to use php, so please tell me what I forgot?
 
Old 08-14-2018, 10:05 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,714

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Look at the /var/log/apache2/error.log for errors that should help you troubleshoot the problem. The web server typically runs as the apache2 user and may not have permissions to access the log file.
 
Old 08-14-2018, 01:30 PM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by stockton View Post
I wish to include the following php script into it
is that the "./Lastline.php" script? is it indeed in the same directory?
what output do you get from getcwd?

Quote:
The php works fine from the command line and if I disable the include in the HTML it also works.
it's a require, not an include. there are differences.

and what exactly do you see with the require?

Quote:
A look at apache2 configuration appears to be allowing me to use php, so please tell me what I forgot?
do other php scripts work?
 
Old 08-14-2018, 11:22 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@OP: You forgot to quote the error message.
 
Old 08-15-2018, 01:05 AM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,266
Blog Entries: 24

Rep: Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195Reputation: 4195
It is not clear to me what you mean when you say that it works if you disable the include. And you have not told us what you see when it "does not work" - any error messages, visible code or a blank page?

As others have asked, do other php scripts work on this server - that is, is php enabled in the apache configs? Does this line produce any visible output?

Code:
<?php echo getcwd(); ?>
Please try to be more complete in your description and provide any error messages that appear in the page, or in the apache logs. Help us help you!
 
Old 08-15-2018, 02:53 AM   #6
stockton
Member
 
Registered: Jan 2006
Location: Midrand, Gauteng, South Africa
Distribution: Raspbian, Mint 13, Slackware 14, Debian & Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 2
I have looked in the apache2 logs and access.log shows that the html is connecting and that is all. The error log shows nothing.
The LastLine.php is in the same directory and I get no output from getcwd.
I have tried both required as well as include and still I get a blank screen.
Not only do other php scripts work including phpinfo but LasLine.php also works if called from command line.
There is no error message just a blank screen.
When I disable the include the html loads.
astrogeek if I had any more information I would certainly share it.
If it helps at all you can try browsing to 196.32.102.29/lcars/solar5.html and if you do look at the page source and tell my why the two php lines are red, implying an error, but what.
 
Old 08-15-2018, 04:56 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please start with something simple, eg:
PHP Code:
<HTML><BODY>
<?php
    phpinfo 
();
?>
</BODY></HTML>
 
1 members found this post helpful.
Old 08-15-2018, 05:01 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,714

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Does your code work if you change the file name extension from html to php?

You can also add this php code to see errors too. error_reporting(E_ALL)

I finally was able to test embedded php code on my Pi and it will not run within a html web page unless it has the php extension by default.

Last edited by michaelk; 08-15-2018 at 06:57 AM. Reason: Update
 
1 members found this post helpful.
Old 08-15-2018, 09:38 AM   #9
stockton
Member
 
Registered: Jan 2006
Location: Midrand, Gauteng, South Africa
Distribution: Raspbian, Mint 13, Slackware 14, Debian & Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 2
If I rename solar5.html to solar5.php at least it starts to work. Now to see why my proggie cannot open that file. Probably permission error.
Thank you for your patience and help
 
Old 08-15-2018, 09:41 AM   #10
stockton
Member
 
Registered: Jan 2006
Location: Midrand, Gauteng, South Africa
Distribution: Raspbian, Mint 13, Slackware 14, Debian & Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 2
If I save NevemTeve suggestion as an html it fails but if I alter the suffix to php it works fine.
 
Old 08-15-2018, 09:44 AM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,714

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Check the error.log but would expect a permission error why you can not open the solar.log file.

Last edited by michaelk; 08-15-2018 at 09:46 AM.
 
Old 08-15-2018, 10:56 AM   #12
stockton
Member
 
Registered: Jan 2006
Location: Midrand, Gauteng, South Africa
Distribution: Raspbian, Mint 13, Slackware 14, Debian & Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 2
Of course running from the command line my php script manages to access that file fine but not if run from a webpage
 
Old 08-15-2018, 03:09 PM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> if I alter the suffix to php it works fine.

That is the expected behaviour. Keep using the .php extension.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP include rblampain Programming 4 11-13-2007 11:54 PM
PHP include problems deadlock Programming 2 01-17-2006 09:02 AM
PHP include it-s Programming 3 10-05-2005 11:07 PM
php include msound Programming 2 06-24-2004 04:21 PM
PHP Path include ..:eMa:.. Programming 4 09-25-2003 01:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration