Jump to content

Destramic

Members
  • Posts

    969
  • Joined

  • Last visited

Everything posted by Destramic

  1. hey guys i'm using command prompt to execute the following: httpd.exe -k uninstall but it comes back with i've even removed maria-db as i thought that may have been the problem...no uninstall in c:\apache24 directories also no sign of apache in my add/remove programs listings. does anyone please have any idea on how i can uninstall apache please? thank you
  2. hey guys...I'm currently building a web server and to my excitement I'm reading up about which one is best to install apache or nginx?...or even both? as i imagine a lot of you have your own web server with a load more experience on both engines than me...hopefully can give me a answer into which one i should really choose?...although i am more swayed to use nginx as it supposedly runs the quickest. what i need for my server is a web-socket as well as PHP and MariaDB. hope you guys can give me some good advise. Thanks
  3. works like a dream even works if i put parameters in like so <?php $pattern = "hello[/name/hello[/s:second*]][/bye]"; or $pattern = "hello[/name/hello[/s:second]][/bye]"; or $pattern = "hello[/name/hello[/:second(1|2)]][/bye]"; thank you...you've been a great help
  4. something like this <form method="POST" action="page.php"> Mail: <select name="mail"> <option value="admin@yourdomain">Admin</option> <option value="postmaster@yourdomain">Post Master</option> </select> <input type="submit" name="submit" /> </form> if (isset($_POST['submit'])) { $mail = $_POST['mail']; // send mail }
  5. $value would be the value of the drop down list... but $value would be something like this: $_POST['to']
  6. hey guys i'm having a slight problem with getting the correct match, which i know is down to my regex pattern. with my first result i get [/name/hello[/second] but im after the result of [/name/hello[/second]] with the closing bracket at the end. is it possible for me to match that? $pattern = "hello[/name/hello[/second][/bye]"; if (preg_match_all('/\[(.*?)\]/', $pattern, $matches)) { print_r($matches) } Array ( [0] => Array ( [0] => [/name/hello[/second] // --- > [/name/hello[/second]] [1] => [/bye] ) [1] => Array ( [0] => /name/hello[/second [1] => /bye ) ) thank you
  7. well i think the way you've suggested is more a practical...dunno why i always try to over complicate things. thanks requinix
  8. it doesn't need to be overly strict...it would probably be better if i explained what i wanted to do. ok well for my mvc routing system i want to know if a route i add is a domain or not ie. Router::add_route('shop.bisi.bid', array('controller' => 'shop', 'action' => 'items' )); then i can add that route into a sub domain array hope this explains things a little better...thanks
  9. I'm guessing regex would be best for this as i can't see a php function for the job, but what i want to do is check if a string matches as being a valid domain. does anyone know a good pattern or a better solution to this please? I've seen a lot of patterns when searching but with little experience in regex i wouldn't know which one would be the strongest pattern. thank you
  10. 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');
  11. Yeah that's all good and we'll but error_get_last() doesn't work for php5
  12. 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; } }
  13. Even when triggering a warning error it doesn't return nothing...
  14. 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?
  15. 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
  16. 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
  17. 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"; }
  18. 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...
  19. 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
  20. 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
  21. http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#function_truncate
  22. 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
  23. 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 ) )
  24. worked like a dream thank you...its always fun to find easier ways of doing things
×
×
  • 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.