Jump to content

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


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'];

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.