notaprogrammer Posted May 26, 2010 Share Posted May 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/ Share on other sites More sharing options...
kenrbnsn Posted May 26, 2010 Share Posted May 26, 2010 There are no syntax errors in the code you posted. Ken Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/#findComment-1063684 Share on other sites More sharing options...
notaprogrammer Posted May 26, 2010 Author Share Posted May 26, 2010 Yeah, I didn't think there was a problem, but that is the error I am getting. I wonder if it has anything to do with my PHP installation. Is there anything I should check? Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/#findComment-1063686 Share on other sites More sharing options...
premiso Posted May 26, 2010 Share Posted May 26, 2010 That is the full code from index.php? Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/#findComment-1063691 Share on other sites More sharing options...
notaprogrammer Posted May 26, 2010 Author Share Posted May 26, 2010 Yes, that is all that is in index.php. I have attached a screenshot. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/#findComment-1063696 Share on other sites More sharing options...
The Eagle Posted May 26, 2010 Share Posted May 26, 2010 Something must be wrong with your PHP installation. There aren't any syntax errors in that PHP script and infact it just sucessfully worked for me. http://vazzer.net/phpfreaks/work/notaprogrammer Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/#findComment-1063718 Share on other sites More sharing options...
notaprogrammer Posted May 26, 2010 Author Share Posted May 26, 2010 Yeah, that seems like what it is. Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/#findComment-1063721 Share on other sites More sharing options...
The Eagle Posted May 26, 2010 Share Posted May 26, 2010 No problem, if you have any more questions don't hesitate to ask. If you may, can you please mark this topic as solved. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/202988-parse-error-on-widely-used-php-script/#findComment-1063730 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.