From: Vahis on
On 2010-06-12, graham <graham.marsden1(a)ntlworld.com> wrote:
> On Sat, 12 Jun 2010 06:41:21 +0000, Vahis wrote:
>
>> When I look at line 21 in Kate I don't know what the fault there is.
>> Instead of pasting the whole code here it can be seen at
>> http://waxborg.servepics.com/testsite/uptime.php
>>>
>
> That page renders ok in firefox and konquerer with os11.1 kde3.5.

It does. It always has.
It just has started to cause the notice in Apache logs.
Obviously php has changed and the php code has to be changed
accordingly.

Similar things have happened before, php written during a certain version
has probs after php changing to newer version.

Vahis
--
http://waxborg.servepics.com
openSUSE 11.2 (x86_64) 2.6.31.12-0.2-default
11:21am up 39 days 15:33, 14 users, load average: 0.04, 0.04, 0.00
From: David Bolt on
On Saturday 12 Jun 2010 11:03, while playing with a tin of spray paint,
houghi painted this mural:

> David Bolt wrote:
>> [0] I'm even writing shell scripts in php rather than bash. One of them
>> is a wrapper around the build script used for package building. It's
>> only 747 lines, and lets me build for any version of (open)SUSE that
>> I have mirrored. It's a sort of poor mans build service[2], except it
>> requires starting manually.
>
> Manually? Tss.

There's nothing wrong with doing it manually.

> $ while inotifywait -r -e MODIFY dir/; do make; done;
> make, or run a script, everytime a file in a directory is modified

Except I'd need to have that running for multiple directories, one for
the main project, and again for each sub-project.

> I am sure you have enough fantasy and knowledge to write a script around
> it to do what you want it to do. ;-)

I could, but the way I work is (usually) to make the required changes
and then do the test builds locally. No point in having it start doing
a build when I'm part way through updating, patching, or adding a
package. Plus, the build script needs to run as root, and in those
circumstances I'd rather do that manually.


Regards,
David Bolt

--
Team Acorn: www.distributed.net
openSUSE 11.0 32b | | | openSUSE 11.3M7 32b
| openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11

From: David Bolt on
On Saturday 12 Jun 2010 11:13, while playing with a tin of spray paint,
houghi painted this mural:

> Because now all we see is a working page and we have no idea what went
> wrong if anything.
> And afterwards you can comment the lines out or remove them.

You might not want to include it with pages that sets up and uses
database connections. As an alternate to that, take out the parts that
have the sensitive information, put it as a separate script, and then
include it by using require() or require_once(). For extra security,
you could even take that script out of the normally accessible webroot.
As long as it's stored in a location that php can read, and you pass
the path to the file, it will be found and used.


Regards,
David Bolt

--
Team Acorn: www.distributed.net
openSUSE 11.0 32b | | | openSUSE 11.3M7 32b
| openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11

From: David Bolt on
On Saturday 12 Jun 2010 07:41, while playing with a tin of spray paint,
Vahis painted this mural:

> On 2010-06-12, David Bolt <blacklist-me(a)davjam.org> wrote:
>> On Friday 11 Jun 2010 17:27, while playing with a tin of spray paint,
>> Vahis painted this mural:
>>
>>> which gives a 'PHP Notice: Undefined variable' in Apache error log.
>>
>> Have you checked to see where $days and $uptimeString are defined?
>
> Tried, yes. Php just isn't in my set of skills :(
> It's a script that I found long ago, it used to have no errors AFAIR
> but after some php version change there's been this notice.

Which PHP version change? PHP4 to PHP5? There were some changes between
them, but I've not noticed anything when upgrading through the various
PHP5 versions.

> <snip>
>>
>> So was I, although I've improved a little bit[0] since the last time I
>> posted here about PHP and databases[1].
>
> I remember that. That's roughly when I noticed that programming is not
> necessarily my cup of tea.
> Purchasing a two inch thick book about Php5/MySQL didn't get me
> anywhere.

I've got of them, although each of mine are only about an inch thick.

> It looks great in the book shelf though.

Strangely enough, that's more or less what's happened to mine. At least
they keep my photography books company.

>> Try calling the script using the command line.
>
> That gives the same as Apache log. It says
> PHP Notice: Undefined variable: uptimeString in uptime.php on line 21

Now that gives more details that weren't in the first post.

> When I look at line 21 in Kate I don't know what the fault there is.

My guess is that before the line:

