Jump to content

Destramic

Members
  • Posts

    960
  • Joined

  • Last visited

Everything posted by Destramic

  1. yeah that worked a charm thank you....after a bit more reading i discovered setting the register_shutdown_function() in my class seemed to have been the problem. is there, or does anyone know how to use the register_shutdown_function() from a method please? <?php class Error_Handler { protected $_handler; public function __construct() { register_shutdown_function(array($this, 'fatal_error_catcher')); } public function fatal_error_catcher() { $last_error = error_get_last(); if ($last_error['type'] === E_ERROR) { echo "yes"; } } } $error_handler = new Error_Handler; throw new Exception('test');
  2. Yeah that's all good and we'll but error_get_last() doesn't work for php5
  3. here's what i've made just need to add database now...the one problem i did see though is if using a PHP vesion > 5.3 then you're unable to use the error_get_last(): function...therefor being unable to capture any fatal errors which sucks! <?php class Error_Handler { protected $_handler; protected static $_error_reporting; public function __construct($handler = "Unkown") { set_exception_handler(array($this, 'exception_catcher')); set_error_handler(array($this, 'error_catcher')); $this->_handler = $handler; } public function set_error_reporting($error_reporting = true) { if ($error_reporting !== false) { ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(E_ALL); self::$_error_reporting = true; } else { ini_set('display_startup_errors', 0); ini_set('display_errors', 0); error_reporting(0); self::$_error_reporting = false; } } public function debug($name, $data) { $data = $this->desensitize_data($data); if (self::$_error_reporting === true) { if (is_array($data) || is_object($data)) { $data = json_encode($data); } echo "<script>console.log('PHP: " . $name . " - " . $data . "');</script>"; } else { echo "log debug in db."; } } public function log($message, $data) { $handler = $this->_handler; if ($data instanceof Exception) { $traces = $this->trace($data->getTrace()); // log traces // log exception } else { $traces = debug_backtrace(); $traces = array_slice($traces, 3); $traces = $this->trace($traces); // log traces // log exception } } public function exception_catcher($exception) { $this->log('Uncaught Exception', $exception); } public function error_catcher($error_number, $message, $filename, $line, $parameters) { switch ($error_number) { case "2": $type = "E_WARNING"; break; case "8": $type = "E_NOTICE"; break; case "256": $type = "E_USER_ERROR"; break; case "512": $type = "E_USER_WARNING"; break; case "1024": $type = "E_USER_NOTICE"; break; case "16384": $type = "E_USER_DEPRECATED"; break; default: $type = "Unknown"; break; } if (empty($parameters)) { $parameters = null; } else { $parameters = json_encode($parameters); } $this->log($type, array('filename' => $filename, 'line' => $line, 'message' => $message, 'error_number' => $error_number, 'type' => $type, 'parameters' => $parameters )); } protected function trace($data) { $trace_count = count($data); $traces = array(); for ($i = 0; $i < $trace_count; $i++) { if (isset($data[$i]['class'])) { $function = $data[$i]['class'] . $data[$i]['type'] . $data[$i]['function']; } else { $function = $data[$i]['function']; } $function .= "("; $paramters = $data[$i]['args']; $paramter_count = count($paramters); $j = 1; foreach ($paramters as $parameter) { $function .= "'" . $parameter . "'"; if ($paramter_count !== $j) { $function .= ", "; } $j++; } $function .= ");"; $file = $data[$i]['file']; $line = $data[$i]['line']; $traces[] = array ('function' => $function, 'file' => $file, 'line' => $line ); } return $traces; } public function desensitize_data(&$data, $key = null) { if (is_array($data)) { array_walk_recursive($data, array($this, 'desensitize_data')); } else if (preg_match('/(password|pass|pwd|pw)/', $key)) { $data = "*****"; } return $data; } }
  4. Even when triggering a warning error it doesn't return nothing...
  5. yeah i've used mine to catch exceptions also...although i do like the redirect to 500 error page if occurs...the problem is with my code is that when i try to get the last error print_r(error_get_last()); it returns nothing even when there's a error....any idea why?
  6. hey guys i read about being able to catch E_ERROR's using: register_shutdown_function('fatal_error_catcher'); function fatal_error_catcher() { $last_error = error_get_last(); if ($last_error['type'] === E_ERROR) { print_r($last_error); } } now I've tried to test it when triggering but it'll just show a warning message trigger_error('test', E_ERROR); my questions are 1. is it even possible to catch a fatal error?...as a fatal error would be caused by the PHP engine itself, which makes me think it wouldn't execute this error catcher? 2. or is it not catching because you can't manual trigger a E_ERROR. some advise on this would be helpful thank you
  7. is something like this you're after? SELECT v.visitor_id, v.visitor_name FROM visitors v LEFT JOIN users u ON u.visitor_id = v.visitor_id
  8. i come up with the idea of this for getting uri variables...am i just do things the hard way? <?php class Router { protected static $_routes = array(); public static function add_route($method, $uri, $route) { self::$_routes[] = array('method' => $method, 'uri' => $uri, 'route' => $route ); } public function get_routes() { return self::$_routes; } public function is_route() { $routes = $this->get_routes(); $method = $_SERVER['REQUEST_METHOD']; $request = '/login/foo/bar'; //$_SERVER['REQUEST_URI']; foreach ($routes as $route) { $uri = $route['uri']; $uri = str_replace('/', '\/', $uri); $uri = '/^\/' . $uri . '$/i'; // check for :variables if (preg_match_all('/(?<=\w+/', $uri, $parameters)) { $parameters = $parameters[0]; // replace :variables $uri = preg_replace('/:(?<=\w+/', '(.*?)', $uri); } if ($method === $route['method'] && preg_match($uri, $request, $variables)) { unset($variables[0]); if (!empty($parameters) && !empty($variables)) { $parameters = array_combine($parameters, $variables); print_r($parameters); } return true; } } return false; } } Router::add_route('GET', 'login/:test1/:test2', array('contoller' => 'foo', 'action' => 'bar' )); $router = new Router; if ($router->is_route()) { echo "successful route"; } else { echo "page error"; }
  9. yeah everything goes through my index too and i use this in my .htaccess Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?uri=$1 [PT,L,QSA] so i can get the uri from $_GET['uri'] or $_SERVER['REQUEST_URI'];... but have no idea the best way to extract a variable from a route such as items/:item - items/shoes and to return shoes...
  10. hey guys im trying to re-write my framework routing system...which to be honest is a mess. after a bit of reading i see people are using regular expression to match uri's...now what i've done is simplistic at the moment...but im wondering if i'm on the right track and if you guys could give me some useful suggestions please. here is my code i've started <?php class Router { protected static $_routes = array(); public static function add_route($method, $uri, $route) { self::$_routes[] = array('method' => $method, 'uri' => $uri, 'route' => $route ); } public function get_routes() { return self::$_routes; } public function is_route() { $routes = $this->get_routes(); $method = $_SERVER['REQUEST_METHOD']; $request = '/login'; //$_SERVER['REQUEST_URI']; foreach ($routes as $route) { $uri = $route['uri']; $uri = str_replace('/', '\/', $uri); $pattern = '/^\/' . $uri . '$/i'; if ($method === $route['method'] && preg_match($pattern, '/login', $matches)) { return true; } } return false; } } Router::add_route('GET', 'login', array('contoller' => 'foo', 'action' => 'bar' )); $router = new Router; if ($router->is_route()) { echo "successful route"; } else { echo "page error"; } what i'd like to know is how i would go about putting things like this into my url variables - search/:item so i can retrieve :item value set variable - news/:action(add|edit|delete) matching /news/ with add, edit or delete at the end and something like this - items[/test] allowing /items or /items/test to work for a certain route some advice on this would be greatly appreciated...thanks guys
  11. SELECT @latitude := :latitude, @longitude := :longitude, @distance_unit := :distance_unit, @category_id := :category_id, @item := :item, CASE WHEN (@latitude IS NOT NULL AND @longitude IS NOT NULL AND u.latitude IS NOT NULL AND u.longitude IS NOT NULL) THEN @distance := (SELECT (IF(@distance_unit = 'Kilometers', 6371, 3959) * 2 * ASIN(SQRT(POWER(SIN((@latitude- u.latitude) * pi()/180 / 2), 2) + COS(@latitude * pi()/180) * COS(u.latitude * pi()/180) * POWER(SIN((@longitude - u.longitude) * pi()/180 / 2), 2))))) END, @distance_unit := IF (@distance = 1, REPLACE (@distance_unit, 's', ''), @distance_unit), IF (@distance, CONCAT(TRUNCATE(@distance, 2), @distance_unit), 'Unknown') AS `distance`, (SELECT amount FROM user_bids ORDER BY created_timestamp DESC) AS `amount`, i.item_id, i.cover_image_source, i.buy_now, i.title, i.quanity, i.price, i.p_and_p, i.auction, i.condition, (i.price + i.p_and_p) AS `total_price`, CONVERT_TZ(DATE_ADD(i.start_timestamp, INTERVAL concat(i.listing_duration) DAY), '+00:00', '+00:00') AS `end_timestamp`, cu.code AS `seller_currency_code` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.category_id = sc.category_id AND c.category_id = :category_id LEFT JOIN users u ON u.user_id = i.user_id LEFT JOIN currencies cu ON cu.currency_id = u.currency_id WHERE MATCH (i.title, i.description) AGAINST (:item IN BOOLEAN MODE) AND i.start_timestamp < NOW() GROUP BY i.item_id HAVING end_timestamp >= NOW() AND @distance < 50 ORDER BY end_timestamp ASC LIMIT 10 OFFSET 0 having worked thank you
  12. http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_truncate
  13. yeah i used TRUNCATE to round and to display only 2 numbers ending the decimal place...although that isnt the problem... using AND @distance < 5 in the where clause is...basically i want to display items which are withing 5 mile distance only
  14. hey guys here is my query and my only row in my database...i'm having a small problem when i try adding AND @distance < 5 in my where clause...it doesn't display the row...does anyone have any idea why not please? SELECT @latitude := :latitude, @longitude := :longitude, @distance_unit := :distance_unit, @category_id := :category_id, @item := :item, CASE WHEN (@latitude IS NOT NULL AND @longitude IS NOT NULL AND u.latitude IS NOT NULL AND u.longitude IS NOT NULL) THEN @distance := (SELECT (IF(@distance_unit = 'Kilometers', 6371, 3959) * 2 * ASIN(SQRT(POWER(SIN((@latitude- u.latitude) * pi()/180 / 2), 2) + COS(@latitude * pi()/180) * COS(u.latitude * pi()/180) * POWER(SIN((@longitude - u.longitude) * pi()/180 / 2), 2))))) END, @distance_unit := IF (@distance = 1, REPLACE (@distance_unit, 's', ''), @distance_unit), IF (@distance, CONCAT(TRUNCATE(@distance, 2), @distance_unit), 'Unknown') AS `distance`, (SELECT amount FROM user_bids ORDER BY created_timestamp DESC) AS `amount`, i.item_id, i.cover_image_source, i.buy_now, i.title, i.quanity, i.price, i.p_and_p, (i.price + i.p_and_p) AS `total_price`, i.auction, i.condition, CONVERT_TZ(DATE_ADD(i.start_timestamp, INTERVAL concat(i.listing_duration) DAY), '+00:00', '+00:00') AS `end_timestamp`, cu.code AS `seller_currency_code` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.category_id = sc.category_id AND c.category_id = :category_id LEFT JOIN users u ON u.user_id = i.user_id LEFT JOIN currencies cu ON cu.currency_id = u.currency_id WHERE MATCH (i.title, i.description) AGAINST (:item IN BOOLEAN MODE) AND @distance < 5 AND i.start_timestamp < NOW() AND DATE_ADD(i.start_timestamp, INTERVAL concat(i.listing_duration) DAY) >= NOW() GROUP BY i.item_id ORDER BY end_timestamp ASC Array ( [0] => Array ( [@latitude := 51.7328] => 51.7328 [@longitude := -3.0658] => -3.0658 [@distance_unit := ' Miles'] => Miles [@category_id := ''] => [@item := 'xbox'] => xbox [CASE WHEN (@latitude IS NOT NULL AND @longitude IS NOT NULL AND u.latitude IS NOT NULL AND u.longitude IS NOT NULL) THEN @distance := (SELECT (IF(@distance_unit = 'Ki] => 0.000032539954191771116 [@distance_unit := IF (@distance = 1, REPLACE (@distance_unit, 's', ''), @distance_unit)] => Miles [distance] => 0.00 Miles [amount] => [item_id] => 1 [cover_image_source] => xboxone.jpg [buy_now] => 0 [title] => XBOX One [quanity] => 0 [price] => 99.00 [p_and_p] => 0.00 [total_price] => 99.00 [auction] => 1 [condition] => New-Other [end_timestamp] => 2015-07-17 10:51:45 [seller_currency_code] => GBP ) )
  15. worked like a dream thank you...its always fun to find easier ways of doing things
  16. well the user will go to the url which will have a token in it...if token exists then it will unblock account. now i want the user_id so i can send the user to the change password action...I'm passing the user_id as a parameter so if the $user_id parameter is not null in the change password action he/she can change password without logging in. else if null and not authenticated then redirected to log in...if that sounds right i couldnt think of another way of letting the user change password without being authenticated.
  17. is it possible to get the value of user_id when updating a row?..this query works but im struggling to get the user_id (doesnt return a result) UPDATE users SET status = 'Active', token = NULL WHERE token = 'test' AND status = 'Blocked' AND (SELECT user_id as `user_id`) if i'm not able to do it that way then i could use the following, but would be great if i was able to do this all in one query. SELECT LAST_INSERT_ID(); thank you
  18. use the code below of top of your script's while developing...let us know if you get an error of some kind. ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(E_ALL);
  19. thanks for that if (preg_match("/\.html$/i", $file_name)) { ob_start(); extract($this->_variables); require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name; $body = ob_get_contents(); ob_clean(); } $this->_response->append_body($body); solved it now...thanks for your input guys ...much appreciated
  20. well its ob_flush() i need to use...but still getting the return of 1's at the end of the html...so i meant how to sort so it stops showing the 1's?
  21. any ideas on how i can sort this please?
  22. thanks for your post if i use $body = ob_get_contents(); instead then i get no 11 at end of the </html> tag...as for it being the response there's nothing in there that could cause it... =/
  23. hey guys...im having a issue when using ob_flush()...what im getting is a 1 at the end of my html depending on how many templates i render...in this instance i get 11 at the end of my html in the browser, render in my view class: public function render($file_name) { if (preg_match("/\.html$/i", $file_name)) { ob_start(); extract($this->_variables); require_once PRIVATE_DIRECTORY . 'application' . DS . 'views' . DS . $file_name; $body = ob_flush(); } $this->_repsonse->append_body($body); } inside my controller: $this->view->render('template.html'); template.html my header is here <? $this->view->render('content.html') ?> my footer here how the source looks in browser: my header is here content is here my footer here11 any idea why i get 1's after my html when using ob_start() please? thank you
  24. @psycho hit it on the head DELETE FROM sessions WHERE UTC_TIMESTAMP() > DATE_ADD(modified, INTERVAL lifetime SECOND) was so simple...dont even know why i had asked the question...been on this computer everyday after work trying to work on my site for the last year...think i need a couple of weeks off @barand i'm gonna save that query for the future...i'm sure it'll come in handy somewhere along the line thanks guys
×
×
  • 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.