Jump to content

alecks

Members
  • Posts

    80
  • Joined

  • Last visited

    Never

Everything posted by alecks

  1. as long as you are using ajax, grab the hash w/ ecma and load the rest of the page from a php script
  2. Never encountered this before until browsing through some code error_reporting(E_ALL & ~E_STRICT); I know what the function is, I'm curious about what & ~E_STRICT does. If it helps, this code has a PHP 5 requirement. Thanks
  3. Whats the point of having static methods then?
  4. Just a bit confused as to how PHP handles static methods; my impression is that they cannot be accessed through an instance ($obj->staticMethod(), only using the scope res op (class::staticMethod(). Is this correct?
  5. Nevermind $('ul.test').children('li').remove();
  6. I have a list (<ul>), and I want to remove the items (<li>s) from within it using jQuery. How do I do it? I tried it this way: JavaScript: $(function() { $('ul.test').remove('li'); }); HTML file: <ul class="test"> <li>List item number one.</li> <li>List item number two.</li> </ul> Thanks!
  7. Will a session ID always have letters in it, so that when tested with is_numeric() it will always come back as false?
  8. I need to clear this up in my mind, because I have heard so many conflicting answers from online references: What is the proper way to retrieve HTTP passed variables (http://www.test.com/index.php?var=foo) within a PHP script? (so that it will work with PHP 6 (register_globals gone))
  9. Consider this query: $query = "SELECT * FROM users WHERE username = ''. $_POST['username'] .''"; The user could send "' OR '1'='1" as their username, which would make the query: $query = "SELECT * FROM users WHERE username = '' OR '1'='1' "; Which would always come back as true (not false) if queried. The user could of course do something even more malicious . What mysql_real_escape_string does is add slashes before the quotes, so they are taken literally, not as parts of the query. $query = "SELECT * FROM users WHERE username = '\' OR \'1\'=\'1\''"; In this query where the input is escaped the username would have to be "' OR '1'='1" in order for the query to come back as true (not false).
  10. that would be a javascript feature, not PHP basically just look at the source code from existing text editors (http://www.kevinroth.com/rte/demo.htm).
  11. That does work; the context I was trying to implement it was within the object instantiation. I wanted to fetch data from a database and then change the array into object vars. Ex: <?php class obj{ function obj($name) { $data = <fetch from database> $this = (object) $data; } } $obj = new obj('name'); ?>
  12. Is there an easy way to turn an associative array into an object? Something like (within the object) : $this = (object) array('bleh'=>'teh'); The above does not work...
  13. $GLOBALS['glob_var'] = 10; $var =& funk(); echo 'SHOULD BE 10: '.$var."<br />\n"; $GLOBALS['glob_var'] = 11; echo 'SHOULD BE 11: '.$var."<br />\n"; function funk() { $ref_var = &$GLOBALS['glob_var']; echo 'SHOULD BE 10: '.$ref_var."<br />\n"; return $ref_var } ???
  14. with global-ized variables or super globals like $GLOBALS it isn't necessary to reference them within a function, ex $my_var = 12345; echo $my_var; function afunc() { global $my_var; $my_var = 23456; } afunc(); echo '<br />'.$my_var; would output 12345 23456 References are useful when passing variables to functions and you want to modify them, ex: $my_var = 12345; echo $my_var; function afunc(&$ref_to_my_var) { $ref_to_my_var = 23456; } afunc($my_var); echo '<br />'.$my_var; will output 12345 23456
  15. what is the error, that you are getting...
  16. If you have a 'time' column filled with timestamps of when the row is added, you can make a query like SELECT * FROM table ORDER BY time DESC LIMIT 1
  17. and here we go... <?php // http://www.phpfreaks.com/forums/index.php/topic,186985.0.html if($getcon = file_get_contents("http://www.fedex.com/Tracking?ascend_header=1&clienttype=dotcom&cntry_code=us&language=english&tracknumbers=222222222222222")) { $one = strpos($getcon, "<!-- BEGIN Scan Activity -->"); $final = substr($getcon, $one); $two = strpos($final, "<!-- END Scan Activity -->"); $final = substr($final, 0, $two); echo $final; } else { echo "Error: Could not connect to page..."; } ?>
  18. OK I just had a quick look at the source of the page you are trying to extract data from, I assume you are trying to get the table that lists status? Well in the source it is nicely surrounded by '<!-- BEGIN Scan Activity -->' and '<!-- END Scan Activity -->', you can use strpos() to find where these are as a string index, and then you can just get the data in between the two.
  19. if you do echo '<textarea style="width: 500px; height: 300px;">'.strip_tags($getcon).'</textarea>'; you can better see what effect strip_tags has had...
  20. The header("Location: ...")s don't do anything but redirect the user to a new page. It validates what data the user has sent using an HTML form and depending on that data it gives an appropriate response. (For example, the first one "!isset($_REQUEST['email'])" checks to see if the user has given his/her email address (if the inverse of the value returned by isset($_REQUEST['email']) is true); if the user hasn't, simply take them back to the original form. It sounds like you are from a C (or like) background; note that PHP does not have header files in the context you are using them; header() refers to the http:// header sent to the clients web browser.
  21. Seems that doing the latter (require_once each time) is a bit faster. Put together some test scripts and made 998 classes, each in their own file, and then timed __autoloading each class and then require_once-ing each class. Here is what I did, specifically. 1. I made a function to generate a file name (and class name) and then looped to make 1000 different php files, and store them in array, name=>file. 2. When it finished making those files, it prints out a string formatted like an array creation string ('something' => 'something else', ...), which I copied to make an array in a new script. 3. For the require_once, I looped through the above array and included each file, immediately afterward adding a new object to an array. 4. I microtimed each file inclusion method individually; here are the results: Note: I had to delete 2 of the classes because they were randomly named 'use' and 'try', which are reserved... I restarted my server after each trial... __autoload each ----------------- 0.115617036819 0.177067041397 0.110083890915 0.134618959427 0.148484945297 require_once each ----------------- 0.124009132385 0.120284080505 0.106649875641 0.103686809542 0.103996038437 Soooo yeah. EDIT: test script stuff class timer { public function timer() { $this->resume = $this->cur_time(); $this->pause = 0; $this->state = TRUE; $this->total = 0; } private function cur_time(){ $time = explode(' ', microtime()); return $time[1].substr($time[0], 1); } public function pause() { if ($this->state) { $this->pause = $this->cur_time(); $this->total = $this->pause - $this->resume; $this->state = FALSE; return $this->total; } } public function resume() { if (!$this->state) { $this->resume = $this->cur_time(); $this->state = TRUE; } } } /* * File gen * function fill($len) { $chars = "abcdefghijkmnopqrstuvwxyz"; $i = 0; while ($i < $len) { $fill = $fill.substr($chars, rand(0,24), 1); $i++; } return $fill; } $huge = array(); $i = 0; while ($i < 1000) { $name = fill(3); if (!file_exists("lots_o_files/".$name.".php")) { $file = fopen("lots_o_files/".$name.".php", "w"); fwrite($file, "<?php class $name { function $name(){} } ?>"); fclose($file); $huge[$name] = $name.".php"; $i++; } } foreach ($huge as $name => $file) { echo "'$name'=>'$file', "; } echo "<br />"; foreach ($huge as $name => $file) { echo "require_once 'lots_o_files/$file';"; } */ // Listed all 998 classes. $classes = array('cmh'=>'cmh.php', 'jnj'=>'jnj.php', 'dur'=>'dur.php', 'hze'=>'hze.php', ....); // __AUTOLOAD TEST $autoload = new timer(); function __autoload($name) { global $classes; require_once 'lots_o_files/'.$classes[$name]; } foreach ($classes as $name => $file) { $class[] = new $name; } echo $autoload->pause(); // REQUIRE ONCE TEST /* $require = new timer(); foreach ($classes as $name => $file) { require_once 'lots_o_files/'.$file; $class[] = new $name; } echo $require->pause(); */
  22. http://127.0.0.1/sites/blogtastic -> http://127.0.0.1/sites/blogtastic/
×
×
  • 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.