我需要屏蔽对所有不包含&uuid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
x
是随机的,可以包含数字和文字
最终代码需要同时包含两个验证:if ($context->data->ticket->ohanah_event_id)
和URL检查。
此刻使用的守则是:
<?php
/**
* @package Ohanah
* @copyright Copyright (C) 2012 - 2016 Beyounic SA. All rights reserved.
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
* @link http://www.beyounic.com
*/
class ComOhanahViewTicketHtml extends ComOhanahViewHtml
{
protected function _fetchData(KViewContext $context)
{
parent::_fetchData($context);
if ($context->data->ticket->ohanah_event_id) {
$doc = JFactory::getDocument();
$translator = $this->getObject('translator');
$doc->setTitle($translator->translate('COM_OHANAH_TICKET') . ' - ' . $context->data->ticket->event->title);
}
}
}
答案 0 :(得分:0)
class ComOhanahViewTicketHtml extends ComOhanahViewHtml
{
protected function _fetchData(KViewContext $context)
{
parent::_fetchData($context);
$url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if(isset($context->data->ticket->ohanah_event_id) && strpos($url, '&uuid=') == true) {
//here $url is your url
$doc = JFactory::getDocument();
$translator = $this->getObject('translator');
$doc->setTitle($translator->translate('COM_OHANAH_TICKET') . ' - ' . $context->data->ticket->event->title);
}
}
}
我认为这就是你的想法
答案 1 :(得分:0)
这将是这样的..如果你给我更多关于uuid格式的精确度,我可以用更好的正则表达式进行更新。有些事情,例如,如果示例显示由x
分隔的-
的准确数字,则正则表达式将为'/^[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}$/'
。 (请注意,这些正则表达式不支持重音字符)
class ComOhanahViewTicketHtml extends ComOhanahViewHtml
{
protected function _fetchData(KViewContext $context)
{
parent::_fetchData($context);
if(!isset($_GET['uuid']) || !preg_match('/^[A-Za-z0-9-]*$/', $_GET['uuid'])){
exit('URL NOT ALLOWED!');
}else{
if ($context->data->ticket->ohanah_event_id) {
$doc = JFactory::getDocument();
$translator = $this->getObject('translator');
$doc->setTitle($translator->translate('COM_OHANAH_TICKET') . ' - ' . $context->data->ticket->event->title);
}
}
}
}
请注意,如果尚未发送标头,您可以使用header('HTTP/1.0 403 Forbidden');
添加准确的禁止错误(简单版本,您可以找到更好的接受HTTPS和所有标准的错误)