Jump to content

EsOne

Members
  • Posts

    59
  • Joined

  • Last visited

    Never

Everything posted by EsOne

  1. Hello. I am new(er) to PHP, but I think I am learning pretty quickly. You guys have helped me out a few times already. Today I am trying to log/record IPs of visitors. I am not quite sure of the principles behind it, but would like to learn. Both the how and why of it. I have learned to ban certain IPs, but it would only be assuming I know the IP address of the person I am trying to restrict. That code is: <?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (isset($_SERVER['HTTP_VIA'])) { $ip = $_SERVER['HTTP_VIA']; } elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } else { $ip = "Banned"; } $banned = file("banned.txt", "r+"); $nbanned = count($banned); function ban($ip, $banned, $nbanned){ for ($i = 0 ; $i < $nbanned ; $i++) { // Use this if you want to use IP patterns with regular expressions: // if (eregi($ip, $banned[$i])) { // We have to strip the end-of-line characters, to test for equality: if ($ip == rtrim($banned[$i])) { echo "You have been banned from this site, if you feel this is in error "; echo "please send email to *********@***** "; die(); } } } ban($ip, $banned, $nbanned); ?> I'll admit that it was a copy/paste code. Not quite sure what it all does. But, as I said, this only limits people that I know the IP address of. Any help, or patient teaching is appreciated.
  2. That worked as far as centering. However, the "Here's one:" still appears one line above the result echo. I need them both on the same line:
  3. Alright. It seems to not work again. Here is what happens with what you suggested: Here is the exact code I am using. (This does not include the lower end tags (body, php, etc.) as it is only a snippet of my whole page.) <html> <title>Dolphin Mania! The TEXT Version!</title> <head><style> h1{ font-size=14; color=#ff0000; text-align=center; } h2{ font-size=14; color=#ff6600; text-align=center; } </style> </head> <body> <?php echo "<h2>Here's one:</h2>"; $data = file_get_contents('http://www.gaiaonline.com/chat/gsi/index.php?v=json&m=[[6500%2C[1]]%2C[6510%2C[%22129681%22%2C0%2C1]]%2C[6511%2C[%22129681%22%2C0]]%2C[6512%2C[%22129681%22%2C0]]%2C[107%2C[%22null%22]]]&X=1260301935'); $regex = '/"state":"(.+?)","player_count"/'; preg_match($regex,$data,$match); if ($match[1] == 'open') { echo '<h1>Glowing <a href="http://www.gaiaonline.com/tank/9264215/?userEnvironmentId=129681&gsiUrl=www&isInEdit=false&location=popUp&quality=low&version=118&graphicsServer=http://s.cdn.gaiaonline.com/images/Gaia_Flash/aquarium/&isGameActive=false">Click me to play!</a></h1>'; } elseif ($match[1] != 'open') { echo '<h1>Not Glowing</h1>'; } echo "</br>";
  4. Thanks for the reply. The HTML I threw in there (Head, Body, etc.) were not in my actual code like that. I manually added them when typing this post. All tags are closed on my page I am doing. I'll try it, and post results.
  5. I am just starting to learn PHP. I have an easy (if you know much php) problem, that my newb brain can't figure out. I have a code of PHP such as $data = file_get_contents('**URL here**'); $regex = '/"**What I am matching**"/'; preg_match($regex,$data,$match) if ($match[1] == '**Found string**') { echo '**words here <a href="**link here**">**link name here**</a>'; } elseif ($match[1] != '**something**') { echo '**more text here**'; It all works fine and dandy. However. I also am wanting to Make it look pretty. How would I put CSS into that as well? Example: I want the if statement to echo "Some text here", but I do not ant the output to look just simple "Some text here", rather I want "Some text here", and I would like it centered. Also, because I am using this code for different things on my page, I would like it to echo something before the results of the code. Example: Output: Here's one: Some Text Here Oh, here's another: Some Text Here The problem I am coming into is that when I try to put in my CSS on just making "some text here" red, and centered, is that it does not output red and centered. Also, my tags I want to come before each "some text here" ("Here's another one" from above, for example) will center and color properly, however, the "some text here" will not center next to it, but just go to a new line, not centered or colored. For example: Here's one: Some Text Here Instead of: Here's one: Some Text Here Here is an example of code that I am using: <html> <head> <style> h1 { font-size=14; font-color=red; text-align=center; } h2 { font-size=14; font-color=orange; text-align=center; } </style> <?php echo "Here's one:"; $data = file_get_contents('**URL here**'); $regex = '/"**What I am matching**"/'; preg_match($regex,$data,$match); if ($match[1] == '**Found string**') { echo '<h1>**words here <a href="**link here**">**link name here**</h1></a>'; } elseif ($match[1] != '**something**') { echo '<h2>**more text here**</h2>';
  6. :'( Sorry, kind of new to PHP. Care to explain exactly what var_dump does? Also, what would be the proper way to loop this (ex. elseif loop until the $match == 'open')? I know I cannot have it constantly looping, but what would be the proper way to make it loop and re-check the data every 5 minutes or so?
  7. I decided to ask this question here. I have a code that scrapes a page for info, then in turn echos something when a certain data compnent is found in the scrape. <html> <head><?php $data = file_get_contents('http://www.gaiaonline.com/chat/gsi/index.php?v=json&m=[[6500%2C[1]]%2C[6510%2C[%225175269%22%2C0%2C1]]%2C[6511%2C[%225175269%22%2C0]]%2C[6512%2C[%225175269%22%2C0]]%2C[107%2C[%22null%22]]]&X=1260296981'); $regex = '/"state":"(.+?)","player_count"/'; preg_match($regex,$data,$match); var_dump($match); if ($match[1] == 'open') { echo 'Glowing'; } elseif ($match[1] != 'open') { echo "Not Glowing"; } ?></head> <body> </body> </html> This is my code so far. The output of this is: array(0) { } Not Glowing How do I make it echo just the "Not Glowing", or when the correct data is found on the page I am scraping to say JUST "Glowing", instead of having the arrays showing?
  8. <?php if ($match[1] == 'open') { echo 'Glowing'; } ?> But note that $match[1] won't exist when the pattern doesn't match the source, resulting in a thrown notice in those cases. That's possible yes, but problematic. Some servers ban your server's IP if they suspect you're automating a lot of requests. And the script would halt until the state changed to "open", and probably time out, depending on your server settings. A more realistic approach would be to make a request every 5 minutes e.g. Thank you all so much!!! If I may, I have one more set of questions. 1. Now, when it echos "glowing" (I also used "elseif" to make "not glowing") It still echos the arrays. How do I make it to where it only echos the results and not, i.e. "array(0) { } Not Glowing "? 2. badbad, you spoke of a way to parse every 5 minutes or so. How would I be able to do that? I want to thank you all a lot. I am learning slowly on PHP, and a lot of the tutorials I have read go into "What makes it work" but not "why it works", which is how I learn.
  9. You were correct. I changed them back to " and I got this: array(2) { [0]=> string(29) ""state":"open","player_count"" [1]=> string(4) "open" } Array Now, I see the wanted result is in [1], string 4. How would I "if" this to say if [1] = "open" to echo the word "Glowing"? Also, (as I said I was quite new with PHP), would I be able to do an "else" command to make it loop until it is "open"?
  10. Thanks for the quick reply! After using that, I get the following: Fatal error: Call to undefined function: json_decode() in /home/content/e/s/o/esone/html/test/test.php on line 4 So you can see my entire php file, I will put it here now. <html> <head>1. <?php $data = file_get_contents('http://www.gaiaonline.com/chat/gsi/index.php?v=json&m=[[6500%2C[1]]%2C[6510%2C[%22789151%22%2C0%2C1]]%2C[6511%2C[%22789151%22%2C0]]%2C[6512%2C[%22789151%22%2C0]]%2C[107%2C[%22null%22]]]&X=1260293122'); $json = json_decode($data); print_r($json); ?></head> <body> </body> </html> Thanks @cags - Thanks for the reply. I also have tried that, but again no luck. I will switch it back, and reply with the results of that (as I do not have them now)
  11. Ok. I am trying to do a basic scrape and echo results via PHP. I have the information I am trying to scrape, and I think I am using the correct code, but I am not sure, since it is not showing the array of the results when I try it. Here is a section of the page source I am trying to scrape noire","user_id":"3237825","show_in_sig":"1","show_in_profile":1,"last_engine_run":"1260190557","tap_count":"11984","view_count":"10951","total_gold_won":2119743,"env_health":"32166","env_bg_id":null,"env_last_grant_time":"1260190557","inhab_retire":false,"game_info":{"1":{"type":1,"instance_id":"1190571832.1260284818.446690843","open_time":1260292832,"close_time":1260293672,"end_time":1260293732,"length":60,"results_time":1260293742,"state":"open","player_count":6}},"events": The part I am trying to scrape is the "state":"open" I am wanting the $match outcome to show if it is "open" If the code is not "open", the whole line of code disappears. I am testing the code on open games, so I can see if it will come back and tell me the "state" is "open" Here is the code I am using to do this... <?php $data = file_get_contents('http://www.gaiaonline.com/chat/gsi/index.php?v=json&m=[[6500%2C[1]]%2C[6510%2C[%22789151%22%2C0%2C1]]%2C[6511%2C[%22789151%22%2C0]]%2C[6512%2C[%22789151%22%2C0]]%2C[107%2C[%22null%22]]]&X=1260293122'); $regex = '/"state":"(.+?)","player_count"/'; preg_match($regex,$data,$match); var_dump($match); echo $match; ?> Result is coming back: 1. array(0) { } Array Completely not showing the results. I tried scraping another section using the above code, and it did work, but the section that did work did not have any " around it. I am VERY new at PHP, so I am figuring it is something to do with my $regex, and the whole " in the results I am looking for. Also, if I use the if command to say if ($match = "open") echo "glowing"; Would this echo "Glowing" (minus the ") when the match variable is equal to "open"
×
×
  • 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.