Jump to content

marcbraulio

Members
  • Posts

    60
  • Joined

  • Last visited

Everything posted by marcbraulio

  1. The reason being is because I am working on a application that will dynamically generate new emails based on existing emails. Instance: example@example.com will generate exam_Ne3u7Ir@domain.com, "Ne3u7Ir" being a hash of the original email "example@example.com". Understood, I'm not really interested in converting it to Hex as I can further shorten this output if it is numeric. So to clarify, what are the odds of Crc32() producing the same "32-bit integer" for two different emails? 1 in 2^32?
  2. Hi, I am a bit confused about when and how to use crc32(). I am looking for a method to hash email addresses, security is not really important, but the hashes do have to be unique and as short as possible. Originally, I thought that the crc32() function returned a hash with both letters and numbers, but it only seems to return numbers. Instance: crc32('example@example.com'); // output 875998594 crc32('exampleexampleexampleexampleexampleexampleexample@example.com'); // output 1225065599 How is it possible that it will always output a 9-digit or 10-digit no matter the length of the string? What are the chances of collision? For as long as the string is unique will it output a unique 9-digit or 10-digit number? Will it ever output letters as well? I am working on 64-bit system, will this output change in a 32-bit system? I have read a few articles and the php manual on it, but I am still some what clueless if this will in fact fit my needs.
  3. Hello everyone, From a security stand point, what are the differences between these two queries? $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->bindParam(':calories', $calories, PDO::PARAM_INT); $sth->bindParam(':colour', $colour, PDO::PARAM_STR, 12); $sth->execute(); and $calories = 150; $colour = 'red'; $sth = $dbh->prepare('SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour'); $sth->execute(array(':calories' => $calories, ':colour' => $colour)); Essentially they do the same thing, but does the addition of "Bind Parameters" add an extra layer of security? I am currently using the latter method.
  4. Hi, I am trying to store the view rate of articles so that I can retrieve them later on by "the most popular". I have searched around but cannot find a straight answer. Can anyone point me towards the right direction? Edit: Never mind, I was over complicating the logic behind this.
  5. Awesome, I'll definitely check it out. Coincidentally the CMS I am building for my own use is based on my experienced with Joomla and Codeigniter. So far I been using Joomla's way of getting the controller and method, probably should have went towards Codeigniter for that one. The reason I got Joomla's concept involved was because I very much like their folder structure, frontend/backend separation, and system of organizing components and modules while utilizing the MVC architecture, which is something that I really believe Codeigniter is weak in, even with the "HMVC" plugin. I am putting it up on GitHub soon, I'll send you the link if you would like to take a look at it.
  6. Interesting, I am going to do a little more research on that. Many thanks for the great insight, this is exactly what I was looking for.
  7. Thank you for the explanation, some how I thought it was the other way around. I now see that my way would never work unless every link was redirected. Would you know exactly how Wordpress deals with multiple components while still keeping the link free of component declarations? If I understood your post correctly, they either: 1. Assume that for any link without a component declaration, like so: (www.example.com/how-to-use-examples) is automatically referring to the article component and therefore the slug is automatically searched for in the article database, if no article is found an error would show. While every other component would require a component declaration, like so: (www.example.com/store/men-blue-jeans) to avoid being searched for in the article database. or 2. Check each component for the slug, like you posted above: if (slug exists in article component) { .... } else if (slug exists in store component) { .... } else if (slug exists in contact component) { .... } But this method seems to be insanely inefficient, wouldn't you agree? As a side note: I think I'll avoid using IDs as I think that the chances of a duplicate titles will be slim. Besides for 99% of the cases, it wouldn't make any sense for me to create two different articles with the same title. Avoiding duplication in general is a good habit for SEO anyway...
  8. Thank you for the quick reply This is a response to which question? I am aware of that, that's what I meant by "Finally remove 'index.php?comp=article&view=category&id=1&/' from the url using .htaccess", I plan to use mod_rewrite. The slug has to be in the url for mod_rewrite to work with it, am I correct? That's why I am adding it in the second step. I am trying to accomplish this: http://www.example.com/this-title-was-converted-to-a-slug Rather than this: http://www.example.com/article/category/1/ Please let me know if I have this concept wrong.
  9. Hey everyone, I am attempting to find the best method to dynamically create seo friendly urls. This is my plan: Original url: http://www.example.com/index.php?comp=article&view=category&id=1 Make slug from the page's title and add it to url: http://www.example.com/index.php?comp=article&view=category&id=1&/this-title-was-converted-to-a-slug Finally remove "index.php?comp=article&view=category&id=1&/" from the url using .htaccess: http://www.example.com/this-title-was-converted-to-a-slug My questions are: Is there a better strategy/technique for accomplishing this? I have done a lot of research and this seems to be the most popular method. Also since I couldn't do directly put a forward slash right after "&id=1", like so "&id=1/this-title-was-converted-to-a-slug", I went ahead and added a "&" right after the id number, like so "&id=1&/this-title-was-converted-to-a-slug". Is this the correct way of doing this? Any suggestions are appreciated, thank you!
  10. And this is when I exit the room in shame... lol
  11. Simply perfect. Many thanks! Pikachu2000's solution worked out perfectly, but I am curious about this method that you mentioned, could you elaborate by giving me an example? Yeah I was about to say, "isn't technically Pikachu2000's solution a MySQL date function?" lol Thanks anyway!
  12. Well, what do you have on line 1? Check for any missing/misplaced semi-colons, parenthesis, or quotes.
  13. Hello everyone, I am trying to convert dates directly from the database but still keep it within the same array so that I can conveniently access it later on. I am not sure how to explain this better, but I believe the code is pretty self explanatory: $stmt = $this->db->query("SELECT title,slug,content,author_id,created FROM article"); $stmt->setFetchMode(PDO::FETCH_ASSOC); $i = 0; while($var = $stmt->fetch()) { $this->data[] = $var; $this->data[$i]['date'] = date("F j, Y", strtotime($var['created'])); $i++; } print_r($this->data); /* produced array Array ( [0] => Array ( [title] => PHP Security Book [slug] => php-security-book [content] => Lorem ipsum dolor sit amet, consectetur adipisicing elit. [author_id] => 3 [created] => 2012-03-13 12:34:42 [date] => March 13, 2012 ) [1] => Array ( [title] => Something To Do [slug] => somthing-to-do [content] => You know what a dolor sit amet, consectetur adipisicing elit. [author_id] => 3 [created] => 2012-03-13 12:35:46 [date] => March 13, 2012 ) ) */ I access it like so: foreach ($_data as $var) { echo '<h2>' . $var['title'] . '</h2> <br />'; echo '<b>' . $var['date'] . '</b> <br />'; echo '<p>' . $var['content'] . '</p> <br />'; } It works perfectly but my question is: Is there a better or more efficient way to do this? I think that my while loop could use some improvement. I was also thinking of maybe fetching the results into a class using PDO::FETCH_CLASS, but it seems like a bit of a hassle for just one modification.
  14. I am not an expert and the way I learned CRUD was by using PDO prepared statements, so I am not 100% familiar with the original mysql format. But as far as I know, to achieve what you want, you would have to do the following: $stores = array("$MktName", "$address"); mysql_query("INSERT INTO stores (name, address) VALUES("implode(',', $stores)") or die(mysql_error()); Because with your current code you are producing this: mysql_query("INSERT INTO stores (name, address) VALUES('address', '$address') or die(mysql_error()); mysql_query("INSERT INTO stores (name, address) VALUES('name', '$MktName') or die(mysql_error()); And that makes no sense since the Columns have to match the Values. Instance: $stores = array("$MktName", "$address"); mysql_query("INSERT INTO stores (name, address) VALUES("$MktName", "$address") or die(mysql_error());
  15. Understood. Many thanks for all the replies =]
  16. Ok, so a method without a declared visibility is considered public, so why bother declaring "public"? Good practice? To simply make it more readable?
  17. I just have a quick question, what happens if I don't assign a visibility element to methods? In other words, if I just have: class Article_model { public $data; function index() { return $data; } [code=php:0] ...instead of declaring public, private, static, and so on before the function. Will php just consider it public?
  18. Fair enough =]. If you have any preferred articles on database design best practices, please share. Once again thank you.
  19. This is a much more convenient way to do it, thank you! I simply didn't think of doing it that way and you are right, I don't have a need to store mod_position and mod_name under two different keys.
  20. I asked the question above for my general use, but here is a specific example where I would use the assignment of array keys inside a foreach loop, where readability is essential. This is a modular CMS i am building for my personal use. /* * get the itemid of the page else assign it '1' which is the id of the front page. * every page will have an unique item id. * example of url www.example.com/index.php?comp=components&itemid=22 */ if (isset($_GET['itemid'])) { $itemid = $_GET['itemid']; } else { $itemid = 1; } /* * select from columns where the modules status is 1 (enabled) * and the page itemid is equivalent to the page's itemid. */ $sql = "SELECT mod_name, mod_position, mod_item_id FROM module WHERE mod_status = 1 AND mod_item_id = $itemid"; $stmt = $db->query($sql); // fetch results into the modules class for itemid manipulation. $objs = $stmt->fetchALL(PDO::FETCH_CLASS, 'modules'); // break down the results and assign them to a name convention foreach($objs as $obj) { // example: $module_array[nav] = nav $module_array[$obj->mod_position] = $obj->mod_position; // example: $name = nav_module $name = $obj->mod_position . '_module'; // example: $module_array[nav_module] = menu $module_array[$name] = $obj->mod_name; } /* * this specific module position is called nav. * if this position is set the $module_array[nav_module] will call the appropiate module * in this case the $module_array['nav_module'] = menu */ if (isset($module_array['nav'])) //&& in_array($itemid, $module_array['nav_itemid']) ) { echo load_module($module_array['nav_module']); } By the way, if you have a better way of accomplishing this "modular system" please don't hesitate to give me your input.
  21. Well honestly, state/country/zip or even persons have nothing to do with what I am doing. I used "persons" because it was easier to explain and I didn't think this would turn into a table structure issue. But seeing that this is in fact a table structure issue, here is the real scenario: I am building a module based CMS similar to Joomla for my personal use. The numbers on the rows (11, 21, 23, 31) for instance is actually referring to the "itemid" of the page. The link goes as follows: www.example.com/index.php?comp=article&view=category&id=34&itemid=22 The itemid is used by the modules as a reference of when to show up or when to hide. For instance if the page has an itemid=21 and I would like to assign it a "login module", "newsletter module", and "navigation module", I would assign all three of those modules the itemid of 21. And if I wanted to also assign those modules to another page, let's say a page with an itemid of 23, I would assign the three modules to the itemid number of 23, so when I query for "23" all those three modules would show up on that page. So I made the following table: module_id | module_name | module_title | module_status | module_position | module_item_id -------------+-------------------+----------------+--------------------+----------------------+--------------------- 1 | Nav | Main Menu | 1 | nav | 11, 21, 23, 31 But your suggesting that I make another table to reference the itemid to the module's id, correct? Like so: module_id | module_item_id -------------+--------------------- 1 | 11 1 | 21 2 | 23 2 | 31 2 | 44 2 | 56 I would really appreciate your opinion on this. Also if you have any other suggestions on the logic of making this module system work, please let me know.
  22. What if I have a some what large amount of numbers and tables going across like: person | city | state | country | zipcode -------+----- A | 11 | New Jersey | USA | zipcode A | 22 | New Jersey | USA | zipcode A | 44 | New Jersey | USA | zipcode A | 34 | New Jersey | USA | zipcode A | 18 | New Jersey | USA | zipcode A | 23 | New Jersey | USA | zipcode A | 49 | New Jersey | USA | zipcode A | 34 | New Jersey | USA | zipcode A | 10 | New Jersey | USA | zipcode A | 32 | New Jersey | USA | zipcode A | 44 | New Jersey | USA | zipcode A | 34 | New Jersey | USA | zipcode A | 11 | New Jersey | USA | zipcode A | 22 | New Jersey | USA | zipcode A | 54 | New Jersey | USA | zipcode A | 64 | New Jersey | USA | zipcode A | 31 | New Jersey | USA | zipcode A | 52 | New Jersey | USA | zipcode A | 64 | New Jersey | USA | zipcode A | 14 | New Jersey | USA | zipcode B | 12 | New Jersey | USA | zipcode B | 56 | New York | USA | zipcode B | 78 | New York | USA | zipcode B | 98 Is it is really worth it to repeat everything just because of a number? I figure it would be more performance effective to have A | 11, 22, 44, 55, 56, 64, 34, 54 and so on... | New Jersey | USA | zipcode B | 3, 33, 45, 25, 53, 63, 32, 53 and so on... | New Jersey | USA | zipcode That way I only have two rows, but I am no performance expert. Please give me an insight on this.
×
×
  • 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.