Jump to content

function - validate ip address and return errors


seanfacer@yahoo.co.uk
 Share

Recommended Posts

HI guys

 

I have vreated a site and am now trying to validate the ip address i have created a function but am failing to get it to work i need to add the errors to add to the errors array but instead it keeps resetting and leaving me with the last error that is returned any help would be greatly appreciated im a newbie so if i can understand the concept behind whats happening it will be of great benefit

Thanks Sean

 

heres the code

 

// Function validateIpaddress($address,$record,$errors)

// {

// if ($address !=="" or $address !=="ip_address")

// {

// Print_r($address);

// echo "<br><br>";

// $fullstoppos = strpos(($address), ".");

// echo "strpos = $fullstoppos";

// $fullstoppos2 = strpos(($address), ".", $fullstoppos+1);

// echo "strpos2 = $fullstoppos2";

// $fullstoppos3 = strpos(($address), ".", $fullstoppos2+1);

// echo "strpos3 = $fullstoppos3";

// }

// if ($fullstoppos !==4 && $fullstoppos2 !==9 && $fullstoppos3 !==14)

// {

// $errors[] = "<br><font color='red'>Please correct the following.Or contact your client manager for assitance.<br>* $record is a required field.An ip address is a 16 digit numerical value.  </font>";

// }

// }

 

$errors = validateIpaddres($_POST['destinationPoint'],A/AAAA record, $errors)

 

 

Link to comment
Share on other sites

You could just use:

 

filter_var($address, FILTER_VALIDATE_IP);

 

But as for your code, it looks like you have $errors in the arguments so that would lead me to believe that you want to pass by reference.  If so do this:

 

Change:

Function validateIpaddress($address,$record,$errors)

To:

Function validateIpaddress($address, $record, &$errors)

Change:

$errors = validateIpaddres($_POST['destinationPoint'],A/AAAA record, $errors)

To:

validateIpaddres($_POST['destinationPoint'], 'A/AAAA record', $errors);

 

If you want to return errors instead, then change:

 

Function validateIpaddress($address,$record,$errors)

To:

Function validateIpaddress($address, $record)

Change:

$errors[] = "<br><font color='red'>Please correct the following.Or contact your client manager for assitance.<br>* $record is a required field.An ip address is a 16 digit numerical value.  </font>";

To:

return "<br><font color='red'>Please correct the following.Or contact your client manager for assitance.<br>* $record is a required field.An ip address is a 16 digit numerical value.  </font>";

Change:

$errors = validateIpaddres($_POST['destinationPoint'],A/AAAA record, $errors)

To:

$errors[] = validateIpaddres($_POST['destinationPoint'], 'A/AAAA record');

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.