Jump to content

ionicle

Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by ionicle

  1. Here's what I came up with ( it's incomplete, but it's almost there ): The DB file actually does contain a Unix timestamp right now, and it's smaller than the current one. For some reason though, all I'm getting is a blank page. Why is that? I am not quite sure of the timestampState function - what I am basically doing there, is checking if the $recorded_time variable is an integer. <? $current_time = time(); $recorded_time = recordedTime(); $time_difference = $current_time - $recorded_time; $timestamp_state = timestampState($recorded_time); $threshold = "7200"; function recordedTime() { $db_file = 'db_file.txt'; $handle_check = fopen($db_file, "r"); $contents_check = fread($handle_check, filesize($db_file)); fclose($handle_check); return $contents_check; } function timestampState($recorded_time) { if($recorded_time === (int)$recorded_time) { return true; } else return false; } if ($timestamp_state == 'true') { if ($time_difference > $threshold) { echo "Time to erase this value and reset things."; } else { echo "Time to ban everyone."; die(); } } ?>
  2. Figured my plan of action would be the following: 0. declare $current_time and $recorded_time 1. open db file 2. read value in first line of db file 3. determine whether the value is a valid time value 4. if not, continue with the rest of the script 5. if yes, do the following: 5a. calculate difference between $current_time and $recorded_time 5b. if difference is larger than 2 hours, erase contents of db file and continue with the script 5c. if difference is smaller than 2 hours, echo out "404" and die() 6. check whether visitor's IP belongs to the predefined range. if it does, do the following: 6a. erase contents of db file 6b. create a new entry for $recorded_time 6c. echo out "404" and die() How do I go about step 3, specifically? Anyone?
  3. I'm not sure if I got that correctly, but let me clarify this: When a specific IP visits the page, it should start showing that predefined echo value for EVERYONE in the next 2 hours. Not just for the person from that specific IP address. And I am not using a database right now - how do I implement that? Can't I just use a plain .txt file to record the time when that IP visits the page, and just use that value to determine how long it's got left until 2 hours have expired, using time()? And when the 2 hours have expired, auto-erase the entry from the .txt file and start over?
  4. Hey guys and gals! I am currently working on implementing the following functionality in one of my pages: Whenever a person with a specific IP address visits the page, an internal countdown timer of 2 hours should be started. Until that timer is active, the only response from the page ANYONE can get would be a predefined echo value. Once the timer has run out, the normal script execution of the rest of the page should be restored. Any pointers and tips on how to approach that would be greatly appreciated.
  5. This isn't exactly a PHP issue I'm having, but it is indeed related to cURL in a way, so here it goes: How can I convert a cURL/Netscape style cookie into a valid Opera/IE cookie for usage with one of those browsers? Is that even doable?
  6. Turns out JIXO's code works. For some reason though, when I load up a large number of email addies in the arrays, it screws up and spits out a blank result. No clue why. I got another reply on Stackoverflow: <?php function domain($email){ $x=explode('@',$email); return $x[1]; } $list1=array("brym@yahoo.com","gargamel@yahoo.com","grungel@gmail.com","shushlek@hotmail.com","gushterlqk@aol.com","shuslica@web.de");//first list $list2=array("brym@yahoo.com","grungel@gmail.com");//second list $black_domains=array(); foreach($list2 as $l2){ $black_domains[]=domain($l2); } $new_list1=array(); foreach($list1 as $l1){ $domain=domain($l1); if(!in_array($domain,$black_domains)){ $new_list1[]=$l1; }; } print_r($new_list1); //this gives new list ?> That one works like a charm, even with very large lists.
  7. That looks pretty convenient! Thing is, I not only need the entire List 2 to be removed from List 1, but also have all email addresses from List 1, matching with all domain names from List 2, be removed from List 1. array_diff() wouldn't help with that, I guess.
  8. Hey again, everybody. Need help with the solution of yet another task related to php. I have two lists of email addresses - List 1 and List 2, so to say. The entire contents of List 2 is a part of List 1. I would like for PHP to compare both lists and erase all the email addresses out of List 2, that are contained in List 1, plus all the email addresses, located at every domain name, listed within List 2. For instance: List 1: brym@yahoo.com gargamel@yahoo.com grungel@gmail.com shushlek@hotmail.com gushterlqk@aol.com shuslica@web.de List 2: brym@yahoo.com grungel@gmail.com After processing's completed, List 1 should look like this: List 1: shushlek@hotmail.com gushterlqk@aol.com shuslica@web.de How would I go about doing that?
  9. Thank you everyone for the help! Issue was sorted out and everything's working like a charm now.
  10. Last suggestion works perfectly! The only thing I need now is to load a text file into the array, and avoid having to input email addresses manually. <?php // Open the file $filename = "test.txt"; $fp = @fopen($filename, 'r'); // Add each line to an array if ($fp) { $array = explode("\n", fread($fp, filesize($filename))); } //INITIALIZE ARRAYS $emails = $array; $newEmails = array(); $usedDomains = array(); $uniqueDomains = array(); //WHILE THERE ARE EMAILS AVAILABLE, PROCESS THE NEXT RANDOM ENTRY while(!empty($emails)) { //GET RANDOM EMAIL $randomEntryID = array_rand($emails); $randomEntry = $emails[$randomEntryID]; $currentDomain = substr(strrchr($randomEntry, '@'), 1); //UPDATE ARRAYS $newEmails[] = $randomEntry; $usedDomains[] = $currentDomain; unset($emails[$randomEntryID]); } //REMOVE DUPLICATE DOMAINS (ALSO GIVES THE INDEX WHERE THE DOMAIN WAS FIRST USED) $uniqueDomains = array_unique($usedDomains); $uniqueIDs = array_keys($uniqueDomains); //DISPLAY EMAILS OF INTEREST foreach($uniqueIDs as $currID) { print '<div>' . $newEmails[$currID] . '</div>'; } ?> The .txt file contains the following test emails: laina@yahoo.com kochina@yahoo.com brym@gmail.com shushlek@gmail.com kurnica@gmail.com shushlica@yahoo.com However, when I execute the php, I get the following output: kochina@yahoo.com kurnica@gmail.com shushlica@yahoo.com There's only 2 types of domains in those email addresses, and I always get 1 of one domain and 2 of the other, instead of one of each. What am I missing here?
  11. Hey everybody. Trying to figure out how to complete a certain task here, and I am pretty sure it can be done via php. Not sure how to start implementing it though, so any suggestions would be hugely appreciated. What I wanna accomplish is, as follows: Out of a list of email addresses, I would like php to pick ONE RANDOM email address out of every domain name, listed in there, for instance: dave@yahoo.com john@yahoo.com michael@hotmail.com jason@hotmail.com etc. Just one random email addy with a certain domain name ( namely, the part after the @ sign ). The ending result out of the example, listed above, ought to be: dave@yahoo.com jason@hotmail.com That's it, pretty much. Nothing more, nothing less. Open to suggestions on how to start this thing!
  12. By attempting to log in to your Yahoo account from a browser that you've never used before to do so, while having the Secondary Sign-in protection in place. Yahoo seems to set a cookie the first time you sign in to your Yahoo account from a specific browser, and it's a permanent one, even if you're logged out. It doesn't maintain a session, but if it isn't there, Yahoo will request additional verification every time you try to sign in. Using IMAP doesn't bypass the protection - that is when you get the "Notice: Unknown: [AUTHORIZATIONFAILED] Please verify your account at https://login.yahoo.com." message. Both when used in the context of a php script, and by using a regular mail client.
  13. There are 2 separate types of notices - one for Unknown user/pass, and another for Unknown location. I just want to differentiate between them and set up two unique redirects to two different pages, depending on which one of the notices is encountered. What's so complicated about that? I did it by dumping the contents of the "imap_errors" array into a file, then opening and reading it, checking for a certain string, and then doing a redirect based on that ( well, it's an echo in the example above, I will add the header redirect a bit later ). Wouldn't that work? Now the only thing I need is figure out how to configure "fopen" to overwrite the file with the new data every time it's executed, instead of just adding to it.
  14. I changed my code: <?php /* Yahoo connection params */ $hostname = '{imap.mail.yahoo.com:993/imap/ssl}INBOX'; $username = 'user@yahoo.com'; $password = 'password'; /* Initialize connection */ $inbox = @imap_open($hostname,$username,$password); $filename = "imap.txt"; $errors = imap_errors(); for ($i=0; $i<count($errors); $i++) { $file = fopen("$filename", "a"); fputs($file, "$errors[$i]\r\n"); fclose($file); $response = file_get_contents('$filename'); if ($response == '[AUTHORIZATIONFAILED] Incorrect username or password. (#MBR1212) [AUTHORIZATIONFAILED] Incorrect username or password. (#MBR1212) [AUTHORIZATIONFAILED] Incorrect username or password. (#MBR1212) Too many login failures') { echo 'Done.'; } } ?> How do I make sure that, whatever's in "imap.txt", gets overwritten every time the script is run, and not just added to?
  15. Yeah, that should work, since I have full control over the web server and the PHP interpreter on it ( it's basically my home machine ). However, that will simply echo out the result of the IMAP notice - I want the display of that suppressed and, depending on whether it's Notice 1 or Notice 2, redirect either to Page 1 or Page 2, automatically. The redirect itself should not be a problem. The differentiation is what's tripping me up here. I would like the IMAP notice received to be dumped into a text file ( or, ideally, read directly ), and, depending on whether it contains "String A" or "String B", the next script action will be a redirect to either Page 1 or Page 2.
  16. Hey guys! I'm trying to figure out how to customize this piece of PHP code in such a way, so that I can set two specific conditions, based on the PHP error notices that I am receiving. <?php /* connect to yahoo */ $hostname = '{imap.mail.yahoo.com:993/imap/ssl}INBOX'; $username = 'user@yahoo.com'; $password = 'password'; $alerts = imap_alerts() /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to yahoo: ' . $alerts); if ( $inbox === false ) { exit ("Can't connect: " . imap_last_error() ."\n"); } else { echo"Logined:"; //do stuff } ?> What I wanna accomplish is: 1. Connect to the IMAP server. 2. Check if the user/password combo is correct, and if so, log me in ( I got that covered ). 3. If it isn't, I will just be greeted with an IMAP error stating "Too many login failures". 4. If it is, but I am trying to log in from a location that Yahoo doesn't recognize, that is, I have never logged in from there before, I will get the same error. 5. Depending on whether the user/pass combo is incorrect, or the location isn't recognized, redirect the user to either "page1" or "page2". The imap_last_error returns the same error for both cases. The error alerts ( imap_alerts ), however, are different for both cases, and this is where I can differentiate between them. How can I set it up so that when it attempts to log in, and it receives an error notice, containing a certain text string, it would just read that text string ( not displaying the errors at all ), and redirect to either "1" or "2"? IMAP wrong user/pass combo notice: Notice: Unknown: [AUTHORIZATIONFAILED] Incorrect username or password. IMAP unknown location notice: Notice: Unknown: [AUTHORIZATIONFAILED] Please verify your account at https://login.yahoo.com.
  17. I am currently attempting to create a page with cURL instructions that does the following: Take the following link, send a GET request to it, and retrieve the results. http://login.yahoo.com/config/login?login=xxxxxxx&passwd=yyyyyyyy&.done=http://m.yahoo.com/mail xxxxx - username yyyyy - password Easy, right? Not really. Since the page that is to be returned, is designed to automatically log you in your Yahoo Mail inbox. I tried with: <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_AUTOREFERER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_URL => 'http://login.yahoo.com/config/login?login=xxxxxx&passwd=yyyyyyy&.done=http://m.yahoo.com/mail', CURLOPT_USERAGENT => 'something-here' )); $resp = curl_exec($curl); curl_close($curl); echo $resp; ?> I do get a response, but all it's about is the Yahoo Mail login page. It doesn't actually execute the login and retrieve the related Yahoo inbox. How would I go about doing that with cURL?
  18. No worries, I figured it out. I needed to modify a hidden field, and it's working like a charm now. No need for additional cURL-ing.
  19. Hey there guys. My current task has presented me with the challenge of using cURL in order to automatically pass form data to an external script via a Glype proxy server. In a nutshell, I've got: 1. Normal HTML containing the form fields. 2. Browse.php, the main component of Glype. 3. The external script that is about to receive the form data ( I have no control over that one ). What I want to achieve is: Instead of simply passing the form fields by submitting them directly to the external script, do it by forwarding them via the "browse.php" file of Glype instead. I am aware that I would have to format the "action" value of the <form> tag in order to access the external script via the proxy instead. However, when I do that, instead of logging me in ( the form data submitted contains a username and a password, along with some hidden fields ), I get redirected to a login page. That obviously happens because the form data is being posted to browse.php, instead of to the external script, and, since browse.php has no idea it has to be resubmitted to the external script, it simply discards it. How would I go about automatically reposting the form fields data to the external script, and displaying the result via browse.php? I assume that would be achieved using cURL, right?
  20. I am a bit unclear on numbers 3 and 4. How does the submitting page receive the output from the process page, and how does it output it to the user? Any quick example code of how that would be handled?
  21. I see. What if the form contains login data for a webmail interface, it automatically gets submitted to the external script, and a login sequence is initiated? Who will get served with the content upon a successful login - the server, making the request, or the client that is using the form page?
  22. Hey guys, got a question and I'm not really sure about it, so I thought I'd ask. One of the pages on my server contains an ordinary HTML form, that is designed to contact an external script for its form submission. If I open the page, enter the information in the fields manually, and hit "Process", the external script will, naturally, record my own IP address as a visitor. What IP address will it record if I automate the form submission by using a server-side method, such as cURL? Does it record the server's IP address, since the server is sending an automated request to the script, or does it record the client's IP address, as usual?
  23. Yup, that does seem like it's gonna be working. I replaced the example email with: $email = $_POST['email']; where email is the name of the email input field on the submitting page, so it would capture the correct email address. Is that correct? Also, how would you specify a varying "yahoo" domain? So that I can avoid listing all the regional Yahoo domains by hand ( yahoo.de, yahoo.co.uk etc. ). The only constant in that would be "@yahoo." . Gmail doesn't use regional domains, so it wouldn't be an issue.
×
×
  • 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.