[PHP] Finding out when a Web page has changed
Hi all, I need to write an application that accepts a list of URLs and checks them on a daily basis (via cron) to see if the pages have changed in the past day. I need some help with this. Does anyone know the most optimal way to find out when a particular Web page has been modified? I am thinking about using the Last-Modified: HTTP header - however, all servers do not return this header - any ideas on what the fallback should be? TIA, Vikram -- "I find your lack of faith disturbing." --Darth Vader -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Finding out when a Web page has changed
>> I need to write an application that accepts a list of URLs and checks them >> on a daily basis (via cron) to see if the pages have changed in the past day. >> >> I need some help with this. Does anyone know the most optimal way to find >> out when a particular Web page has been modified? I am thinking about using >> the Last-Modified: HTTP header - however, all servers do not return this >> header - any ideas on what the fallback should be? > >You could calculate and store the MD5 hash of the page. If the hash is >different the next day, you know the page has been modified. Does this mean that I need to read the entire contents of the HTTP stream into a variable, calculate the hash and store it for comparison? Or is there an easier way to get the MD5 hash? Basically, I'm wondering if there is a way to do this without having to read the entire URL contents via HTTP. Vikram -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Finding out when a Web page has changed
Yup, thought of that one - but it just seems a little sub-optimal ;) Any way to do this without resorting to a brute-force "read the entire file stream over HTTP"? I can't think of one, so I guess I may do it this way after all - but if something occurs to you, or anyone else on the list, please let me know. Thanks for the help :) Vikram >You could cache/save the actual contents of the file, then when you read >it next time, compare it to what you saved and see if it changed. You >may want to filter out everything but what's between and , >so you're not thinking it changed just b/c of something in the >headers... > >---John Holmes... > >> -Original Message- >> From: Vikram Vaswani [mailto:[EMAIL PROTECTED]] >> Sent: Thursday, September 26, 2002 7:04 AM >> To: [EMAIL PROTECTED] >> Subject: [PHP] Finding out when a Web page has changed >> >> Hi all, >> >> I need to write an application that accepts a list of URLs and checks >them >> on a daily basis (via cron) to see if the pages have changed in the >past >> day. >> >> I need some help with this. Does anyone know the most optimal way to >find >> out when a particular Web page has been modified? I am thinking about >> using >> the Last-Modified: HTTP header - however, all servers do not return >this >> header - any ideas on what the fallback should be? >> >> TIA, >> >> Vikram >> -- >> "I find your lack of faith disturbing." >> --Darth Vader >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex for telephone number
Hi! Can someone help me out with a regex to validate a phone number? Thanks Vikram -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Regex for telephone number
Thanks for the reply. I'd like to ensure that numbers entered are in any of these formats: 123 4567 1234567 +91 44 123 4567 +91 44 1234567 91-44-123 4567 91-44-1234567 Number will be a minimum of 5 digits. TIA Vikram At 12:11 AM 1/16/01 +1100, Angus Mann wrote: >At 17:55 15/01/01 +0500, Vikram Vaswani wrote: >>Hi! >> >>Can someone help me out with a regex to validate a phone number? > >We'd need to know what format of telephone numbers you're looking to >validate, first. > >Angus. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] optimal way of counting votes in online poll
Hi all! I have a question as to the optimal method of counting and storing votes in an online poll. Once a user answers the poll by clicking on one of three options, I am performing a query on a table which holds values for each option. Currently I - query the table to get the current count - increment the count by 1 - UPDATE the table with the new value I wonder: what happens if two users submit the answer simulatneously, and the answer is the same. Will only of those votes register? Or will the SQL somehow be "queued" so that both are counted? If the former - is there any other, better way to do this? I am using mySQL as the database, and PHP to process the form and execute the query. Please CC your response to the address above also. TIA Vikram Vaswani -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Job listings DB
Hi, I am designing a system for my company to get employee resumes via the Web, rather than paper. All resumes now go into a mySQL DB, which can be searched by HR (at least that's the theory :) Here are the scripts I will be writing. User pages Listings Descriptions Application form Admin pages --- Add listing Edit listing Delete listing Search for matches --- Now, job description consists of: job code department desig location desc qualification contact posted on salary range (?) Application form consists of: personal information: job code and name first name last name age sex addr 1 addr 2 city state zip country email web site primary phone country code city code local area type - home/work/cell sec. phone SAA willing to relocate?? employment history (last 3 jobs) start end employer job title field of work responsibilities is current employer? skills skill name years of experience references contact person phone email additional info free-form field salary current monetary range current non-monetary benefits expected type of employment trainee freelance full-time would you like your resume to be shared with other departments? My questions: For job listings - how do I design the tables? Can I dump all job listings into a single table, and all applications/resumes into another one? Or should they be normalized? If normalized - how much? For example, in a listing, I have job code, department, location, salary range, etc. - should I have separate tables for each of these? Like jcode deptloc 1 213 2 2 77 3 where dept and loc are FKs to other tables? Or is this taking it too far? Same for application form. All this information that I am getting - should I put into a single table, or split across separate tables? I do plan to search by differenet criteria later. What about items in drop-downs? For example, if I have a drop-down for salary ranges or countries - should this information come from a table, or should I hard-code into the form itself? How do I make the decision as to which is appropriate? Any assistance much appreciated. TIA, Vikram -- Give a homeless man a bundle of firewood, and he'll be warm for one day. Douse him with a gallon of gasoline and set him on fire, and he'll be warm for the rest of his life! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Classes versus native functions
Hi, I was wondering if anyone knew (and could quantify) the performance difference between a script that uses PHP's native XML functions - for example, DOM functions to add/remove nodes - and one that simulates these functions via a class - like the PHP.XPath class. I would assume that simulating it via a class would obviously be slower than the native function - right? But are there any numbers to back this up? Any ideas on how to build a test case to check this? Thanks in advance! Please CC my address above as well as the list if you have a response. Vikram -- Friends help you move. Real friends help you move bodies. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] XSLT error functions
Hi all, Am working with the XSLT functions in PHP. I'm trying to trap errors with the xslt_error() functions - however, the function generates no output even if I deliberately introduce errors into the XSLT sheet. Same goes for the openlog() function. Any one have any ideas how I can use these to generate and log errors? Finally, I don't think the Sablot engine which ships with 4.0.6 supports all the features of the XSLT spec. Any clues on where I can find a list of supported items? TIA, Vikram -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Entity handling in DOM
Hi all, If I have an entity reference in an XML document, which I', parsing with the libxml PHP/DOM parser - does anyone know how I can [1] expand entities and [2] read in and parse external entities? Code would be helpful. :) TIA, Vikram -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] DTD validation with DOM parser
Hi all, Anyone know how to validate an XML document with the PHP DOM/libxml parser? Code would be helpful. :) TIA, Vikram -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] File upload and database optimization questions
Hello all, I'm in the process of building a document-storage system for my firm with PHP. The goal is this is essentially to allow users to upload documents to our server (central repository) and allow other users to view/modify these files. I have a number of questions, most of them related to optimization of the code. Any assistance on these from more experienced developers would be much appreciated. 1. I will be allowing users to upload files of specific types only (DOC, HTML, TXT, images). My original belief (maybe incorrect) was that allowing users to upload scripts (.php, .cgi) was dangerous and should be disallowed. I am now considering whether files, once uploaded, should be renamed - for example, "abc.txt" gets renamed to "01.03.dat", with a reference in the mySQL database containing the real name. First, which of these two approaches is better, performance-wise (or is the difference insignificant)? Second, is it correct to say that if I adopt this "rename-after-upload" approach, I can allow users to upload scripts also (since the file extensions will be changed and no longer recognized as scripts). 2. Once the file is received by the upload script, I am using the followign code to INSERT a record. I then use the insert_id() function to set the new filename as well. Is this approach correct? $query = "INSERT INTO data (category, owner, realname, created, description, comment, view, modify) VALUES('$category', '$SESSION_UID', '$file_name', NOW(), '$desc', '$comment', '$viewStr', '$modifyStr')"; $result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error()); $fileId = mysql_insert_id($connection); $newFileName = $category . "." . $fileId . ".dat"; 3. At the time of upload, it is possible to specify a list of users who can "view" and "modify" the file. Currently I am storing this list as a whitespace-separated list in a mySQL TEXT column. Column "view" data: 3 11 1 At the time of displaying the list, I first SELECT * the entire list of files, and then use explode() in combination with a "for" loop to split up the "view" field and match each element againt the current user's ID. Only if a match is found will I display the filename. I suspect this approach is not optimal. Can anyone suggest a better approach? Any insight into these issues will be much appreciated. Please CC a copy of your response to [EMAIL PROTECTED] as well as the list (as I will be working on this @ home also and do not have access to the full digest there) TIA, Vikram Vaswani -- Sex is like air. It's only a big deal if you can't get any. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Question on manually instantiating a file download
Hello all, I am working on a script which locates a file on the system and then tells the browser to pop open the "Save As" dialog box for download. In order to do this, I am using the following code: $filename = $dataDir . $id . ".dat"; header ("Content-Type: application/octet-stream"); header ("Content-Disposition: attachment; filename=$filename"); readfile($filename); This works fine - however, I would like to redirect the browser to another page once the download is complete (or once it starts). I have tried adding a header("Location:next.php") line to the end of the script above, but it has no effect whatsoever (after the download is complete, the browser displays an hourglass as though waiting for something). Do I need to send some kind of "end-of-download" header...or something else? Can anyone suggest some possible solutions to this problem? Please CC a copy of your response to [EMAIL PROTECTED] as well as the list (as I will be working on this @ home also and do not have access to the full digest there) Any help will be much appreciated. TIA, Vikram Vaswani -- Sex is like air. It's only a big deal if you can't get any. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] PHP and IE5.5 download problem
Hi! I have a script which sends the following headers in order to get the client to display a "file save" prompt. > header ("Content-Type: application/octet-stream"); > header ("Content-Disposition: attachment; filename=$filename"); > readfile($filename); This works well on Netscape/lynx. However, IE 5.5 has a problem with this - I get a message saying that the "file could not be found". Looked around online, some sites say that this is an IE-specific issue with MIME-type recognition. However, I see sites like yahoo and deja allowing users to download email attachments using a similar technique, and that works fine on IE. Any ideas on what I'm doing wrong here? TIA! Vikram -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Using PHP to test if server is online
Hi again, I am writing a PHP script to test if the server on which it is running is currently connected to the Internet. If so, the main page will display a notice saying "We are now online", else it will say "Not connected" Any ideas on how to do this with PHP? I'm guessing it would involve some kind of socket connection... TIA, Vikram -- I took an IQ test, and the results were negative. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Help with DB abstraction layer and Menu class
Hi all, I am developing a simple PHP menu class - the goal is to use PHP and a mySQL database to quickly generate a menu tree. I require some assistance with the database abstraction I am trying to use: My entire menu is stored in a "menu" table containing these fields: id - id of record (AUTOINC) label - name of menu item link - if leaf, where does it link? parent - parent of item in menu tree (0 = root level) Now I have written a PHP class with some functions to help me manipulate this table. Here is the code: hostname, $this->user, $this->pass) or die ("Cannot connect to database"); $ret = mysql_db_query($this->db, $query, $connection) or die ("Error in query: $query"); mysql_close($connection); return $ret; } function create_leaf($link, $label, $parent = 0) { $this->query("INSERT INTO menu(link, label, parent) VALUES ('$link', '$label', '$parent')"); } function create_branch($label, $parent = 0) { $result = $this->query("INSERT INTO menu(label, parent) VALUES ('$label', '$parent')"); } function get_children($id = 0) { $result = $this->query("SELECT id, label, link FROM menu WHERE parent = '$id'"); $children = array(); $count = 0; while (list($id, $label, $link) = mysql_fetch_row($result)) { $children[$count][0] = $id; $children[$count][1] = $label; $children[$count][2] = $link; $count++; } return $children; } function get_child_leaves($id = 0) { } function get_child_branches($id = 0) { } } ?> Here are my problems: 1. As you can see, I am using a function called query() to hold all the database-specific functions. If I change to PG, I need only change the code here and the rest of the class will work as normal. When I use create_leaf() or create_branch(), I would like the query() function to return to me the last INSERT id via mysql_insert_id() function (not happening currently). And when I use the get_children() and other get_* functions, I would like to have the resultset returned as an array (happening fine). How can I tell query() to return different data depending on the type of query being executed ie. for INSERT return id, for SELECT return result identifier 2. Is it necessary to close() the SQL connection at the end of query()? I know this is preferred - however, I was thinking - if I didn't close it, I could write another function get_id() which could use the result identifier $ret and get the INSERT id from it. It is because I am closing the DB connection at the end of query() that other mysql_ functions cannot be run from outside it. 3. What should be put in the constructor here? 4. I would like to release this class to SourceForge as an open-source project. Even if you cannot help me with the questions above - are there any ideas/features/improvements you can suggest that would make it more useful and generic? I am kinda new to PHP :) and your ideas would be very helpful TIA, Vikram -- I took an IQ test, and the results were negative. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] connect() vs. pconnect()
Hi, I need some help with a class that I am writing. class myclass { function query($query) { // connect $connection = mysql_connect($this->hostname, $this->user, $this->pass) or die ("Cannot connect to database"); // run query $ret = mysql_db_query($this->db, $query, $connection) or die ("Error in query: $query"); // return result identifier return $ret; } // function: get label for $id // returns: string function get_label($id) { $query = "SELECT label FROM $this->table WHERE id = '$id'"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } // function: get link for $id // returns: string function get_link($id) { $query = "SELECT link FROM $this->table WHERE id = '$id'"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } // function: execute query $query // returns: result identifier } In this class, I have a query() method which accepts a query and returns a result identifier. All the other class methods use this to run SQL queries. Now, if I had the following code: get_link(29) . ">" . $a->get_label(29) . ""; ?> Would two different connections be opened to the DB for the two method calls? If so, is this optimal? I suspect it is not. Someone has suggested using mysql_pconnect() in my query() method - is this better? Why? If I use pconnect() - how and when will the connection close? Does this happen automatically? TIA, Vikram -- I took an IQ test, and the results were negative. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Connecting to WDDX server in PHP
Hi, I have a script running on a server, which retrieves some values from a DB and encodes them into WDDX. I have another script running on the client, which deserializes WDDX and SAX-parses the XML data. How do I connect the two, so that the client script connects to the server, runs the server script and gets the resulting WDDX packet? Thanks! Vikram -- I wouldn't recommend sex, drugs, and insanity for everyone, but it works for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Passing HTTP_POST from one script to another
Hi, 'nother question: if I have a form which submits data in POST to script "a.php", and I now want to pass this POSTed data to "b.php" - how do I do this? I have tried the technique of iterating through $HTTP_POST and concatenating the key-value pairs into a GET URL, which works perfectly. However, I would like to pass the data from a.php to b.php as POST data, in the HTTP_POST array itself - is this possible, and how do I do it? Thanks! Vikram -- I wouldn't recommend sex, drugs, and insanity for everyone, but it works for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] WDDX recordset data
Can anyone point me to a resource which explains how to iterate through WDDX recordsets with PHP? Thanks! Vikram -- I wouldn't recommend sex, drugs, and insanity for everyone, but it works for me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Finding first/last occurrence of a substring
Hi I have a string like this: Just when you begin to think the wagon of Vietnam-grounded movies is grinding to a slow halt, youre hit squarely in the face with another one. However, while other movies depict the gory and glory of war and its effects, this centres on the psychology of troopers before they're led to battle. I need to know the index position of every occurrence of the pattern "the" in the string above, and replace it with something else. Specifically, I need the position of the last, first and third occurrences of "the". I'm totally lost as to how to do this. Could someone help me out? TIA, Kam - Do you Yahoo!? Yahoo! Mail - You care about security. So do we.