Jump to content

ShaolinF

Members
  • Posts

    314
  • Joined

  • Last visited

    Never

Everything posted by ShaolinF

  1. When using DateTime() create a date from a string I encounter one problem. In the UK the date is structured as dd/mm/yy but the date method only accepts the mm/dd/yy format. How can I change this ? $date = new DateTime('31/05/10'); // fails $date = new DateTime('05/31/10'); // works
  2. doh, forgot about the mysql function. thanks guys.
  3. The solution is simple, just use a cryptographic hash like SHA2, you will have no collisions. You can use the customer name, RMA primary key id, and a timestamp, hash them and there you have an RMA. If its too long then you can trim it. One major benefit (in this case) is hash calculations are very light on the CPU, you can performs 1000s per second and collisions are extremely extremely unlikely. <?php $rma_primarykey_id = 12831; $customer_name = 'namehere'; $microtime = microtime(); $rma_number = hash('sha256', ($rma_primarykey_id.$customer_name.$time); // 256bits of pure randomness ?>
  4. I have a MySQL column which holds the date in DATETIME format. When I pull it and try and format it in php using the DATE function the times are wrong. See code below: <?php print date("d/m/y @ G:H:s A", strtotime($pt->transaction_date)); ?> Anyone know why this is the case ?
  5. Hi Guys, Theres always been one issue that I just cannot overcome (maybe because I keep pushing it to the backburner). Whenever debugging other peoples code I do the usual var_dump() or print_r() or vars which (sometimes) displays a monolithic array. I just find it very intimdating and can never really figure out whats going on. Is anyone else like this ? Any good reads on how to 'decode' such large arrays ?
  6. That works outside an input value but not inside. <input value="<? echo htmlspecialchars("this is & that");?>" /> Are there any workarounds other than stripping?
  7. Hi Guys, I am trying to use htmlentities and htmlspecialchars to convert a ampersand (&) to the html markup eqivalant (&) to no avail. any ideas ? htmlentities("this is & that");
  8. Yes, I copy/pasted it into my editor. Bare in mind the 'content here' bit being wrapped in the blockquotes will hold data pulled from a WYSIWYG editor. BTW, the space is meant to be there.
  9. Thanks but that didnt work either
  10. Hi Guys I am trying to get some content between some div tags but cannot do so thus far. Code and regex below: <blockquote class="postcontent restore "> content here </blockquote> Regex: /<blockquote class=\"postcontent restore \">(.*?)<\/blockquote>/ Returns nothing.. Any ideas on where I am going wrong ?
  11. Thanks - That does work but what Im trying to do is remove everything other than the href="test.htm" bit. How would I do that ? The only way I can think of doing this is using something like [^(expression here)] but that will match on a per letter basis.
  12. Hi Guys, I have the following URL: <a href="test.test"></a> I want to remove everything except the href="test.test" bit so I did the following: [^(href=\"(.*)\")] but this returns href="e.e". Any ideas?
  13. Hi Guys, Is there anyway I can use the trim() function to remove P tags from the beginning AND end ? So far I can only get it to remove one P tag but not both. trim($content, '<p>'); I tried the following but it didn't work: trim($content, '<p>..</p>'); trim($content, array("<p>", "</p>"));
  14. Hi Guys, I do the following to GET an id: $id = $_GET['id']; There needs to be some filtering/sanitization. I have noticed that many people just cast it as an int and leave it at that. Is that really the best way to approach this issue ? It doesnt look right to me. Im hoping someone can shed some light on this from a secure coding POV.
  15. Hi Guys I have been doing some DB mapping to link two tables to no avail. Everytime I run the code I get the following error: Message: File "Role.php" does not exist or class "Role" was not found in the file Stack trace: #0 C:\wamp\www\zend\library\Zend\Db\Table\Row\Abstract.php(867): Zend_Db_Table_Row_Abstract->_getTableFromString('Role') #1 C:\wamp\www\uw\application\models\admin\User.php(56): Zend_Db_Table_Row_Abstract->findDependentRowset('Role') #2 C:\wamp\www\uw\application\controllers\AdminController.php(110): Application_Model_Admin_User->getUsers() #3 C:\wamp\www\zend\library\Zend\Controller\Action.php(513): AdminController->usersAction() #4 C:\wamp\www\zend\library\Zend\Controller\Dispatcher\Standard.php(289): Zend_Controller_Action->dispatch('usersAction') #5 C:\wamp\www\zend\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 C:\wamp\www\zend\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() #7 C:\wamp\www\zend\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() #8 C:\wamp\www\uwi\public\index.php(26): Zend_Application->run() #9 {main} Code & DB below: application/models/admin/User.php <?php class Application_Model_Admin_User extends Zend_Db_Table_Abstract { protected $_name = 'user'; protected $_dependentTables = array('Role'); public function getUsers() { $rows = $this->fetchAll($this->select()->where('active = ?', 1)); $rows1 = $rows->current(); $rows2 = $rows1->findDependentRowset('Role'); return $rows2; } } application/models/admin/Role.php <?php class Application_Model_Admin_Role extends Zend_Db_Table_Abstract { protected $_name = 'role'; protected $_referenceMap = array ( 'Role' => array( 'columns' => array('id'), 'refTableClass' => 'User', 'refColumns' => array('role_id') ); } DB tables CREATE TABLE role ( id integer auto_increment NOT NULL, name varchar(120), PRIMARY KEY(id) ); CREATE TABLE user ( id integer auto_increment NOT NULL, username varchar(120), PRIMARY KEY(id), FOREIGN KEY(role_id) REFERENCES role(id) );
  16. ShaolinF

    regex help

    Hi Guys I have written some regex which is meant to replace certain BBcode tags with the HTML equiv. It is not working as I intended. See problem and code below: HTML I want to process: [quote][quote=Jack][quote=John]hello mate, how you doing?[/quote] Im fine thanks, you?[/quote] Im good.[/quote] PHP: $searchArray = array( '/(^\[quote=(.*)[\]]|\[quote\])/i', '/\[\/quote\]/i' ); $replaceArray = array( '<div class="quote">', '</div>' ); $message = preg_replace($searchArray, $replaceArray, $message); It should give me this output: <div class="quote"> <div class="quote"> <div class="quote"> hello mate, how you doing? </div> Im fine thanks, you? </div> Im good. </div> But instead I get this: <div class="quote"> [quote=Jack][quote=John]hello mate, how you doing? </div> Im fine thanks, you? </div> Im good. </div>
  17. Hi guys If fetchAll() has been depreciated then what is the alternative ?
  18. Right, Im going to make it so random its going to send the cryptos running for their money.
  19. Hi Guys Do you think the following is an overkill for a salt: $salt = substr(hash('sha256',uniqid(md5(rand()), TRUE)),0,20);
  20. Hi Guys I have setup a form to add users to a mailing list. However, whenever I submit it the action rejects it as its apparantly not using the POST method (when it is). Code attached below: <?php class Application_Form_MailingList extends Zend_Form { public function init() { $frontController = Zend_Controller_Front::getInstance(); $baseUrl = $frontController->getBaseUrl(); $this->setAction($baseUrl.'/index/joinlist') ->setMethod('POST') ->setName('mailingList'); $name = $this->createElement('text', 'name'); $name->addValidator('NotEmpty') ->addValidator('stringlength', false, 3) ->addFilter('StringTrim') ->setRequired(true) ->setLabel('Name'); $email = $this->createElement('text', 'email'); $email->addValidator('NotEmpty') ->addValidator('stringlength', false, 3) ->addFilter('StringTrim') ->setRequired(true) ->setLabel('Email'); $submit = $this->createElement('submit', 'Join List', array('class' => 'btn')); $this->addElements(array($name, $email, $submit)); } } IndexController: Code fails to recognise the POST in the joinlistAction method. I have hand checked the outputted HTML and the form is certainly set to POST. <?php class IndexController extends Zend_Controller_Action { public function indexAction() { $form = new Application_Form_MailingList(); $this->view->form = $form; } public function joinlistAction() { if(!$this->getRequest()->isPost) { return $this->_forward('index'); } } } ?>
  21. Hello ignace, I am curious to know why one would want to extend the Zend_Db_Table_Row_Abstract and Zend_Db_Table_Rowset_Abstract classes when the 'standard' method (i.e. extending Zend_Db_Table_Abstract and using select/insert/update etc) of doing things handles everything automatically ?
  22. Hi Guys, I have the following tag (minus the spaces): [ QUOTE=test ]testes sdfsdf[ /quote ] I have written the following regex which will hopefully get the name 'test' from that tag, see below (minus the space before the quote word): /^\[ quote=(.*)[\]\z]/ However, when I specify the replacement string the regex returns the whole tag instead of just the name: <div class="nm">$1</div> $message = preg_replace('/^\[quote=(.*)[\]\z]/', '<div class="nm">$1</div>', $message); returns: <div class="nm">[ QUOTE=test ]testes sdfsdf[ /quote ]</div> Anyone know where Im going wrong ? . P.S. I have to use preg_replace for this problem.
  23. Hi Guys I am using str_replace to remove userdefined code and replace it with the HTML equivalent. So for example: will be replaced with <strong></strong>. I have come across a problem with tags. The problem is the opening quote tag has the name of the person after the equals sign. For example:
  24. table below: id auto_increment PRIMARY KEY, product_name varchar(233), product_type varchar(100), product_weight varchar(10), date_posted datetime In the preparedstatment I insert the values for product_*, I dont need to bind a param for ID since its auto. Is the same applicable for the date_posted col (i.e. i dont need to bind a param to it since its automatic)?
  25. Hi Guys When executing prepared statements, will one need to also bind parameters for datetime columns in the DB or will the system do it automatically?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.