Jump to content

dsaba

Members
  • Posts

    724
  • Joined

  • Last visited

    Never

Everything posted by dsaba

  1. echo out this: $users_online_handle = session_save_path(); it might be looking in the wrong directory, it depends on your host/settings might want to look in php info to see directories or echo out the files in this directory with other php directory functions other than glob() to see if it can find them you might be using incorrect syntax with the glob() function try a test run on similar search but in a directory where there are known files and you will know it should return that it found something that's all I can think of at the moment
  2. Hi, I've been thinking a while about this. I have a bunch of experience with posting remotely to forms. I need a way to secure my form on my website from being POSTED too from anywhere other than my own website. Something that cannot be bypassed. There are so many fail attempts/ideas that can be bypassed. Too many to list... So, this is an open thread, if you have an idea describe the method/algorithim. I'll or others will decide if its truly full proof in disallowing anyone from POSTING to from anywhere else other than your form. Anything goes except, HTTPS protocol. Keep in mind I said to disallow people from posting from somewhere else other than your site, and I didn't say to disallow automation. Automation is another thing entirely. It can be a method involving regex, sessions, captchas..whatever.. of course something to do with PHP or JS is preferred... So anyone up to the challenge? Let's see if it can be done. keep in mind that: 1. headers can be easily be manipulated 2. cookies can be injected (although values of cookies might not be able to be changed)
  3. if you're having trouble parsing through something you might want to post this something, so we can see what went wrong when you parsed through it
  4. you don't have to use heredoc syntax.... double quotes should do the trick in echoing variables within html code/strings $var = 'hello world'; echo "<b> $var </b>"; if mixing actual code and not just variables within strings you can try concacetantion echo '<b>'.strtolower('HELLO WORLD').'</b>'; single quotes: 'string'.code.'string'.code.'string' 'string'.code double quotes: "string".code."string".code."string" "string".code
  5. use a foreach loop, running this code might help you understand how it works <?php //the object name is $myObject foreach ($myObject as $key => $val) { //goes through the whole object // you can access each key or title with $key //you can access each value or item with $val echo "$key => $val<br>\r\n"; } ?>
  6. as far as language construct concerns there are no issues doing this, the only issues there are are the person who is coding it, his motives/decisions although I have noticed this bug before in using naming $_POST variables you can't say $_POST['text.moretext'] in PHP 4 I think, last time I checked it changes that into 'text_moretext' , and replaces the dot
  7. dsaba

    regex help

    without regex you can take only the part to the left of the queryString by using explode() <?php $url = 'www.yoururl.com/something/page.php?var=val'; $splitUrl = explode('?', $url); $newUrl = $splitUrl[0]; echo $newUrl; //if url doesn't have any queryString //same code will still work $url = 'www.yoururl.com/something/page.php'; $splitUrl = explode('?', $url); $newUrl = $splitUrl[0]; echo $newUrl; ?>
  8. dsaba

    Screen Scrape

    <?php $str = <<<EOD <tr> <td class="text" width='90' align='right' bgcolor='#f5deb3'>Pickup Date:</td> <td class="text" width='90' bgcolor='#f5f5dc'>12/04/07</td> <td class="text" width='90' align='right' bgcolor='#f5deb3'>Del Date/Time:</td> <td class="text" width='90' bgcolor='#f5f5dc'>* in route *</td> </tr> EOD; $pat = '~Del Date/Time:\</td\> \<td class="text" width=\'90\' bgcolor=\'#f5f5dc\'\>((??!\</td\>).)+)\</td\>~s'; preg_match_all($pat, $str, $out); print_r($out); ?> this works as long as: Del Date/Time:</td> <td ^ end of del/date td tag and next td tag are seperated by 1 space you can change the pattern to suit however else it may be seperated, like with a line break, depending on your data, a good rule of thumb is just to remove all line breaks period from the haystack, and then search data, but it can be done without that as well using $ and ^ or s modifiers.. it really depends how static or not this data you are searching through is coming in.... so you must know details/specifics to make such a decision
  9. to answer your other question: with preg_match_all($pat, $str, $out); where $out is the output array of matches $out[0] will have the complete match with the pattern included $out[1-....] will have substrings that you specify in the pattern to specify these substrings to match simply enclose regex statements in ( ) parenthesis so for example in your original post, to get the substring (of the actual url) to spit out in $out[1] you would say: preg_match_all ("\[url\](.+)\[\/url\]",$text,$matches); ^^ there's the substring enclosed in parenthesis /href=[\'"]((??![\'"]).)+)[\'"]/ ^^^^^^^^^ in the pattern I gave you here it is as the most outer set of parenthesis -happy coding
  10. here's a modified version of my other post to allow single quoted href tags as well <?php $pat = '/href=[\'"]((??![\'"]).)+)[\'"]/'; ?>
  11. try <?php $haystack = '<a id="topofpage" name="topofpage"></a> <ul class="access"> <li><a href="/div/kidspace/" title="Go to the home page of this website. [ALT + 1 Windows, CONTROL + 1 Mac, then press ENTER/RETURN if using IE]" accesskey="1">Go to the home page for this website.</a></li> <li><a href="#startcontent" title="Go to the main content. [ALT + 2 Windows, CONTROL + 2 Mac, then press ENTER/RETURN if using IE]" accesskey="2">Go to the main content for this page.</a></li> <li><a href="#skiptonavigation" title="Go to the main navigation for this page. [ALT + 3 Windows, CONTROL + 3 Mac, then press ENTER/RETURN if using IE]" accesskey="3">Go to main navigation for this page.</a></li> <li><a href="#topofpage" title="Go to the top of this page. [ALT + 4 Windows, CONTROL + 4 Mac, then press ENTER/RETURN if using IE]" accesskey="4">Go to the top of this page.</a></li> <li><a href="/div/sitesearch/" title="Go to the search tool for this website. [ALT + 5 Windows, CONTROL + 5 Mac, then press ENTER/RETURN if using IE]" accesskey="5">Go to the search tool for this website.</a></li> <li><a href="/div/contact/" title="Go to the contact page for this website. [ALT + 6 Windows, CONTROL + 6 Mac, then press ENTER/RETURN if using IE]" accesskey="6">Go to the contact page for this website.</a></li> <li><a href="/div/ask/" title="Go to our Ask A Question reference service. [ALT + 7 Windows, CONTROL + 7 Mac, then press ENTER/RETURN if using IE]" accesskey="7">Go to our Ask A Question reference service.</a></li> <li><a href="/div/accessibility/" title="Go to the accessibility information page for this website. [ALT + 0 Windows, CONTROL + 0 Mac, then press ENTER/RETURN if using IE]" accesskey="0">Go to the accessibility information page for this website.</a></li> '; $leftM = 'href="'; $rightM = '"'; $pat = '~'.$leftM.'((??!'.$rightM.').)+)'.$rightM.'~'; preg_match_all($pat, $haystack, $out); print_r($out); ?> this only works for links enclosed in " double quotes btw
  12. so you were explaining something and then you stopped? bla bla bla, what's this have to do with your question? So I didn't quite understand your problem, you're trying to find urls that have http:// in them twice??
  13. your command came up with a parse error but the format was like this: preg_replace(PATTERN, 'negative', HAYSTACK); ^^^ here is my source of confusion in the manual example they do something like this: $replacement = '${1}1,$3'; how this special format of { } brackets and $ dollar sign works I don't know you did none of this for the replacement, and it came up with a parse error anyways.. so...? from my original post you can see my attempt: ${2}negative why I chose 2 ? because in $out[2] are the captured substrings of negative signs in my original regex
  14. dsaba

    Screen Scrape

    Care to explain more specifically how we can help you? What is your problem and what is the output of $matches ? Posting this information would certainly help see where your problem is, of course you'll have to state what your problem is first.
  15. trying to understand how to use preg_replace() I read this in the manual: <?php $string = 'April 15, 2003'; $pattern = '/(\w+) (\d+), (\d+)/i'; $replacement = '${1}1,$3'; echo preg_replace($pattern, $replacement, $string); ?> the output of that sample regex is: Array ( [0] => Array ( [0] => April 15, 2003 ) [1] => Array ( [0] => April ) [2] => Array ( [0] => 15 ) [3] => Array ( [0] => 2003 ) ) now seeing the example I want to do something similar with this code I made up: <?php $str = '$var = -34; if ($this == -134) { $x = 5 - -9; $b = 7 + -9832; $notThis = 8 - 10; $again = 1234-1234; $here = -9 + 78; }'; $pat = '~[-+=](| )(-)[0-9]+~'; preg_match_all($pat, $str, $out); preg_replace($pat, '${2}negative', $str); output($out,100,100); output($str, 100,100); ?> I get this output for the $out: Array ( [0] => Array ( [0] => = -34 [1] => = -134 [2] => - -9 [3] => + -9832 [4] => = -9 ) [1] => Array ( [0] => [1] => [2] => [3] => [4] => ) [2] => Array ( [0] => - [1] => - [2] => - [3] => - [4] => - ) ) I get this output for the changed $str with preg_replace $var = -34; if ($this == -134) { $x = 5 - -9; $b = 7 + -9832; $notThis = 8 - 10; $again = 1234-1234; $here = -9 + 78; } So you see preg_replace() did not change anything! Apparently I'm not using it correctly. My regex grabs all negative signs, take note I said negative signs and not subtraction signs. I simply want to replace all negative signs in the $str string with the string 'negative' The captured negative signs with my regex can be seen in $out[2] So how can I replace these matched negative signs with the string 'negative' with the preg_replace() function? Also if there is a better way to write my regex pattern for matching negative signs, let me know. I couldn't find a way to say '' or ' ' , (space or null) I used (| ), if i didnt' use the parenthesis it wouldn't catch it, however by using parenthesis it also thinks its a substring, and spits it out in $out[1] which is just a waste, because i'm not really looking for that substring, just the negative Thanks for reading
  16. $str = 'wh*?t do you want to do today? H*re is another *sterisk.'; $symbols = preg_quote('/\*!@#$%^&[](){}-_+=<>.,?~`:;."|\'','~'); //$symbols = '\*\?'; $pat = '~['.$symbols.']*~'; $str = preg_replace($pat, '', $str); echo $str; I get this output: Warning: preg_replace() [function.preg-replace]: Compilation failed: range out of order in character class at offset 29 How can I fix it/get rid of this error? I'm simply trying to use preg_replace() to explicitly get rid all symbols in a string using regex. I realize i can put them into an array with preg_replace(), and what I mean by explicit is that I look for symbols, and if I find them I replace them with nothing ( '' ), so I don't want to say [^a-zA-Z] Thank you
  17. ah I just tried your pattern in a string with duplicates of my original string: $str = 'left marker grab this! right marker distraction left marker grab this! right marker'; $pat = '~left marker((??!right marker).)+)right marker~'; $whatever = preg_match_all($pat, $str, $out); o($out); this does indeed match it, why it didn't match it when there was only one, I didn't know, but if somebody would have told me that it acts this way with only 1 of it, then I would have known sooner.
  18. here are more examples of what i'm trying to accomplish: $str = 'lala grab this! right marker distraction lala grab this! right marker'; $pat = '/lala [^l][^a][^l}[^a]+ right marker/'; $whatever = preg_match_all($pat, $str, $out); print_r($out) THIS doesn't work, why not? //<[^>]+> $str = 'here is some text <em> that is nice </em> this is bold <b> hi </b>'; $pat = '/<[^>]+>/'; $whatever = preg_match_all($pat, $str, $out); print_r($out); This does, i'm trying to mimic this one except with the right marker being more than 1 character, take note this right marker i'm referring to is ">", in the other example, the right marker is the string literal "right marker", I want to grab whats in between the two markers ben $pattern = '/.* (.*?) .*/i'; (.*?) I've seen before but it makes the greediness lazy, which requires backtracking, I'm am looking for a way similar to the "alternative to this" that it was talking about in the tutorial, except by negating a string literal.
  19. I've read some things about efficiency with backtracking effects in greediness and lazyness from the link you supplied me effigy, and other places I've gone... However, I realize I must not know EVERYTHING about this subject, you seemed to know a lot. So this is why I asked you this, not because I was trying to be rude, but because I was trying to learn all that I can. So don't be offended, I suppose in "learning" sometimes there are questions that challenge what the person has said before, but this is done in order to learn. I find that a lot of people get offended too easily when people try to have a conversation where any amount of knowledge gets spread because, one person eventually feels like the other is provoking or questioning his current knowledge at that moment. This probably can be offensive, but it is not meant to be. I said duh, because what you said seemed pretty obvious, i thought there was something more I don't know about. Yes, if there are more instances where one must backtrack in any regex search, then this will reduce the effectiveness of the search. More backtracking = less efficiency. This seemed to be obvious to me, yet again I asked you because maybe there is something else you knew that affects the "efficiency" of the regex related to backtracking. I learn very well through example, and I had given a very specific example of the string and pattern I wanted to match. Why not just tell me the effectiveness that you speak of in my specific example, and by doing this, this can define efficency I was not 100% sure about. This is why I asked you this question. On the pattern, I was trying to match what in between the two markers, hence the string I wanted to grabbed was named so accordingly "grab me!". You must have misunderstood me and though I wanted to match the entire string. No, I didn't. In order for me to learn how to correctly use the metacharacters..etc.. to find matches in between two string literals, it would probably help to see an example of that woudln't it? This is why I asked you again, because your earlier example did not do this. You might as well have said this is the pattern I should be using: /left marker grab this! right marker/ This would have achieved the same results as this would have: /left marker(??!right marker).)+right marker/ You see what I'm getting? I thought it was obvious that I wanted to match the string literal in between the two string literal markers and do this in this "non-bactracking method" and by learning how to "negate an whole literal string" to replicate a pattern similar to what they did in the tutorial I read. I appreciate your help effigy, and I'd really rather not type all these explanations of why I asked things and just get to business in spreading the "knowledge", but you asked me too, and I don't like being accused of something i'm not. Thank you
  20. I wanted to grab/match "grab this!" (..I thought this was pretty obvious) your supplied regex matches the entire string, which is not what i wanted code: $str = 'left marker grab this! right marker'; $pat = '~left marker(??!right marker).)+right marker~'; $whatever = preg_match_all($pat, $str, $out); print_r($out); output: Array ( [0] => Array ( [0] => left marker grab this! right marker ) ) So maybe you can show me something that works please? Also, you say that effectiveness of greediness and lazyness depends.. duh? Well, in my specific example what would you say the effectiveness is?
  21. I know how to negate a single character using a character class like so: [^a] which will mean not "a" I want to negate an entire string literal, not just 1 character, where a string literal will compose of many characters, I know i could probably say it this way: if the string literal is "this" [^t][^h][^i][^s] my question is, is there an easier way to negate a string literal? can't I say this: ^(this) I realize ^ carrot symbol outside of [ ] brackets means start of a new line, so the above will surely cause problems ------------------------------------------------------------------------------- The above is my main question, now here is some some explanation of why I am asking this question, do not be confused by this extra explanation, it is my main question that I wanted answered overall. In a tutorial I read about laziness and greediness, how you can make a pattern not so greedy by making it lazy, yet how this laziness will in effect slow down your regex engine by making it backtrack. So the alternative I read, was to negate something to make it get it right the first time, and not back track. For example an original pattern could be this: Str: This is a <EM>first</EM> test. Pattern: <.+?> This will match the <html> tags , but will cause unneccesary backtracking. So the alternative they give is this: str: This is a <EM>first</EM> test. Pattern: <[^>]+> I want to do the same thing, except to negate an entire string literal instead of a single character Str: left marker grab this! right marker pattern: left marker ^(right marker)+ right marker this is where my question stemmed from. -thanks for reading, remem my main question is most important Thank You
  22. I want to match the "123" whatever 123 this ~whatever .* this~ ~whatever (.){0,50} this~ none of these work, what will?
  23. yay! finally the question/s you've been waiting for! -It's not too specific on "how do I fix bla bla, in my own specific project..bla bla" -Its general enough to help onlookers on regex questions in general -------------------------------------------------------------------------------------- I want to match something like this: <meta name="stapler" content="Whatever 39.32" /> the part that will change that I cannot take literally will be the "39.32" So you can basically think of it like this: literal text - any number of chars less than 50 - literal text sounds pretty easy right? I thought so too. Here's my attempt: $pattern = "~literal text .+{1,50} literal text~"; all I want to say is match any characters and 50 or less of them i've seen it written this way before: (.*?){0,200} the dot means 1 single char of any kind the asterisk means 0 or more of these characters and the question mark means optional of these characters, meaning it can be 0?? instead of putting the ? mark there why not just leave it as: (.*) -- I mean doesn't the 0 or more part basically say its optional too? Since there can be 0 I don't quite get the brackets either if someone could explain, when and when not to use them, i tried saying: .*{0,50} but this gave some repitition error..etc.. -thanks
  24. $pat = '~<head>.*(<b>(.*?)</b>).*</head>~s'; I want to say: look in between <head> </head> match all patterns beginning with <b> and followed by any character and any amount of any characters followed by </b> from the regex tutorial here on phpFreaks I am confused by some of the metacharacters: when I say "~<head>.* i take it to mean start with <head> and must have only 1 of these yet * means 0 or more of these.. I don't see why both of these are together like this
  25. This is the result I get. I want to grab all of them only grabs the last one 'five' and not the rest, how can I make it do that?
×
×
  • 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.