PDA

View Full Version : Visual Basic & PHP


JohnBradshaw
Sun 12th Aug '01, 4:16pm
Hi

I know this isn't to do with the forums but I am a bit stuck! I'd like to pass variables from PHP to a Visual Basic programme is there anyway to do this? I thought about cookies but I don't really know.

Mark Hensler
Sun 12th Aug '01, 5:59pm
Cookies wont do it.

Where is the PHP script, and where is the VB app?

I've done this before using TCP sockets. The PHP script was on a web server, and the VB app was on a remote personal machine. The VB app was listening to a specified port, and the PHP script simply opened IP:port, sent a string, and closed the socket. The VB app then parsed the string for needed data and performed it's functions. (this was used for RCM software)

JohnBradshaw
Mon 13th Aug '01, 3:10am
Yep it is PHP on the web server, and the VB app on a computer.

Taht's great! How do you tell PHP to open a port and broadcast on it?

Mark Hensler
Mon 13th Aug '01, 10:29am
something like this:

<?
if ($flag == 1) {
$fp = fsockopen ("$IP", $Port, $errno, $errstr, 30) or die("Error ($errno): $errstr <br>\n");
fputs($fp,"$String");
fclose ($fp);
}
?>
<html>
<head>
<title>PHP to VB</title>
</head>
<body>
<BR><BR>
<form action="" method=POST>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td align=right>
IP:
</td>
<td width=5></td>
<td>
<input type=text name=IP>
</td>
</tr>
<tr>
<td align=right>
Port:
</td>
<td width=5></td>
<td>
<input type=text name=Port value="123">
</td>
</tr>
<tr>
<td align=right>
String:
</td>
<td width=5></td>
<td>
<input type=text name=String>
</td>
</tr>
</table>
<BR>
<input type=hidden name=flag value=1>
<input type=submit value="Send it!">
</form>
</body>
</html>

You can read more about PHP's socket functions here (http://php.net/manual/en/function.socket.php).

Mark Hensler
Mon 13th Aug '01, 10:47am
I've attached a zip with a basic winsock client. It's written in Visual Basic. I haven't used it in quite a while. I made it to test my PHP script. It's listening to port 123, but you can easily change that (even in notepad).

All you'll see is a textarea. If it receives any data, it will write it to the textarea.

JohnBradshaw
Mon 13th Aug '01, 12:49pm
That's great thanks! Unfortunatly the ZIP hasn't uploaded, can you do it again please? ;)

Mark Hensler
Mon 13th Aug '01, 3:52pm
zip...