Welcome to Geeklog Saturday, June 23 2018 @ 11:12 pm EDT

Geeklog Forums

Help with new PHP block


Status: offline

Rick78

Forum User
Regular Poster
Registered: 20/10/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:
PHP Formatted Code
<?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 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>





 

Status: offline

Robin

Forum User
Full Member
Registered: 15/02/02
Posts: 725
I defenitely doesn't like the &lt;? php code.
Geeklog Polish Support Team

Status: offline

Rick78

Forum User
Regular Poster
Registered: 20/10/03
Posts: 98
Any suggestions on what code to use instead of what is used?

Thanks,
Rick

Status: offline

machinari

Forum User
Full Member
Registered: 22/03/04
Posts: 1512
see this topic for my explanation re php open and close tags in staticpages .

Status: offline

knuff

Forum User
Full Member
Registered: 17/12/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 documentationRazzlease 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

Status: offline

Rick78

Forum User
Regular Poster
Registered: 20/10/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:
PHP 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)
PHP 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>
 

Status: offline

knuff

Forum User
Full Member
Registered: 17/12/04
Posts: 340
Location:Sweden
Hi Rick,

Not really related with your error, but you should remove

PHP Formatted Code
<html>
<head>
<title>Berek's WOL front</title>
</head>
<body>


and

PHP 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

Status: offline

Robin

Forum User
Full Member
Registered: 15/02/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)
PHP Formatted Code
    print(\"        <option value="".$macaddress."">   \".$hostname);




HTH
Robert
PS
Don't get discouraged by the errors I don't
Geeklog Polish Support Team

All times are EDT. The time is now 11:12 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