seanfacer@yahoo.co.uk Posted September 1, 2010 Share Posted September 1, 2010 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) Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted September 1, 2010 Share Posted September 1, 2010 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'); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.