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