Jump to content

Why do I get this stupid furecking error? (Misspelled on purpose!)


3raser

Recommended Posts

Sorry for the title.

 

Warning: fsockopen() [function.fsockopen]: unable to connect to udp://:0 (Failed to parse address "") in /home/a9726309/public_html/server.php on line 4

 

Code:

 

<?php

$server = $_POST['ip'];
$port = $_POST['port'];
$status = fsockopen( 'udp://' . $server, $port, $errno, $errstr, 3 );
if ( !$status ) {
//include 'offline.gif';
die('<img src="offline.gif" />');
} else {
//include 'online.gif';
die('<img src="online.gif" />');
}

?>

How are you making sure that the user entered something in those textfields? I didn't enter anything. I just hit enter and got brought to a page that said

 

Warning: fsockopen() expects parameter 2 to be long, string given in /home/a9726309/public_html/server.php on line 5

Why the hell doesn't it work anyways? I currently don't care about if the user has entered something. I just want to get the damn thing working. And when ever I enter random information it keeps saying it's online. WTF?

 

New code:

 

<?php

$server = $_POST['ip'];
$port = $_POST['port'];

if (!$server || !$port)
die ("One of the required fields has not been filled out!");

$status = fsockopen( 'udp://' . $server, $port, $errno, $errstr, 3 );
if ( !$status ) {

die('<img src="offline.png" />');
} else {

die('<img src="online.png" />');
}

?>

 

Same error as before.

Warning: fsockopen() expects parameter 2 to be long, string given in /home/a9726309/public_html/server.php on line 5

2nd parameter is port... it expects a long and your passing a string!

 

just convert it to an int

ie

$port = (int)$_POST['port'];

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.