Jump to content

$1 argument


maymann

Recommended Posts

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 :-) !

Link to comment
https://forums.phpfreaks.com/topic/252736-1-argument/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/252736-1-argument/#findComment-1295701
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.