本文整理汇总了PHP中Validation::url方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::url方法的具体用法?PHP Validation::url怎么用?PHP Validation::url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
public function beforeSave($options = array())
{
// add http:// if not present in webpage
$webpage = $this->data['Registrant']['webpage'];
$V = new Validation();
if (!empty($webpage) && $V->url($webpage) && !$V->url($webpage, true)) {
$this->data['Registrant']['webpage'] = 'http://' . $webpage;
}
// generate edit key
if (empty($this->data['Registrant']['edit_key'])) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$this->data['Registrant']['edit_key'] = substr(str_shuffle($chars), 0, 8);
}
return true;
}
示例2: __cleanOptions
function __cleanOptions($options)
{
if (!$options['size']) {
unset($options['size']);
} else {
if ($options['size'] < 1) {
$options['size'] = 1;
} elseif ($options['size'] > 512) {
$options['size'] = 512;
}
}
if (!$options['rating'] || !in_array($options['rating'], $this->__allowedRatings)) {
unset($options['rating']);
}
if (!$options['default']) {
unset($options['default']);
} else {
if (!in_array($options['default'], $this->__defaultIcons)) {
if (!Validation::url($options['default'])) {
unset($options['default']);
}
}
}
return $options;
}
示例3: register
function register()
{
global $timezones;
$this->pageTitle = __('register', true);
$this->set('tzs', $timezones);
$this->set('utz', $this->data['User']['tz']);
if (!empty($this->data)) {
$this->Security->requirePost('register');
$v = new Validation();
if ($this->data['User']['email'] !== $this->data['User']['confemail']) {
$this->User->invalidate('confemail');
}
if ($this->User->findByEmail($this->data['User']['email']) || !$v->email($this->data['User']['email'])) {
$this->User->invalidate('email');
}
if ($this->data['User']['password'] !== $this->data['User']['confpass']) {
$this->User->invalidate('confpass');
}
if (!$v->url($this->data['User']['website']) && !empty($this->data['User']['website'])) {
$this->User->invalidate('website');
}
if ($this->User->validates()) {
$clean = new Sanitize();
// Generate and set the password, salt and activation key
$pass = $this->Hash->password($this->data['User']['password'], $this->data['User']['email']);
$this->data['User']['active'] = $this->Hash->keygen(10, true);
$this->data['User']['password'] = $pass['pass'];
$this->data['User']['salt'] = $pass['salt'];
// Save a few fields from the wrath of cleanArray()
$temp = array('lat' => $this->data['User']['lat'], 'lng' => $this->data['User']['lng'], 'tz' => $this->data['User']['tz'], 'email' => $this->data['User']['email']);
// Scrub 'a dub
$clean->clean($this->data);
$this->data['User']['email'] = $clean->escape($temp['email']);
$this->data['User']['lng'] = floatval($temp['lng']);
$this->data['User']['lat'] = floatval($temp['lat']);
$this->data['User']['tz'] = intval($temp['tz']);
$this->data['User']['role'] = 0;
$this->User->begin();
if ($this->User->save($this->data)) {
$this->Email->to = $this->data['User']['email'];
$this->Email->replyTo = $this->data['User']['email'];
$this->Email->from = APP_NAME . ' <' . APP_EMAIL . '>';
$this->Email->subject = sprintf(__('email_subject_welcome', true), APP_NAME);
$this->Email->template = 'register';
$this->Email->sendAs = 'both';
$this->set('actcode', $this->data['User']['active']);
if ($this->Email->send()) {
$this->User->commit();
$this->Session->setFlash('Account created!');
} else {
$this->User->rollback();
$this->Session->setFlash('Error!');
}
} else {
$this->User->rollback();
$this->Session->setFlash('Error\'d');
}
}
}
}
示例4: setURL
/**
* Set URL
*
* Validates and sets the URL.
*
* @param string $url
* @return true
* @throws Exception
*/
public function setURL($url)
{
if (!Validation::url($url) || !is_string($url)) {
throw new Exception("URL is not valid to curl.");
}
curl_setopt($this->curl, CURLOPT_URL, $url);
$this->set[] = 'url';
return true;
}
示例5: view
public function view()
{
if (empty($this->request->query['link'])) {
throw new NotFoundException('Missing link parameter');
}
$link = rawurldecode($this->request->query['link']);
if (!Validation::url($link)) {
throw new NotFoundException('Invalid link');
}
$request = new Nodes\Curl($link);
$request->exec();
$responseCode = $request->getResponseCode();
if ($responseCode != 200) {
throw new NotFoundException('Response code was not 200 OK');
}
$this->response->disableCache();
$this->response->type($request->getResponseHeader('content-type'));
$this->response->body($request->getResponseBody());
$this->response->send();
$this->_stop();
}
示例6: testUrl
/**
* testUrl method
*
* @return void
*/
public function testUrl()
{
$this->assertTrue(Validation::url('http://www.cakephp.org'));
$this->assertTrue(Validation::url('http://cakephp.org'));
$this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('http://192.168.0.1'));
$this->assertTrue(Validation::url('https://www.cakephp.org'));
$this->assertTrue(Validation::url('https://cakephp.org'));
$this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('https://192.168.0.1'));
$this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('sftp://192.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
$this->assertTrue(Validation::url('www.domain.tld'));
$this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
$this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params'));
$this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor'));
$this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
$this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
$this->assertTrue(Validation::url('http://underscore_subdomain.example.org'));
$this->assertTrue(Validation::url('http://_jabber._tcp.gmail.com'));
$this->assertTrue(Validation::url('http://www.domain.longttldnotallowed'));
$this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('http://w_w.domain.co_m'));
$this->assertFalse(Validation::url('http://www.domain.12com'));
$this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
$this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
$this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
$this->assertFalse(Validation::url('http://www.underscore_domain.org'));
$this->assertFalse(Validation::url('http://_jabber._tcp.g_mail.com'));
$this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
$this->assertFalse(Validation::url('--.example.com'));
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/subdir/index.html'));
$this->assertTrue(Validation::url('http://www.zwischenraume.de'));
$this->assertTrue(Validation::url('http://www.zwischenraume.cz'));
$this->assertTrue(Validation::url('http://www.last.fm/music/浜崎あゆみ'), 'utf8 path failed');
$this->assertTrue(Validation::url('http://www.electrohome.ro/images/239537750-284232-215_300[1].jpg'));
$this->assertTrue(Validation::url('http://www.eräume.foo'));
$this->assertTrue(Validation::url('http://äüö.eräume.foo'));
$this->assertTrue(Validation::url('http://cakephp.org:80'));
$this->assertTrue(Validation::url('http://cakephp.org:443'));
$this->assertTrue(Validation::url('http://cakephp.org:2000'));
$this->assertTrue(Validation::url('http://cakephp.org:27000'));
$this->assertTrue(Validation::url('http://cakephp.org:65000'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('[::1]'));
$this->assertTrue(Validation::url('[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('[::1]:80'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]'));
$this->assertTrue(Validation::url('http://[::1]'));
$this->assertTrue(Validation::url('http://[2001:0db8::1428:57ab]:80'));
$this->assertTrue(Validation::url('http://[::1]:80'));
$this->assertFalse(Validation::url('[1::2::3]'));
}
示例7: _cleanOptions
/**
* Sanitize the options array
*
* @param array $options Array of options, keyed from default settings
* @return array Clean options array
*/
protected function _cleanOptions($options)
{
if (!isset($options['size']) || empty($options['size']) || !is_numeric($options['size'])) {
unset($options['size']);
} else {
$options['size'] = min(max($options['size'], 1), 512);
}
if (!$options['rating'] || !in_array(mb_strtolower($options['rating']), $this->_allowedRatings)) {
unset($options['rating']);
}
if (!$options['default']) {
unset($options['default']);
} else {
App::uses('Validation', 'Utility');
if (!in_array($options['default'], $this->_defaultIcons) && !Validation::url($options['default'])) {
unset($options['default']);
}
}
return $options;
}
示例8: testUrl
/**
* testUrl method
*
* @access public
* @return void
*/
function testUrl()
{
$this->assertTrue(Validation::url('http://www.cakephp.org'));
$this->assertTrue(Validation::url('http://cakephp.org'));
$this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('http://192.168.0.1'));
$this->assertTrue(Validation::url('https://www.cakephp.org'));
$this->assertTrue(Validation::url('https://cakephp.org'));
$this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('https://192.168.0.1'));
$this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
$this->assertTrue(Validation::url('www.domain.tld'));
$this->assertFalse(Validation::url('http://w_w.domain.co_m'));
$this->assertFalse(Validation::url('http://www.domain.12com'));
$this->assertFalse(Validation::url('http://www.domain.longttldnotallowed'));
$this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
$this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
$this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
$this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/parenth()eses.php'));
$this->assertTrue(Validation::url('http://www.domain.com/index.php?get=params&get2=params'));
$this->assertTrue(Validation::url('http://www.domain.com/ndex.php?get=params&get2=params#anchor'));
$this->assertFalse(Validation::url('http://www.domain.com/fakeenco%ode'));
$this->assertTrue(Validation::url('http://www.domain.com/real%20url%20encodeing'));
$this->assertTrue(Validation::url('http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)'));
$this->assertFalse(Validation::url('http://en.(wikipedia).org/'));
$this->assertFalse(Validation::url('www.cakephp.org', true));
$this->assertTrue(Validation::url('http://www.cakephp.org', true));
$this->assertTrue(Validation::url('http://example.com/~userdir/'));
}
示例9: location
/**
* Checks if path is within given locations
*
* @param string $check Absolute path
* @param mixed $allow True or * allows any location,
* an array containing absolute paths to locations
* @return boolean
*/
function location($check, $allow = false)
{
$allow = self::_normalize($allow);
if ($allow === true) {
return true;
} elseif ($allow === false) {
return false;
}
if (!is_array($allow)) {
$allow = array($allow);
} else {
$allow = array_unique($allow);
}
if (Validation::url($check)) {
foreach ($allow as $path) {
if (preg_match('/^' . preg_quote($path, '/') . '/', $check)) {
return true;
}
}
} elseif (MediaValidation::file($check, false)) {
$check = dirname($check);
if (!Folder::isAbsolute($check)) {
return false;
}
$Check = new Folder($check);
foreach ($allow as $path) {
if (!Folder::isAbsolute($path) || Validation::url($path)) {
continue;
}
if ($Check->inPath($path)) {
return true;
}
}
}
return false;
}
示例10: testInvalidUrlWithoutPrefix
/**
* @testdox url should return false to URLs without protocol
*/
public function testInvalidUrlWithoutPrefix()
{
$value = 'spaghettiphp.org/download#download';
$this->assertFalse(Validation::url($value));
}
示例11: __cleanOptions
/**
* Sanitize the options array
*
* @param array $options Array of options, keyed from default settings
* @return array Clean options array
* @access public
*/
public function __cleanOptions($options)
{
if (!isset($options['size']) || empty($options['size']) || !is_numeric($options['size'])) {
unset($options['size']);
} else {
$options['size'] = min(max($options['size'], 1), 512);
}
if (!$options['rating'] || !in_array(mb_strtolower($options['rating']), $this->__allowedRatings)) {
unset($options['rating']);
}
if (!$options['default']) {
unset($options['default']);
} else {
if (!in_array($options['default'], $this->__defaultIcons) && !Validation::url($options['default'])) {
unset($options['default']);
}
}
return $options;
}
示例12: url
/**
* Validates url
*
* @param string string to check
* @param array options for allowing different url parts currently only scheme is supported
*/
static function url($check, $options = array())
{
if (!is_string($check)) {
return false;
}
if (isset($options['scheme'])) {
if (!preg_match('/^(' . implode('|', (array) $options['scheme']) . ':)+/', $check)) {
return false;
}
}
return Validation::url($check);
}
示例13: validateUrl
/**
* Checks if a url is valid AND accessable (returns false otherwise)
*
* @param array/string $data: full url(!) starting with http://...
* @options array
* - allowEmpty TRUE/FALSE (TRUE: if empty => return TRUE)
* - required TRUE/FALSE (TRUE: overrides allowEmpty)
* - autoComplete (default: TRUE)
* - deep (default: TRUE)
* @return bool Success
*/
public function validateUrl($data, $options = [])
{
if (is_array($data)) {
foreach ($data as $key => $url) {
break;
}
} else {
$url = $data;
}
if (empty($url)) {
if (!empty($options['allowEmpty']) && empty($options['required'])) {
return true;
}
return false;
}
if (!isset($options['autoComplete']) || $options['autoComplete'] !== false) {
$url = $this->_autoCompleteUrl($url);
if (isset($key)) {
$this->data[$this->alias][$key] = $url;
}
}
if (!isset($options['strict']) || $options['strict'] !== false) {
$options['strict'] = true;
}
// validation
if (!Validation::url($url, $options['strict']) && env('REMOTE_ADDR') && env('REMOTE_ADDR') !== '127.0.0.1') {
return false;
}
// same domain?
if (!empty($options['sameDomain']) && env('HTTP_HOST')) {
$is = parse_url($url, PHP_URL_HOST);
$expected = env('HTTP_HOST');
if (mb_strtolower($is) !== mb_strtolower($expected)) {
return false;
}
}
if (isset($options['deep']) && $options['deep'] === false) {
return true;
}
return $this->_validUrl($url);
}
示例14: testUrl
/**
* testUrl method
*
* @access public
* @return void
*/
function testUrl()
{
$this->assertTrue(Validation::url('http://www.cakephp.org'));
$this->assertTrue(Validation::url('http://cakephp.org'));
$this->assertTrue(Validation::url('http://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('http://192.168.0.1'));
$this->assertTrue(Validation::url('https://www.cakephp.org'));
$this->assertTrue(Validation::url('https://cakephp.org'));
$this->assertTrue(Validation::url('https://www.cakephp.org/somewhere#anchor'));
$this->assertTrue(Validation::url('https://192.168.0.1'));
$this->assertTrue(Validation::url('ftps://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftps://192.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('ftp://www.cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://cakephp.org/pub/cake'));
$this->assertTrue(Validation::url('ftp://192.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftps://256.168.0.1/pub/cake'));
$this->assertFalse(Validation::url('ftp://256.168.0.1/pub/cake'));
$this->assertTrue(Validation::url('https://my.domain.com/gizmo/app?class=MySip;proc=start'));
$this->assertTrue(Validation::url('www.domain.tld'));
$this->assertFalse(Validation::url('http://w_w.domain.co_m'));
$this->assertFalse(Validation::url('http://www.domain.12com'));
$this->assertFalse(Validation::url('http://www.domain.longttldnotallowed'));
$this->assertFalse(Validation::url('http://www.-invaliddomain.tld'));
$this->assertFalse(Validation::url('http://www.domain.-invalidtld'));
$this->assertTrue(Validation::url('http://123456789112345678921234567893123456789412345678951234567896123.com'));
$this->assertFalse(Validation::url('http://this-domain-is-too-loooooong-by-icann-rules-maximum-length-is-63.com'));
$this->assertTrue(Validation::url('http://www.domain.com/blogs/index.php?blog=6&tempskin=_rss2'));
}
示例15: validateUrlOrAbsolute
/**
* @brief check for urls either /something/here or full
*
* this can be a url relative to the site /my/page or full like
* http://site.com/my/page it can also be empty for times when the selects
* are used to build the url
*
* @todo remove current($field) == '' || as 'notEmpty' works fine
*
* @param array $field the field being validated
* @access public
*
* @return bool is it valid
*/
public function validateUrlOrAbsolute($Model, $field)
{
return current($field) == '' || substr(current($field), 0, 1) == '/' || Validation::url(current($field), true);
}