Jump to content

Recommended Posts

Hello,

 

As you can see by my name, I am not a programmer. I have programmed before, but I don't do this everyday.

 

I need to setup a Wake On Lan script to remotely wake up some PCs. I found a script on this site that seemed promising: http://www.hackernotcracker.com/2006-04/wol-wake-on-lan-tutorial-with-bonus-php-script.html . I then setup an Ubuntu (10.04) Linux in a virtual machine and installed a LAMP server. I tested the PHP by using this code: <?php phpinfo(); ?>. Works fine. I can also echo out text no problem.

 

When I use the WOL script, I get no output. So I enabled error reporting in the php.ini, and I get the following error:

 

Parse error: syntax error, unexpected T_VARIABLE in /var/www/wol/index.php on line 4

 

The code:

---------------------------------------------------------------------

<?php

flush();

function WakeOnLan($addr, $mac,$socket_number) {

  $addr_byte = explode(':', $mac);

  $hw_addr = '';

  for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));

  $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);

  for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;

  $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

  if ($s == false) {

    echo "Error creating socket!\n";

    echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));

    return FALSE;

    }

  else {

    $opt_ret = socket_set_option($s, 1, 6, TRUE);

    if($opt_ret <0) {

      echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";

      return FALSE;

      }

    if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {

      echo "Magic Packet sent successfully!";

      socket_close($s);

      return TRUE;

      }

    else {

      echo "Magic packet failed!";

      return FALSE;

      }

    }

  }

$socket_number = "7";

$mac_addy = "00:1E:90:0A:5A:89";

$ip_addy = gethostbyname("192.168.1.10");

WakeOnLan($ip_addy, $mac_addy,$socket_number)

?>

---------------------------------------------------------------------

 

This line: $addr_byte = explode(':', $mac);

is line 4

 

What am I doing wrong?

 

Thanks for your help.

Link to comment
https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.