maymann Posted December 8, 2011 Share Posted December 8, 2011 Hi all, I don't know php, but i have a script i would like to be able to also run from shell, like: "php script arg1"... if (isset($_SERVER['argc'])) { $postip = $1; } else { $postip = $_POST["ip"]; } How do i assign $postip = $1; (or is it infact $2...) ? My script gives me this error now: PHP Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' Thanks in advance :-) ! Quote Link to comment Share on other sites More sharing options...
sanjay_zed Posted December 8, 2011 Share Posted December 8, 2011 dont use $1.. use 1 Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 8, 2011 Share Posted December 8, 2011 In PHP, variables cannot start with a number. Where is this $1 supposed to be coming from? EDIT: Maybe this is what you wanted? $postip = $argv[1]; Quote Link to comment Share on other sites More sharing options...
maymann Posted December 8, 2011 Author Share Posted December 8, 2011 Hi thanks, it should come from my "php scriptname arg1" Br. Quote Link to comment Share on other sites More sharing options...
trq Posted December 8, 2011 Share Posted December 8, 2011 That indeed would show up as $argv[1]. Quote Link to comment Share on other sites More sharing options...
maymann Posted December 8, 2011 Author Share Posted December 8, 2011 Thanks, another question, now I have you...:-) I have a working single-site-phone-reboot script here: --- <html> <body> <form action="polycom-reboot.php" method="post"> PolyCom Phone IP: <select name="ip"> <option value="IP1">IP1</option> <option value="IP2">IP2</option> </select><input type="submit" value="Reboot..."/> </form> </body> </html> --- I am trying to figure out how i can make a multi-site-phone-reboot script - here is what i got so far...: --- <html> <body> <script type="text/javascript"> function setOptions(chosen){ var selbox = document.formName.ip; selbox.options.length = 0; if (chosen == " ") { selbox.options[selbox.options.length] = new Option('No site selected',' '); } if (chosen == "1") { selbox.options[selbox.options.length] = new Option('IP1','IP1'); selbox.options[selbox.options.length] = new Option('IP2','IP2'); } if (chosen == "2") { selbox.options[selbox.options.length] = new Option('IP3','IP3'); selbox.options[selbox.options.length] = new Option('IP4','IP4'); } } </script> <form name="formName" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <select name="site" size="1" onchange="setOptions(document.formName.site.options[document.formName.site.selectedIndex].value);"> <option value=" " selected="selected"></option> <option value="1">SITE1</option> <option value="2">SITE2</option> </select> <select name="ip" size="1" method="post" action="polycom-reboot.php"> <option value=" " selected="selected">No phone selected</option> </select> <input type="submit" value="Reboot..."/> </form> </body> </html> --- Polycom-reboot.php script... --- <html> <body> <form method="POST" action="index.php"> <input type="submit" value="Return" /> </form> <?php require_once('php-sip/PhpSIP.class.php'); /* Check if we are running from commandline or not */ if (isset($_SERVER['argc'])) { $postip = $argv[1]; } else { $postip = $_POST["ip"]; } echo "$postip: "; /* Sends check-sync to Polycom phone */ try { $api = new PhpSIP(); $api->setUsername('USR'); // authentication username $api->setPassword('PWD'); // authentication password // $api->setProxy('PROXY'); $api->addHeader('Event: check-sync'); $api->setMethod('NOTIFY'); $api->setFrom('sip:6000@DEST'); $api->setUri("sip:4000@$postip"); $res = $api->send(); echo "response: $res\n"; } catch (Exception $e) { echo $e; } ?> </body> </html> --- I think my problem is parsing the [iP] from index.php->polycom-reboot.php, but i might be wrong. BTW - the "$postip = $argv[1];" did it for me - works like a charm :-) ! Br. Quote Link to comment Share on other sites More sharing options...
maymann Posted December 9, 2011 Author Share Posted December 9, 2011 solved Quote Link to comment 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.