I want to execute tel2.php for each ip address I get from running the for loop. My tel2.php file has a session_start(). Hence, everytime the for loop script runs, I get the error saying session has already started. Please guide me how to fix this. Thank you.
<?php
session_start();
include("check.php");
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'searchrouters';
//connect with the database
$conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
// Check connection
$checkbox1=$_POST['IP'];
{
for($i=0; $i<sizeof($checkbox1);$i++){
$query="INSERT INTO checked (name) VALUES ('".$checkbox1[$i]."')";
$conn->query($query) or die(mysql_error());
$_SESSION['ipadd'] = $checkbox1[$i];
include('tel2.php');
}
}
?>
Tel2.php
<?php
session_start();
require_once "PHPTelnet.php";
$telnet = new PHPTelnet();
$telnet->show_connect_error=0;
// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$ipadd = $_SESSION['ipadd'];
echo $ipadd;
$result = $telnet->Connect("$ipadd",'nib2p1','nib2p1');
switch ($result) {
case 0:
$telnet->DoCommand('term length 0', $result);
echo $result;
$telnet->DoCommand('show clock', $result);
// NOTE: $result may contain newlines
echo $result;
// say Disconnect(0); to break the connection without explicitly logging out
$telnet->Disconnect();
break;
case 1:
echo '[PHP Telnet] Connect failed: Unable to open network connection';
break;
case 2:
echo '[PHP Telnet] Connect failed: Unknown host';
break;
case 3:
echo '[PHP Telnet] Connect failed: Login failed';
break;
case 4:
echo '[PHP Telnet] Connect failed: Your PHP version does not support PHP Telnet';
break;
}
?>