Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 02:00 pm EST
Geeklog Forums
Help with new PHP block
Status: offline
Rick78
Forum User
Regular Poster
Registered: 10/20/03
Posts: 98
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:
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>
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:
Text Formatted Code
<?phpNothing 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:
Text Formatted Code
<?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>
7
10
Quote
Status: Banned
machinari
Forum User
Full Member
Registered: 03/22/04
Posts: 1512
see this topic for my explanation re php open and close tags in staticpages .
7
13
Quote
Status: offline
knuff
Forum User
Full Member
Registered: 12/17/04
Posts: 340
Location:Sweden
Quote by machinari: see this topic for my explanation re php open and close tags in staticpages .
That one surely looks like a very good FAQ. Maybe Dirk could add a link to the forum topic in the Static Page FAQ
Allthough the Static Help Page Documentation does mention it, your example looks much more clear than the line in the docu which is easily overlooked.
Quote by documentationlease 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.
In addition, when you later on want to use it in a block and not a static page have a look at this FAQ 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
Vanrillaer.com - our Family Portal
8
7
Quote
Status: offline
Rick78
Forum User
Regular Poster
Registered: 10/20/03
Posts: 98
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:
?>
<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>
Text Formatted Code
//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)
Text Formatted Code
/*** 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>
7
6
Quote
Status: offline
knuff
Forum User
Full Member
Registered: 12/17/04
Posts: 340
Location:Sweden
Hi Rick,
Not really related with your error, but you should remove
<head>
<title>Berek's WOL front</title>
</head>
<body>
and
</html>
as these will be provided by the staticpage in which you wrap it.
Best Regards,
Boris
Vanrillaer.com - our Family Portal
Not really related with your error, but you should remove
Text Formatted Code
<html><head>
<title>Berek's WOL front</title>
</head>
<body>
and
Text Formatted Code
</body></html>
as these will be provided by the staticpage in which you wrap it.
Best Regards,
Boris
Vanrillaer.com - our Family Portal
24
7
Quote
Status: offline
Robin
Forum User
Full Member
Registered: 02/15/02
Posts: 725
Quote by Rick78:This is what I have now and it errors on line 41. Is this print command allowed in PHP?
I'd say it's an issue with quotes. Try something like this (line 41)
Text Formatted Code
print(\" <option value="".$macaddress.""> \".$hostname);HTH
Robert
PS
Don't get discouraged by the errors I don't
Geeklog Polish Support Team
7
7
Quote
All times are EST. The time is now 02:00 pm.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content