dongyi9023 2013-12-17 01:08 采纳率: 0%
浏览 49
已采纳

Zend URL验证失败

I am running a shopping agent website to accept orders from users. One key step is to allow users send me the URL of items they wish to order (from an overseas website called taobao which do not ship to Australia), so I can order for them.

As I was getting many wrong URLs I thought it may be a good idea to add URL validation before users submit the order. I am using Zend framework so I just use the URI checker provided by Zend:

// allow unwise characters in URL, used in user input URL validation
Zend_Uri::setConfig(array('allow_unwise' => true));

// add http:// or https:// if not present
if ( strlen($tblurl[$rowid]) > 7 )
{

if ( ( substr($tblurl[$rowid],0,7) != 'http://' ) && ( substr($tblurl[$rowid],0,7) != 'https:/' ) )
{
$tblurl[$rowid] = 'http://'.$tblurl[$rowid];
}

}

// Check if URL is valid
$isValidURL = Zend_Uri::check($tblurl[$rowid]);

The only pre-processing here is to add http:// or https:// if the users miss that (as "www.chinabuy.com.au" will return invalid but "http://www.chinabuy.com.au" will return valid).

I have received several emails from customers complaining they get the URL validation failed error message. I really don't see where I'm doing wrong and I've been testing this with many different strange looking URLs but it seems the code is working as intended.

Any ideas? My website is https://www.chinabuy.com.au/order so you can test it (just go straight down to order details, type in some URL and click submit. If there is an error message "There must be a valid URL for each item." then it means the validation has failed.

Thanks!

EDIT: As suggested by @ArendE I've updated my code and has put the new code live on my website:

$tblurl[$rowid] = trim($tblurl[$rowid]);
// Check if the url contain the words http:// or https://
if (stripos($tblurl[$rowid],'http://') === false && stripos($tblurl[$rowid],'https://') === false) {
  $tblurl[$rowid] = 'http://' . $tblurl[$rowid];
}
$isValidURL = Zend_Uri::check($tblurl[$rowid]);
  • 写回答

1条回答 默认 最新

  • doulu8415 2013-12-17 01:31
    关注

    There is a typo with the https:/ (missing a slash). I would suggest you change the way you check the url; or use trim on the input url (it may contain a space, tab, newline etc.). Below is a script you could use, if you dont have other URLs as GET variables.

    Zend_Uri::setConfig(array('allow_unwise' => true));
    
    // Check if the url contain the words http:// or https://
    if(strpos($tblurl[$rowid],'http://') !== false || strpos($tblurl[$rowid],'https://') !== false) {
       $isValidURL = Zend_Uri::check($tblurl[$rowid]);
    } else {
       $isValidURL = Zend_Uri::check('http://' . $tblurl[$rowid]);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。