if ($days > 0) {

you're missing a line:

$uptimeString="";

> Instead of pasting the whole code here it can be seen at

Houghi gave a suggestion on dealing with that.

> http://waxborg.servepics.com/testsite/uptime.php

That works here.

As for my own version, you can find it here:

<http://www.davjam.org/~davjam/uptime.php>

with the page source here:

<http://www.davjam.org/~davjam/uptime.php?code>


Regards,
David Bolt

--
Team Acorn: www.distributed.net
openSUSE 11.0 32b | | | openSUSE 11.3M7 32b
| openSUSE 11.1 64b | openSUSE 11.2 64b |
TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11

From: Vahis on
On 2010-06-12, David Bolt <blacklist-me(a)davjam.org> wrote:

> My guess is that before the line:
>
> if ($days > 0) {
>
> you're missing a line:
>
> $uptimeString="";

Great guess :)
I added that and it seems to have removed the notice.

>> http://waxborg.servepics.com/testsite/uptime.php
>
> That works here.

Does it stay static or does it advance every second?
I'll put the whole thing here, there's javascript in it to make it
dynamic in case the browser supports it.

And if my php skill is zero, javascript is below that...
_________________________________________________
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<link rel="shortcut icon" href="favicon.ico">
<link rel="icon" type="image/gif" href="animated_favicon1.gif">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Waxborg uptime</title>

<?php
// format the uptime in case the browser doesn't support
// dhtml/javascript
// static uptime string
function format_uptime($seconds) {
$secs = intval($seconds % 60);
$mins = intval($seconds / 60 % 60);
$hours = intval($seconds / 3600 % 24);
$days = intval($seconds / 86400);
$uptimeString = "";

if ($days > 0) {
$uptimeString .= $days;
$uptimeString .= (($days == 1) ? " day" : " days");
}
if ($hours > 0) {
$uptimeString .= (($days > 0) ? ", " : "") . $hours;
$uptimeString .= (($hours == 1) ? " hour" : " hours");
}
if ($mins > 0) {
$uptimeString .= (($days > 0 || $hours > 0) ? ", " : "") . $mins;
$uptimeString .= (($mins == 1) ? " minute" : " minutes");
}
if ($secs > 0) {
$uptimeString .= (($days > 0 || $hours > 0 || $mins > 0) ? ", " :
"") . $secs;
$uptimeString .= (($secs == 1) ? " second" : " seconds");
}
return $uptimeString;
}

// read in the uptime (using exec)
$uptime = exec("cat /proc/uptime");
$uptime = split(" ",$uptime);
$uptimeSecs = $uptime[0];

// get the static uptime
$staticUptime = "Server Uptime: ".format_uptime($uptimeSecs);
?>
<html>
<head>
<script type="text/javascript">
<!--
var upSeconds=<?php echo $uptimeSecs; ?>;
function doUptime() {
var uptimeString = "Server Uptime: ";
var secs = parseInt(upSeconds % 60);
var mins = parseInt(upSeconds / 60 % 60);
var hours = parseInt(upSeconds / 3600 % 24);
var days = parseInt(upSeconds / 86400);
if (days > 0) {
uptimeString += days;
uptimeString += ((days == 1) ? " day" : " days");
}
if (hours > 0) {
uptimeString += ((days > 0) ? ", " : "") + hours;
uptimeString += ((hours == 1) ? " hour" : " hours");
}
if (mins > 0) {
uptimeString += ((days > 0 || hours > 0) ? ", " : "") + mins;
uptimeString += ((mins == 1) ? " minute" : " minutes");
}
if (secs > 0) {
uptimeString += ((days > 0 || hours > 0 || mins > 0) ? ", " : "") +
secs;
uptimeString += ((secs == 1) ? " second" : " seconds");
}
var span_el = document.getElementById("uptime");
var replaceWith = document.createTextNode(uptimeString);
span_el.replaceChild(replaceWith, span_el.childNodes[0]);
upSeconds++;
setTimeout("doUptime()",1000);
}
// -->
</script>
</head>
<body onLoad="doUptime();">
<!-- Uses the DIV tag, but SPAN can be used as well -->
<div id="uptime" style="font-weight:bold;"><?php echo $staticUptime;
?></div>
</body>
</html>
_______________________________________________________________

P.S. There had been a power outage this afternoon here.
Boy, was I surprised to see the uptime page after coming home.
Then the wife told me that the power had been down...

Vahis
--
http://waxborg.servepics.com
openSUSE 11.2 (x86_64) 2.6.31.12-0.2-default
18:36pm up 3:08, 9 users, load average: 0.10, 0.28, 0.20