Php url problem

I’m developing a site in which I’ve one page as feedback.

Now in that page I’ve two input fields viz email and url.

The form markup



<td><label for="email">*Email:<?php if(isset($missing) && in_array('email', $missing)) { ?>
                  <span class="register"> Please enter your email</span>
                  <?php } ?></label><br />
                <input type="text" class="comment" name="email" title="We will not share your email with any one."
                value="<?php if (loggedin()) { echo $_SESSION['USER_EMAIL']; } elseif (isset($missing)) { echo htmlentities($_POST['email'], ENT_QUOTES); } ?>" />
                </td>
           </tr>
            <tr>
            	<td><label for="contact">Contact No:</label><br />
        		<input type="text" class="comment" name="contact" title="Your website if any?" value="<?php if (isset($missing)) { echo htmlentities($_POST['contact'], ENT_QUOTES); } ?>" />
                </td>
                <td><label for="url" class="fstcol">Your Website:</label><br />
                <input type="text" class="comment" name="url" size="40" title="Your website if any?" value="<?php if (isset($missing)) { echo htmlentities($_POST['url'], ENT_QUOTES); } ?>" />
                </td>
           


Now the processing script:


if(!empty($email))
		{
			//use regex to ensure no illegal characters are there in email address
			$checkEmail = '/^[^@]+@[^\\s\\r\
\\'";,@%]+$/';
			//reject the email address if it doesn't match
			if(!preg_match($checkEmail, $email))
			{
				array_push($missing, 'email');
			}
			[SIZE="6"][FONT="Comic Sans MS"]$message = "Please fill the required field(s) indicated.";[/FONT][/SIZE]
		}

if(!$suspect && empty($missing)) 
		{
			if(!filter_var($email, FILTER_VALIDATE_EMAIL))
			{
				$message = "Please provide the correct email address.";
			}
			elseif(isset($url) && $url != false)
			{
				if(!filter_var($url, FILTER_VALIDATE_URL))
				{
					$message = "You have not entered the correct website address.";
				}
			}
			elseif(isset($contact) && $contact != false && !is_numeric($contact))
			{
				
					$message = "Only numeric values for contact field.";
				
			}
			else
			{
				if(loggedin())
				{
					$uid = $_SESSION['USER_ID'];
				}
				$sql = "insert into feedback(uid, name, email, url, contact, subject, feedback) ";
				$sql .= " values('".@$uid."','$name', '$email', '$url', '$contact', '$subject', '$comments')";
				$res = query($sql);
				if(!$res)
				{
					$message = "Server Down";
				}
}




Now the problem arises, when ever I’m using the url field, it is unable to send the message and just shows the message which I’ve highlighted.

But if I wont use the url field, then everything works fine.

And one more thing I want to say that the regex I’m using is not mine, and I’m a novice in regex or yet to start.

I just borrowed that regex pattern from regexlib.com. Hence may be there was some error in that regex pattern. While I can guess only.

And even if I wont use that pattern still my script wont work. But if I wont use the url field, then every things just working fine.

Now how can I get rid of this problem ?

And one more thing I wanna add.

if say some one put url as just

somedomain.com

then I wanna convert it to

http://somedomain.com

how can I convert it into such ??

Ok I’ve made a little script, please tell me whether is it correct or not for converting of url

somedomain.com into http://somedomain.com


if(!preg_match('#^(http://)#', $url))
	{
		$url = 'http://'.$url;
	}

Suggestions and advice are needed.

That seems to work, or


if(substr($url,0,7)!== 'http://'){
  $url = 'http://'.$url
}

may too