Posted on: 03/16/05 05:06am
By: Rick78
Hello,
I am trying to make a new PHP block, or static page to wake up other PCs on my LAN using MagicPackets. Right now I am trying to get it to work on a static page, but I would like it to be in a block later. I am using a static page because I figured it would work there without much trouble. However, it errors and I am not sure if it is syntax. I am not a PHP expert at all. If I place the php file in the doc root of my server, it works in stand alone mode. I will place the code below. Maybe someone could spot why it errors in Geeklog.
I have tried with both execute php and execute php (return).
When I paste this code into the static page and chose execute PHP, this error appears when I try to view it:
Parse error: parse error in /var/www/html/home2/staticpages/index.php(59) : eval()'d code on line 1
It seems like it does not like this tag:
<?php
Nothing errors when I select (return), but no select option dropdown appears either.
Thanks a lot for any help.
Regards,
Rick
Here is the full code of the working standalone PHP page:
<?php
/*
** CVS info: $Id$
** ---------------------------------------------------------
*/
/****************************
** Configuration section **
****************************/
// List of hosts
$hosts = array(
"Carolines(FTP)" => "00:e0:29:3d:bd:84",
"Ninas" => "00:01:03:11:97:3b",
"Bereks" => "00:10:dc:e4:8f:21",
"Rick2" => "00:04:23:1b:a5:b8",
);
// Set this to the location of the perl executable
$perlexec = "/usr/bin/perl";
// Set this to the location of the perl script to execute
$perlscript = "/srv/www/cgi-bin/wakeup.pl";
/***********************************
** The stuff that makes it work **
***********************************/
if ($mac != "")
{
system($perlexec." ".$perlscript." ".$mac);
}
?>
<html>
<head>
<title>Berek's WOL front</title>
</head>
<body>
<form action="<?php print($PHP_SELF) ?>" method="post">
<table>
<tr>
<td>
<select name="mac">
<option value="">Select host to wake up:
<?php
foreach ($hosts AS $hostname => $macaddress)
{
print(" <option value="".$macaddress.""> ".$hostname);
}
?>
</select>
</td>
<td><input type="submit" value="GO!"></td>
</tr>
</table>
</form>
</body>
</html>
Help with new PHP block
Posted on: 03/16/05 05:12am
By: Robin
I defenitely doesn't like the <? php code.
Help with new PHP block
Posted on: 03/16/05 06:59am
By: Rick78
Any suggestions on what code to use instead of what is used?
Thanks,
Rick
Help with new PHP block
Posted on: 03/16/05 12:11pm
By: machinari
see
this topic[*1] for my explanation re php open and close tags in staticpages .
Help with new PHP block
Posted on: 03/16/05 12:32pm
By: knuff
[QUOTE BY= machinari] see
this topic[*1] for my explanation re php open and close tags in staticpages .[/QUOTE]
That one surely looks like a very good FAQ. Maybe Dirk could add a link to the forum topic in the
Static Page FAQ[*2]
Allthough the
Static Help Page Documentation[*3] does mention it, your example looks much more clear than the line in the docu which is easily overlooked.
[QUOTE BY=documentation]Please note that when embedding PHP code in a static page, your code should not be enclosed in the PHP tags. Instead, it is assumed that the static page contains the PHP code that would normally go between those two tags.[/QUOTE]
In addition, when you later on want to use it in a block and not a static page have a look at this
FAQ[*4] as you will have to port the php to lib-custom.php in order to get it up and running.
Great Explanation Machinari.
Best Regards,
Boris
Help with new PHP block
Posted on: 03/17/05 05:45am
By: Rick78
Thanks for the replies. Well the easiest solution to get this running in a static page seems to be as machinari suggests in the other post:
//end PHP
?>
<p>this is an HTML paragraph</p>
<?php
//this ends my HTML section and now I can write PHP
This would mean that I would just have to remove the first tag at the top which would leave PHP on until just before the html tag, where I would turn PHP off.
This is what I have now and it errors on line 41. Is this print command allowed in PHP? (Again, sorry I am not that good at PHP, but I am trying to learn)
/*
** CVS info: $Id$
** ---------------------------------------------------------
*/
/****************************
** Configuration section **
****************************/
// List of hosts
$hosts = array(
"Carolines(FTP)" => "00:e0:29:3d:bd:84",
"Ninas" => "00:01:03:11:97:3b",
"Bereks" => "00:10:dc:e4:8f:21",
"Rick2" => "00:04:23:1b:a5:b8",
);
// Set this to the location of the perl executable
$perlexec = "/usr/bin/perl";
// Set this to the location of the perl script to execute
$perlscript = "/srv/www/cgi-bin/wakeup.pl";
/***********************************
** The stuff that makes it work **
***********************************/
if ($mac != "")
{
system($perlexec." ".$perlscript." ".$mac);
}
?>
<html>
<head>
<title>Berek's WOL front</title>
</head>
<body>
<form action="<?php print($PHP_SELF) ?>" method="post">
<table>
<tr>
<td>
<select name="mac">
<option value="">Select host to wake up:
<?php
foreach ($hosts AS $hostname => $macaddress)
{
print(" <option value="".$macaddress.""> ".$hostname);
}
?>
</select>
</td>
<td><input type="submit" value="GO!"></td>
</tr>
</table>
</form>
</body>
</html>
Help with new PHP block
Posted on: 03/17/05 06:31am
By: knuff
Hi Rick,
Not really related with your error, but you should remove
<html>
<head>
<title>Berek's WOL front</title>
</head>
<body>
and
</body>
</html>
as these will be provided by the staticpage in which you wrap it.
Best Regards,
Boris
Help with new PHP block
Posted on: 03/17/05 06:38am
By: Robin
[QUOTE BY= Rick78]This is what I have now and it errors on line 41. Is this print command allowed in PHP?[/QUOTE]
I'd say it's an issue with quotes. Try something like this (line 41)
print(\" <option value="".$macaddress.""> \".$hostname);
HTH
Robert
PS
Don't get discouraged by the errors I don't