BetterPHP PHP Library
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: BetterPHP PHP Library
For password check (mainly register etc) is it worth having it so that there are certain 'security' requirements, that the coder of the site sets in the user class? for example, they can set 1 if they need it to be alphanum, or 2 if they need it multicase etc? or should i just let it be anything goes?
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: BetterPHP PHP Library
let it be anything, and we can add some functions to the validate class to check for things like that. Then the developer can just use them if he wants.
Re: BetterPHP PHP Library
Added two functions to the validation file for email addresses and urls. Two things which can be a pain to do well
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: BetterPHP PHP Library
Um, how do we use these to check if they are valid, if not say throw an error?
Im currently doing
is that what i should be doing or?
Im currently doing
$email = $validate->email($email); if($email === 0){ //echo }I feel that is wrong though.
is that what i should be doing or?
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: BetterPHP PHP Library
the validation class should be used staticly
if (validate::email($email) === false){ // invalid email. }
Re: BetterPHP PHP Library
Hello,
I'm gonna try to make some kind of a form builder class. It would allow to easily create HTML forms and automatically include the appropriate validation.
I'm kind of a noob though, so it might take a while to end up with a crappy result
Regards,
CK
I'm gonna try to make some kind of a form builder class. It would allow to easily create HTML forms and automatically include the appropriate validation.
I'm kind of a noob though, so it might take a while to end up with a crappy result
Regards,
CK
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: BetterPHP PHP Library
That could be very useful actually
Just give it your best shot, and we'll help you fix problems, or improve it and such
Just give it your best shot, and we'll help you fix problems, or improve it and such
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: BetterPHP PHP Library
Yep, I'll give it a try. I'm tired of rebuilding form validation each time I make a form. There's gotta be a way to make everything easierbowersbros wrote:That could be very useful actually
Just give it your best shot, and we'll help you fix problems, or improve it and such
EDIT 1
I just found this, a PHP5 class library:
http://sourceforge.net/projects/pacl/
There are some pretty useful things in there Just have a look.
And this in case someone is interested. Some useful things in there too:
http://code.google.com/p/cmclasses/
EDIT 2
// checks to see if $haystack starts with $needle function str_starts_with($needle, $haystack){ $needle_len = strlen($needle); return ($needle_len <= strlen($haystack) && substr($haystack, 0, $needle_len) === $needle); } // checks to see if $haystack ends with $needle function str_ends_with($needle, $haystack){ $needle_len = strlen($needle); return ($needle_len <= strlen($haystack) && substr($haystack, -$needle_len) === $needle); } // checks to see if $haystack contains $needle function str_contains($needle, $haystack){ return (strpos($haystack, $needle) !== false); }Wouldn't it be easier to just use a Regex ? Would be just as easy, don't you think ? Like preg_match('#hello#',$string) would be the same as string_contains('hello',$string).
Re: BetterPHP PHP Library
function str_starts_with($needle, $haystack){ $needle = preg_quote($needle); return (preg_match("#^{$needle}#", $haystack) === 1); }Should work actually. At the time that didn't cross my mind. I would imagine that it would be slower, but will have to test.
Also, for these files it is not about doing something the easiest way, since when you use it, it is already done.
Re: BetterPHP PHP Library
Hadn't thought about speed :/ And also, just afer I wrote that, I realised that I was building classes a little bit the same way, since it gives you the ability to change the code later without having to update applications, which is quite nicejacek wrote: Should work actually. At the time that didn't cross my mind. I would imagine that it would be slower, but will have to test.
Here are some classes I'm working on (gotta start the form class soon too ). Please tell me whether you think this is useful or not Feel free to add any of this to the BetterPHP library if you find it useful or to use this code anywhere. I don't mind
<?php ini_set('display_errors',1); error_reporting(E_ALL); class Validation { const email_pattern = '#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#'; const fr_phone_pattern = '#^0[1-68]([. -]?[0-9]{2}){4}$#'; const url_pattern = '#^(http(|s)|ftp)://([0-9a-z.-_]+:[0-9a-z.-_]+@)?[0-9a-z.-]+\.[a-z]{2,4}(:[0-9]{2,6})?(/.+)?#i'; const date_pattern = '#^((0?[1-9])|([1-2][0-9])|(3[01]))[/\\.-_ ]((0?[1-9])|(1[0-2]))[/\\.-_ ]([0-9]{4})$#'; const alpha_pattern = '#^[a-z]+$#i'; const alnum_pattern = '#^[a-z0-9]+$#i'; public static function email($email) { return (preg_match(self::email_pattern, $email)) ? TRUE : FALSE; } public static function frenchPhone($number) { return (preg_match(self::fr_phone_pattern, $number)) ? TRUE : FALSE; } public static function url($url) { return (preg_match(self::url_pattern, $url)) ? TRUE : FALSE; } public static function date($date) { return (preg_match(self::date_pattern, $date)) ? TRUE : FALSE; } public static function alpha($string) { return (preg_match(self::alpha_pattern, $string)) ? TRUE : FALSE; } public static function alnum($string) { return (preg_match(self::alnum_pattern, $string)) ? TRUE : FALSE; } } class MySQL { private $conn; private $db; private $username; private $password; private $host; private $port; public function __construct($host, $user, $pw, $db, $port = '3306') { $this->username = $user; $this->password = $pw; $this->host = $host; $this->port = $port; $this->db = $db; $this->conn = mysql_connect($this->host . ':' . $this->port, $this->username, $this->password); mysql_select_db($this->db, $this->conn); } } class HtmlHelper { /* New tag * * @created : 8.7.2011 * @function : open a new tag (not self closing), add classes and an ID */ public static function newTag($type = 'div', $classes = NULL, $id = NULL) { $return = '<' . $type; if(is_string($id)) $return .= ' id="' . $id . '"'; if(is_string($classes)) $return .= ' classes="' . $classes . '"'; $return .= '>'; return $return; } /* Close tag * * @created : 8.7.2011 * @function : close any non self closing tag, add structure to the HTML page by adding information about which tag is being closed * * $info : the id or class of the tag that is closed, for example '.myCustomClass' or '#myCustomId' */ public static function closeTag($type = 'div', $info = NULL) { $return = '</' . $type; if(is_string($info)) $return .= '<!-- /' . $info . ' -->'; $return .='>'; return $return; } /* Meta tag * * @created : 8.7.2011 * @function : add any meta tags that have a name and a content attribute */ public static function metaTag($name, $content) { $return = '<meta name="' . $name . '" content="' . $content . '" />'; return $return; } /* Title of the HTML page * * @created : 8.7.2011 */ public static function title($title) { $return = '<title>' . $title . '</title>'; return $return; } /* Favicon * * @created : 8.7.2011 * @function : add a favicon to the page * @filetype: PNG */ public static function favIcon($filePath) { $return = '<link rel="shortcut icon" type="image/png" href="' . $filePath . '" />'; return $return; } /* CSS * * @created : 8.7.2011 * @function : add a new Cascading StyleSheet to the current page, and set the media it should apply to * @filetype : CSS */ public static function css($filePath, $media = 'all') { $return = '<link rel="stylesheet" type="text/css" href="' . $filePath . '" media="' . $media . '" />'; return $return; } /* JS * @created : 8.7.2011 * @function : add a new Javascript file to the current page, and choose whether it should defer or not * @filetype : JS */ public static function js($filePath, $defer = FALSE) { $return = '<script type="text/javascript" src="' . $filePath . '"'; if($defer === TRUE) $return .= ' defer="defer"'; $return .= '></script>'; return $return; } } ?> <!DOCTYPE HTML> <html lang="en" dir="ltr"> <head><?php echo HtmlHelper::title('ConradK - PHP and webdesign amongst other things'); echo HtmlHelper::favIcon('favicon.png'); echo HtmlHelper::metaTag('keywords','ConradK, Conrad Kleinespel, Webdesign tutorials, PHP tutorials, Free PHP code'); echo HtmlHelper::metaTag('description','I make things. I like PHP. If I could marry someone, it would probably be a beautiful Regex '); echo HtmlHelper::css('styles.css', 'screen, print'); echo HtmlHelper::js('custom.js',TRUE); ?></head> <body> <?php ?> </body> </html>
Re: BetterPHP PHP Library
I will add them tomorrow, well look at them tomorrow really, looks good to me though
Re: BetterPHP PHP Library
Great I will be updating them of course. I made these today, but still there is a lot to do. More tomorrow.jacek wrote:I will add them tomorrow, well look at them tomorrow really, looks good to me though
Re: BetterPHP PHP Library
Hey,
If you still need it, ill be glad to help.
Although I do not know much.
Dom
If you still need it, ill be glad to help.
Although I do not know much.
Dom
I can't think of anything witty to put here!
Check out some of my projects on GitHub: https://github.com/DomTC
Check out some of my projects on GitHub: https://github.com/DomTC
Re: BetterPHP PHP Library
Ok, but do you have any particular requests?
I can't think of anything witty to put here!
Check out some of my projects on GitHub: https://github.com/DomTC
Check out some of my projects on GitHub: https://github.com/DomTC
Re: BetterPHP PHP Library
Would some logging scripts be good?
Such as visitors, errors, 404's, hits etc.
If that's wanted i'll get started
Such as visitors, errors, 404's, hits etc.
If that's wanted i'll get started
I can't think of anything witty to put here!
Check out some of my projects on GitHub: https://github.com/DomTC
Check out some of my projects on GitHub: https://github.com/DomTC
- Linkjuice57
- Posts: 23
- Joined: Tue Jul 12, 2011 2:44 pm
Re: BetterPHP PHP Library
Well, I'd personally like to see that. Could learn something from itDomC wrote:Would some logging scripts be good?
Such as visitors, errors, 404's, hits etc.
If that's wanted i'll get started
non-existent PHP newb
Re: BetterPHP PHP Library
DomC wrote:Would some logging scripts be good?
Such as visitors, errors, 404's, hits etc.
If that's wanted i'll get started
Looks like you have your answer to thatLinkjuice57 wrote:Well, I'd personally like to see that. Could learn something from it
I have no requests but this is a community thing so, literally anything.
Re: BetterPHP PHP Library
I'd suggest using the
Oh and I'd suggest you look at CodeIgniter's docs and helpers, their helpers are usually really useful (well, they were when I used CI).
__autoload($class_name) { include $class_name . '.php'; }function rather than doing that include all, including them all will slow page speed which isn't good, especially if they're not all being used.
Oh and I'd suggest you look at CodeIgniter's docs and helpers, their helpers are usually really useful (well, they were when I used CI).