Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by Destramic

  1. well i've learned something here had a read and this seems to do the trick on duplicate posts, unless i missed something <?php session_start(); if (isset($_SESSION['form'])) { print_r($_SESSION); print_r($_POST); // use data unset($_SESSION['form']); } else if (isset($_POST['submit'])) { $_SESSION['form'] = $_POST; header("Location: " . $_SERVER['REQUEST_URI']); exit; } else { ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Demo</title> </head> <body> <h1>The Form</h1> <form action="" method="POST"> Some Data: <input type="text" value="some data" name="data" id="data" /><br /> <input name='submit' type="submit" /> </form> </body> </html> <?php } ?>
  2. your not going to achieve $conf->test when selecting multiple rows. i'd stick with $config['test'] mate
  3. doh!...sorry i read something wrong, you are correct....i just got the manuel up a function like this would be great...a loop with preg_match is is then...i'm not sure it's going to save time caching it this way though...time will tell
  4. if i'm correct the PREG_GREP_INVERT allows it to work this way also
  5. i tried that but even then it returns the same array i did just realised that /register/(?P<activation_code>[^\s]+) didnt have a ) at the end still the same problem though $uri = '#^/register/aqwrgj73ffgsegr2h$#'; $routes = array( '/register', '/register/(?P<activation_code>[^\s]+)' ); $match = preg_grep($uri, $routes, PREG_GREP_INVERT); print_r($match);
  6. hey guys i'm currently trying to create a cache system for my router, which i think i'm always there but i'm having a slight problem with preg_grep() here is how it goes...the routes are added Router::add_route('/register', array()); Router::add_route('/register/:activation_code', array()); (this is an example - i wouldnt really need to add two routes for /register page) the routes get added to my router class and then get passed to the route pattern class where the patterns will get phased. <?php namespace Router; use Exception\Exception as Exception; class Route_Pattern { const ROUTE_VARIABLES = '(?<=\/)(?[ahis])(?=?!.*?\{)))?(?:\w++)(?!\{\w+\}))?(?\*)|\{([\w-]+(?:\|[\w-]+)+)*\})?(?<!\/)'; const ROUTE_OPTIONAL_SEGMENTS = '(?:^|\G)[^\[\]]*(\[\/((?:[ahis]??[\w-]+)(?:\[\/((?:[ahis]??[\w-]+)\])?\])(?=\[|$)'; private $_character_types = array( 'i' => '[\d]++', 'a' => '[\dA-Za-z]++', 'h' => '[\dA-Fa-f]++', 's' => '[\w-]++', ); private $_route_pattern; public function phase($route_pattern) { if (is_null($route_pattern)) { throw new Exception('Route Pattern: Route pattern is empty.'); } $this->_route_pattern = $route_pattern; $this->optional_segments(); $this->variables(); return $this->_route_pattern; } private function variables() { $parameters = $this->match(self::ROUTE_VARIABLES, $this->_route_pattern); if ($parameters) { $count = count($parameters[0]); for ($i = 0; $i < $count; $i++) { $match = $parameters[0][$i]; $character_type = $parameters[1][$i]; $parameter = $parameters[2][$i]; $all_variable = $parameters[3][$i]; $static_values = $parameters[4][$i]; if ($static_values) { $replace = '(' . $static_values . ')'; } else { $replace = $this->character_type($character_type); } if ($parameter) { $replace = '(?P<' . $parameter . '>'. $replace . '+)'; } $this->_route_pattern = $this->replace($match, $replace, $this->_route_pattern); } } return $this->_route_pattern; } private function optional_segments() { $parameters = $this->match(self::ROUTE_OPTIONAL_SEGMENTS, $this->_route_pattern); if ($parameters) { $count = count($parameters[0]); for ($i = 0; $i < $count; $i++) { $match = $parameters[1][$i]; $segment1 = $parameters[2][$i]; $segment2 = $parameters[3][$i]; $replace = '(/' . $segment1; if ($segment2) { $replace .= '/' . $segment2; } $replace .= ')?'; $this->_route_pattern = $this->replace($match, $replace, $this->_route_pattern); } } return $this->_route_pattern; } private function character_type($character_type = null) { if (isset($this->_character_types[$character_type])) { return '(' . $this->_character_types[$character_type] . ')'; } return '[^\s]'; } private function replace($search, $replace, $subject) { $search = '#' . preg_quote($search) . '#'; return preg_replace($search, $replace, $subject, 1); } private function match($pattern, $subject) { $pattern = '#' . $pattern .'#'; if (preg_match_all($pattern, $subject, $matches)) { return $matches; } return false; } } uri: /register/aqwrgj73ffgsegr2h route pattern /register/:activation_code route pattern phased: /register/(?P<activation_code>[^\s]+ so i decided i'd cache the phased route pattern and use preg_grep (which i'm new to) to match the uri to a single pattern. now here is the problem at hand $uri = '/register/aqwrgj73ffgsegr2h'; $routes = array( '/register', '/register/(?P<activation_code>[^\s]+' ); $match = preg_grep($uri, $routes, PREG_GREP_INVERT); print_r($match); which returns Array ( [0] => /register [1] => /register/(?P<activation_code>[^\s]+ ) so my question is why is key 0 (/register) present? as its not even a match what i'd expect to have matched is /register/(?P<activation_code>[^\s]+ any help on this or my methods would be greatly appreciated...thanks guys
  7. i only gone and nailed it #/([ahis])?(\w+))?(?\(([\w-+]+(?:\|[\w-]+)+)*\))|(\*)|(?<=:\w))(?![^\[\]]*\])# thanks you for pointing me into the right direction requinix
  8. that is what i need...i come up with: #(?<=/)([ahis])?(?:(\w+))?\(([\w-]+(?:\|[\w-]+))*\)|((\w+))?\*)|\w+))(?![^\[\]]*\])# which is a bit spicy...i don't like how i've had to add (\w+)) to every options, also a:var(a) will come with a match althoght it shouldn't i think i'm gonna stop over complicating the pattern and just do each pattern individually thank you for your help again on this matter
  9. sorry i meaning zero or one time ---> ? this returns my match perfectly $pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/news/:action(add|delete|edit)/:type', $matches)) { print_r($matches); } but becuase of the ? zero or one, this subject (/test[/hello[/bye]]) will return matches because of the / $pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/test[/hello[/bye]]', $matches)) { print_r($matches); } what i'm asking is there a way of making my pattern look for: /(with at least one of the zero or one groups) or else don't match i just don't want the regex pattern to match on a / hope i made myself a bit more clearer thank you
  10. is the directory you trying to move the file to writable? or does the dir exist?...do you have any errors?
  11. in my regex pattern i have a lot of none or many operators (?) , which has caused a bit of a problem, as a string containing a forward slash will come back with a result. (?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\]) is it possible to match with a string containing at lease on for the one or many groups? and not just a forward slash? $pattern = '#(?<=/)(([ahis]?)\w+))?(\(([\w-]+(?:\|[\w-]+)*)\))?(\*)?(?![^\[\]]*\])#'; if (preg_match_all($pattern, '/news/:action(add|delete|edit)/:type', $matches)) { print_r($matches); // wanted match } if (preg_match_all($pattern, '/test[/hello[/bye]]', $matches)) { print_r($matches); // unwanted match } i'm not able to find evidence that such thing exists, but it's worth an ask. the reason i bundled all of my routing patterns into one regex pattern is so that i have one simple method to phase all route variables. giving me a nice array to work with: Array ( [0] => Array ( [0] => / [1] => /:action(add|delete|edit) [2] => /:type ) [1] => Array ( [0] => [1] => :action [2] => :type ) [2] => Array ( [0] => [1] => [2] => ) [3] => Array ( [0] => [1] => action [2] => type ) [4] => Array ( [0] => [1] => (add|delete|edit) [2] => ) [5] => Array ( [0] => [1] => add|delete|edit [2] => ) [6] => Array ( [0] => [1] => [2] => ) ) private function variables() { $pattern = self::ROUTE_VARIABLES; $parameters = $this->match($pattern); if ($parameters) { $count = count($parameters[0]); $route_split = explode('/', $this->_route); $uri_split = explode('/', $this->_uri); for ($i = 0; $i < $count; $i++) { $match = $parameters[0][$i]; $type = $parameters[2][$i]; $name = $parameters[3][$i]; $key = $this->array_search($match, $route_split); if (!isset($uri_split[$key])) { return false; } $value = $uri_split[$key]; if (!empty($parameters[5][$i])) { $values = explode('|', $parameters[5][$i]); if (!in_array($value, $values)) { return false; } else if (empty($name)) { $this->_route = $this->replace($match, $value, $this->_route); continue; } } else if (!empty($parameters[6][$i])) { if (empty($parameters[1][$i])) { $this->_route = $this->replace($match, '(.*)', $this->_route); continue; } else { $next_key = $key + 1; if (!isset($route_split[$next_key])) { return false; } $next_value = $route_split[$next_key]; $values = array(); for ($j = $key; $j < count($uri_split); $j++) { if ($uri_split[$j] === $next_value) { break; } $values[] = $uri_split[$j]; } $value = implode('/', $values); } } if ((!empty($type) && !$this->is_type($value, $type))) { return false; } $replace = '(?P<' . $name . '>'. $value . '+)'; $this->_route = $this->replace($match, $replace, $this->_route); } } return true; } thank you
  12. sounds like you havent got jquery included https://developers.google.com/speed/libraries/ latest: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
  13. thanks guys for you replies...just what i'm after! @phscho yours returned an error strange really as my workbench is up to date also i had to turn off safe updates on my mysql workbench...not sure if that is a mysql workbench thing or i would still have gotten the same error if i hadn't of turned off and executed from my php script? thanks again much appreciated
  14. hey guys i'm trying to delete all rows but the latest 6 but i'm having some trouble with the query if you could please help. i've done some reading and have been llooking at simular queries to what i'm after, but i'm not succeeding. here is what i have so far: DELETE FROM benchmarks WHERE ( SELECT count(benchmark_id) FROM benchmarks WHERE name = 'Framework' ORDER BY timestamp ASC ) < 6 the error i get is: any help on where i'm going wrong would be great. thank you guys
  15. wel i feel a lot wiser now...thank you for the breakdown and all your help requinix
  16. for 4:30am you've come up with some good solutions i do like the first option and it does get rid of the bother caused by the brackets and you've openned my mind up to another soltion, thank you...options 2 is what i'm currently doing at the moment. although my regex knowledge is poor could you please explain to me how i can make this pattern match multiple please? $uri = "/i:news_id/:hello"; if (preg_match_all('/^\/(i|a|h)?[A-Za-z0-9_]+)$/', $uri, $parameters)) { print_r($parameters); } thank you for your great information
  17. well my routing system may contain something like this: /search/xbox[/category/:category] matching: /search/xbox /search/xbox/category/consoles so i decided to make my pattern a bit stonger so it match uri vars which are not inside brackets...so yeah my pattern has changed slightly...with the regex in this posts and the others i'm working on i get the problem of matching multiple patterns in the same string...this is my only problem. can you please tell me where i'm going wrong...thank you
  18. i'm sorry for having to post a simular thread but i'm really struggling to get my pattern to work after many attempts...i've tried playing around with it but its just not matching multiple patterns this will work great $uri = "/i:news_id"; if (preg_match_all('/(??!\[\/).)*^\/(i|a|h)?[A-Za-z0-9_]+)$(??!\]))/', $uri, $parameters)) { print_r($parameters); } but when chaging this part of the code it won't work $uri = "/i:news_id/:hello"; examples of matching are: /:test /i:test /a:test /b:test but i only want a match as long as the pattern isn't wrapped inside brakcets [ ] invalid: [/:test] i thought the ^ start and $ end characters would have been all i needed...any advise wouldnt greatful...thank you
  19. brilliant thank you very much requinix. i used this pattern which seems to work fine /(i|s)+:+([A-Za-z0-9_-]\w*)/
  20. hey guys, i'm trying to get back in to the swing of things after a lot of time out from programming, and i'm struggling with this simple regex pattern if i could get some help please. i've decided to go over some of my code and try and re-write things better....starting with my framework. here is my pattern: /^\/?(i|s)?:+([A-Za-z0-9_-])$/ what im trying to do is match: news/i:news_id - returning strings i (if there) and news_id as the string is uri it could contain a forward slash at the beginning. if (preg_match_all('/\/?(i|s)?:+([A-Za-z0-9_-])/', 'my-page/i:foo/:bar', $fixed_parameters)) { print_r($fixed_parameters); } result: Array ( [0] => Array ( [0] => i:f [1] => /:b ) [1] => Array ( [0] => i [1] => ) [2] => Array ( [0] => f [1] => b ) ) idealy what i'd like is a result like this: Array ( [0] => Array ( [0] => i [1] => foo ) [1] => Array ( [0] => [1] => bar ) ) thanks guys
  21. well i have no real exprience what so ever when it comes to api's...but if someone is paying for a key then it makes sense to register the key to a site...ie: phpfreaks.com = phpfreakskey this way you can ensure the key is correct and also that the request for your api is phpfreaks.com, ensuring another site isn't using the key. you'd simply have to create a page www.yoursite.com/api.php?key=phpfreakskey and then validate the key and where the request is sent from....if all checks out then the data can be sent process seems simple to me but i may be overlooking things.. what does your api do exactly?
  22. ok firstly you would need to set a cookie for the page your talking about....here is a example setcookie ('time_visited', time(), 3600, '/' , 'domain.com', true, false); when revisiting this page again you can do something like this: if (isset($_COOKIE['time_visited'])) { $time_visited = $_COOKIE['time_visited']; $last_visited = date('m/d/Y H:i:s', $time_visited); echo "Hi User, you last visited: " . $last_visted; } you may want to look at the manuel here regarding cookies: http://php.net/manual/en/function.setcookie.php i hope this is what you are looking for
  23. although looking further into your script i would leave the encryption of passwords to server side (behind closed doors) your want to be using http://php.net/manual/en/function.password-verify.php and http://php.net/manual/en/function.password-hash.php on your passwords and possibly encrypt the password using aes also before-hand
  24. the reason your form isn't working is because of your formhash js function if you open console in your browser you will see it says which point to this line here: p.value = hex_sha512(password.value); once you sort out you js error the form should submit as intended by your js function
  • 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.