Jump to content

terryds

Members
  • Posts

    174
  • Joined

  • Last visited

terryds's Achievements

Member

Member (2/7)

5

Reputation

  1. What's the best way to sanitize user input ? Is htmlspecialchars() enough ? Or, filter_var() is better? In sanitizing string to avoid XSS, which one performs better, htmlspecialchars() or filter_var() ??
  2. Hmm.. maybe, Facebook uses IP Address to track the location. $_SERVER['REMOTE_ADDR']
  3. How to auto-adjust the time by users' timezone ? Must the user fill the form asking for his/her timezone ? Do browsers send the user timezone information when interacting with the server ? Can we just use PHP to auto-adjust the time ? Or, Do we need javascript ?
  4. What's better ? Using foreign key ON DELETE CASCADE ON UPDATE CASCADE, so it can automatically delete/update the rows. Or... Just manually delete it (using query) ? Please tell me the pros and cons.
  5. My query generates error. (errno:150) CREATE TABLE userrole ( userid BIGINT NOT NULL, roleid INT NOT NULL, PRIMARY KEY(userid,roleid), CONSTRAINT fk_userid FOREIGN KEY (userid) REFERENCES user(user_id), CONSTRAINT fk_roleid FOREIGN KEY (roleid) REFERENCES role(role_id) ) Please tell me how to solve it..
  6. I just want to check which one is faster (isset or strlen) So , I use this code <?php include 'function.speedster.php'; $username = "myusername"; // Using strlen() $code = "if(strlen($username) > 5);"; // This line is what i want to benchmark speedster($code, 10, 'strlen()'); // Using isset() $code = "if(isset($username[4]));"; // This line is what i want to benchmark speedster($code, 10, 'isset()'); Could you please show me the way to benchmark the speed ?
  7. I changed the isset section into // Using isset() $code = "if(isset('$username[4]'));"; speedster($code, 10, 'isset()'); Then, I print out the code if(isset('s')); But, I don't know why error still occurs. Output : if(strlen('myusername') > 5); The time consumed by strlen() method is 0.000248194 seconds. if(isset('s')); ( ! ) Parse error: syntax error, unexpected ''s'' (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11( ! ) Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in C:xampphtdocsterrytesttestersfunction.speedster.php(14) : eval()'d code on line 1 Call Stack # Time Memory Function Location 1 0.0006 135416 {main}( ) ..strlen()_vs_isset().php:0 2 0.0014 140704 speedster( ) ..strlen()_vs_isset().php:11 The time consumed by isset() method is 0.015677929 seconds. Please help me solve this error
  8. I have changed the username variable into "'myusername'" (single quoted in double quote)But, it doesn't solve the problem and the error occurs.Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in C:xampphtdocsterrytesttestersfunction.speedster.php(13) : eval()'d code on line 1Printed out code : if(isset(s));Please help me fix my function.
  9. Thanks for the advice, justsomeguy. Now, I have rewritten the code and it tells me an error (parse error) This is my function <?php function speedster($code="", $repetition=1, $name="this") { $eval_start = microtime(true); for ($i=0; $i < $repetition; $i++) { eval(""); } $eval_time = microtime(true) - $eval_start; $time_start = microtime(true); for ($i=0; $i < $repetition; $i++) { eval($code); } $time_end = microtime(true); $total_time = $time_end - $time_start - $eval_time; printf("<p>The time consumed by $name method is %.9f seconds.</p>", $total_time); } This is how i use it <?php include 'function.speedster.php'; $username = "myusername"; // Using strlen() $code = "if(strlen($username) > 5);"; speedster($code, 10, 'strlen()'); // Using isset() $code = "if(isset($username[4]));"; speedster($code, 10, 'isset()'); And, it gives me this error : Notice: Use of undefined constant myusername - assumed 'myusername' Then, I changed the username variable into "'myusername'" But, it doesn't solve the problem and the error occurs. Parse error: syntax error, unexpected ')', expecting :: (T_PAAMAYIM_NEKUDOTAYIM) in C:xampphtdocsterrytesttestersfunction.speedster.php(13) : eval()'d code on line 1 Please help me fix my function.
  10. The first post has been updated.. Please help me...
  11. I have a php benchmarking function, but it doesn't work as expected. <?php function speedster($arg, $name="") {static $time_start; if($arg == 'start') {echo "<p>The time consumed by $name method is ";$time_start = microtime(true);} elseif ($arg == 'end') {$time_end = microtime(true);$time_ex = $time_end - $time_start;printf("%.9f seconds.</p>", $time_ex);}else {die('Invalid argument');}} This is how i use the code : <?php include 'function.speedster.php'; $password = 'passwordku'; speedster('start','isset()'); if(isset($password[4])); speedster('end'); speedster('start','strlen()'); if(strlen($password) > 5); speedster('end'); And, the result is very different from the one without function (which always tells that isset() is faster than strlen()) <?php $password = 'passwordku'; $timestart = microtime(true); if(isset($password[4])); $timeend = microtime(true); $totaltime = $timeend-$timestart; printf("<p>The time consumed by isset() method is %.9f seconds.</p>", $totaltime) ; $timestart = microtime(true); if(strlen($password) > 5); $timeend = microtime(true); $totaltime = $timeend-$timestart; printf("<p>The time consumed by strlen() method is %.9f seconds.</p>", $totaltime) ;
  12. What is the advantage and disadvantage using persistent connection to MySQL database server ?? When to use it and when not to use it ?
  13. I want to make a child class from the PDO class. I want to count the queries by the parent class, so I make a property called $queries. I'm thinking about if(parent::query) { ++$this->queries }; But, i don't know where to put it. Please, help me.
  14. Yes, i do. So, the illustration is below. I posted an article in my site. The timezone set in the configuration setting is GMT+4 (assume the time is 11:45 A.M.) Then, I want my site visitors in other timezone see that the time i posted the article is adapted by their timezone ( If the man is in GMT+2 timezone, so he will see that the time i posted the article is 9:45 A.M.) Please tell me how to do that Sorry for my bad English skill
×
×
  • Create New...