Home > Backend Development > PHP Tutorial > Javascript and PHP verify whether the URL address entered by the user is correct, javascripturl_PHP tutorial

Javascript and PHP verify whether the URL address entered by the user is correct, javascripturl_PHP tutorial

WBOY
Release: 2016-07-13 10:17:33
Original
881 people have browsed it

Javascript and PHP verify whether the URL address entered by the user is correct, javascripturl

The example in this article describes the method of using Javascript and PHP to verify whether the URL address entered by the user is correct. It is shared with everyone for your reference. The specific method is as follows:

1.javascript detects URL address validity:

Copy code The code is as follows:


URL:






2.PHP detects URL address validity

Copy code The code is as follows:
function is_url($str){
return preg_match("/^http://[A-Za-z0-9]+.[A-Za-z0-9]+[/=?%-&_~`@[]':+!]*( [^<>"])*$/", $str);
}
?>

If you want to try to see if it works normally, we can use the file_get_contents() function to verify.

I hope this article will be helpful to everyone’s PHP programming design.

How to use javascript code to judge whether the verification code entered by the user in php is entered correctly

Verification codes are generally generated randomly on the server. Use ajax to obtain the verification code on the html page and compare it with the verification code entered by the user.


< a href="document.getElementById('img_auth_code').src='auth_code.php?code='+Math.random();">Can’t see clearly, please change another one

//This page is used to randomly obtain the verification code rand_auth_code.php
function get_auth_code()
{
for($i=0;$i<5;$i++ )
{
$_GLOBALS['rand_str'].=strtoupper(dechex(rand(0,15)));
rand_str_width+=imagefontwidth($i);
}
}
echo $_GLOBALS['rand_str'];
?>

include_once("rand_auth_code.php");//Import the page that generates the verification code
$img_width=100;
$img_height=25;
$img=imagecreatetruecolor($img_width,$img_height);

$img_bg_col...The rest of the text>>

The results of PHP verification of user input and javaScript verification of user input are different?

Is there a problem with the page connecting to the database? I suggest you try another method

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/891105.htmlTechArticleJavascript and PHP verify whether the user input URL address is correct, javascripturl This article describes the example of Javascript and PHP verifying the user input URL address. Is it the correct method? Share it with everyone for everyone...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template