Hi, i have two files. client.php/server.php. Basically the client selects a drop down box of the number of rows and number of columns. This is then converted into 1 string and sent to the server. The server then splits the strings back again and then generates the table using the numbers from the strings.
What i need help is, basically i've done everything except the loop for actually generating the table using the numbers; because i have no idea.
ill post the code below. Its fairly straight forward since im just starting to use php and it isn't particulary good code, but i've commented everything anyway. If anyone could take a look and help me out, much apprechiated!
Client.php
<html>
<head>
</head>
<body>
<?php
if(isset($_POST['submit'])) {
$row = $_POST["rows"];
$column = $_POST["column"];
$com = ",";
$str = ($row . $com . $column);
do_it($str);
}
?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<label><strong>Table Generator</strong><br>
<br>
Rows
<select name="rows" id="rows">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</label>
<br>
<label>
Columns
<select name="column" id="column">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</label>
<p>
<input type="submit" name="submit" value="Generate">
</form>
<?
function do_it($str)
{
// set some variables
$host = "localhost";
$port = 10010;
$ret;
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// connect socket
$ret = socket_connect($socket, $host, $port);
$str = $str . "\n";
// socket write
socket_write($socket, $str);
$input = socket_read($socket,1024);
$input = trim($input);
echo $input;
socket_close($socket);
}
?>
</body
</html>
Server.php
<?
// set some variables
$host = "localhost";
$port = 10010;
// timeout!
set_time_limit(30);
do{
// create socket
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
// bind socket to port
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
// start listening for connections
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
// accept incoming connections
// spawn another socket to handle communication
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
// read client input
$input = socket_read($spawn, 1024);
// clean up input string
$input = trim($input);
// set input back to $str
$str = $input;
//split the text using , to get rows and columns
$pieces = explode(",", $str);
//set row and column back to variables
$rows = $pieces[0];
$column = $pieces[1];
// output the variables
$output = ("$rows,$column");
// write back to socket
socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
// close sockets
socket_close($spawn);
socket_close($socket);
}while ($input != “END”);
?>
[attachment deleted by admin]