[PHP] Regex for Advanced search feature
I'm trying to create an advanced search feature for my site, and I have it mostly working the way I want. I take whatever search term ($searchkey) that the user submits, explodes if off any spaces between words, and then use that to search for each word separately. $keys = explode(" ",$searchkey); So the search phrase of: Dog Cat Horse would output : Array ( [0] => Dog [1] => Cat [2] => Horse ) However, I would like to add the ability to have phrases in there indicated by " marks. So, if the search phrase was this: "Dog Cat" Horse It would output: Array ( [0] => Dog Cat [1] => Horse ) My concept to solve this is right before I explode the keys as above, to replace any spaces within " marks with a garbage string of characters (say XX) using a regular expression, and then later replace it back with a space. However, I suck at regular expressions and can't figure it out. Anyone have a way for me to accomplish this with a regular expression or with another method? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
Re: [PHP] count vs mysql_num_rows
Is this a joke? You are using a LIMIT 1, so your count is always going to be 1. No, its not a joke. The answer is not going to always 1, its going to be 1 (the value exists in the DB at least once) or 0 (the value doesn't exist in the DB), that's what I am trying to test for. I don't need to know how many times something exists, just if it does. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326
[PHP] count vs mysql_num_rows
I've got a little function that just checks to see if something is in a mysql db. There are several ways to do this and was curious as to the best way. The following are 2 (simplified) versions that work just fine. If these are the best ways, which of the following is better from a performance standpoint. And if there is a way that is better than one of these, I'd love to know what that is. $query = "SELECT count(id) as count FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1"; $results = mysql_query($query); $row = mysql_fetch_array($results); $count = $row["count"]; return $count; OR $query = "SELECT id FROM wncci_intranet.iAdmin_users WHERE name = '$name' LIMIT 1"; $results = mysql_query($query); $count = mysql_num_rows($results); return $count; Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
Re: [PHP] Re: strpos error (I'm missing something obvious)
Thanks for the info. I've modified the script to reflect that. I actually ended up reversing it, and so I used !== 0 which should work just the same. All this is a minor portion of a much larger security scheme for an intranet site (which is protected by an LDAP server), where I am just trying to keep images outside the web directory, and want to prevent people from linking directly to an image... the only way an image displays is if they view the page, and not link directly to the image. Not foolproof, I know, but I'm not dealing with the general population here, just internal employees some of whom are more computer savvy than others. Thanks all for your help. It seems to be working now. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu. On Oct 2, 2007, at 8:32 AM, Andrew Ballard wrote: I'd suggest the following *slight* enhancement to make sure that the HTTP_REFERER actually *begins* with the site name, not simply contains it. // prevents visits from pages like http://badsite.com/form.htm?http://www.wnc.edu if (strpos($referer, $site) === 0) { echo 'yes'; } (or, if you like the preg solution) if (preg_match("%^$site%", $referer)) { // } However, I'd argue that the effectiveness of checking the referrer itself could be considered "negligible", and hardly "foolproof". The header is easily spoofed in scripts, and may not even be sent at all by legitimate clients because of various browser and/or personal firewall options. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strpos error (I'm missing something obvious)
I fixed this by changing === TRUE to !== FALSE, so I think I am good to go now. But would still like to know why TRUE doesn't work. Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu. On Oct 1, 2007, at 2:23 PM, Kevin Murphy wrote: Overly simplified version of my code. $site = "http://www.wnc.edu";; $referer = $_SERVER["HTTP_REFERER"]; echo $referer; // the output is correct at: http://www.wnc.edu/test/ if (strpos($referer,$site) === TRUE) { echo "yes"; } Why doesn't it echo out "yes"? I know I am doing something stupid here, but it doesn't seem to work :-) -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
[PHP] strpos error (I'm missing something obvious)
Overly simplified version of my code. $site = "http://www.wnc.edu";; $referer = $_SERVER["HTTP_REFERER"]; echo $referer; // the output is correct at: http://www.wnc.edu/test/ if (strpos($referer,$site) === TRUE) { echo "yes"; } Why doesn't it echo out "yes"? I know I am doing something stupid here, but it doesn't seem to work :-) -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
[PHP] Secure Image Storage
Hello all, Following up with my success last week with putting downloadable files in a directory above the web root and then using a combination of fopen and stuff to download the file, I am now trying to do something similar with images. However, what I am trying to do is to put an image file above the web root, then use PHP to display that image in the web page, and not download it. I have the feeling that this isn't possible (all solutions I've seen involve using header() function, which won't work since this is midway down the page), but I wanted to make sure. This will return the binary source of the file: print file_get_contents($file_path); but doesn't display the image. Is there any way to have this (or something else) generate the image? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
Re: [PHP] Re: Strategy for Secure File Storage
Ok, I'm almost there. I took what everyone said (and a few Google searches later) and built this, which works great on Firefox and Safari (both mac and PC). The $path leads to a directory outside the web root, and there is also an array with all the mime types in it ($mimetype). $file_path = $path."/".$file; $ext = explode(".",$file); $filesize = filesize($file_path); $extension = $mimetypes["$ext[1]"]; header("Content-type: $extension"); header("Content-length: $filesize"); header("Content-Disposition: attachment; filename=\"$file\""); header("Pragma: no-cache"); $file = file_get_contents($file_path); echo ($file); The problem is IE7. All browsers work with this code as is but IE says "Internet Explorer cannot download test.pdf from XXX" Any suggestions? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
[PHP] Strategy for Secure File Storage
I'm working on a intranet site that uses an LDAP server to authenticate users and then a integrated CMS (kind of like a wiki with security features so only certain people can post things or upload files) runs the whole thing. (The CMS is custom built with PHP). I've got a need to make certain files secured so that if someone uploads a file they can specify that no one except certain people can view the file. I've got all the security features set up, what I need to do is come up with the best way of securing those files. Obviously the link won't show to those files if the user doesn't have access to it, but I'm worried that someone might know the link and be able to access the file that they are not supposed be able to see. This doesn't need to be NSA level security, but I do need to protect against some computer savvy users. So, I'm pondering the following ideas for hiding those files. Any insight on the best method would be appreciated: 1) Write secure files to MySQL as a blob (only secure files would be written there) 2) Write secure files to the level below the web root and come up with a way of copying the files over to a temporary directory for access, then delete the files as soon as they are accessed. 3) Use Unix passwords to protect a folder in the web level and then the CMS knows the password and can pass the password for access (so that the user doesn't know this password, but the CMS does). 4) Some various forms of link obfuscation, where the CMS goes through all the secure files once an hour or so and rewrites the file name with a random string. 5) Or ???? I'm open to suggestions. Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
[PHP] PHPSESSID in links
I've got a site (password protected, sorry) where I have this in the top of my template: session_start(); $iSessionId = session_id(); $iSessionName = session_name(); Then I have a bunch of links like this in the site: echo "Departments"; The first time, and only the first time you load the page, that link is transformed in the HTML output to be this: Departments But if I reload the page, or go to any other page, I will get this: Departments which is what I want. Obviously I could do something where if it detects the PHPSESSID in the URL, it forces the page to reload, but I was thinking that there would be another way to do this without adding another page load into the mix. Is there? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
Re: [PHP] IE Not Following Header("Location: /path/to/file.php");
Also, turn on error reporting and see if an error is being generated before the header is sent. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu. On Sep 6, 2007, at 11:44 AM, Edward Kay wrote: Scott Wilcox wrote: hey folks. I have a strange problem with IE sometimes. It doesn't seem to accept and follow a header sent to the browser. The action occurs when a user logs in, then is sent this header. Any hints/ideas appreciated. Scott. Get Microsoft's (free) Fiddler Tool and look at the exact info been sent and received: http://www.fiddlertool.com/fiddler/ Edward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] manual vs. meta refresh
On Aug 13, 2007, at 2:16 PM, Richard Lynch wrote: Of course, the question of whether it's a Good Idea to show something different for a manual Refresh versus META refresh springs to mind... I can't see why you'd want to do this for anything other than educational purposes... Well, as the OP, I can first tell you all that I don't actually need to do this anymore quite like this. Basically, what I was trying to accomplish was that I have an application that has access to sensitive student data (like grades and stuff), and I wanted to write it so that it would log you out and display a different screen after a specified period of time just in case the instructor walked away from their computer we didn't want it displaying whatever the instructor was last looking at forever. So what I was doing was refreshing the page every 31 minutes and comparing with the last time the page was accessed (set via a session variable), and if longer than 30 minutes, it would log you out and show you a login form rather than the page you were looking at. The problem came in the fact that if you had 2 windows open simultaneously, the PHP couldn't tell if it was the background window or the front window doing the loading, so therefore it would never log you our. The solution, which came to me from some of the early comments, was to create a new page that the META refresh sent to (logout.php) and then anytime you hit that page, it logs you out. So if the background or foreground window now refreshes and gets sent to that page. Thanks everyone for their help on this. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Date Problem with \n
Small issue with formatting a date. If I type in this: echo date("g:i:s a \o\n l F j, Y"); the "n" character in the word "on" doesn't appear, but instead what I get is a new line in the source code. If I type it as: echo date("g:i:s a \on l F j, Y"); I get the number 8 (current month) where the n is supposed to be. Is there any way to get an "n" in there? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
[PHP] manual vs. meta refresh
I doubt this, but is there any way to determine via PHP if a browser was refreshed automatically via a META tag vs the person clicking the refresh button? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 P.S. Please note that my e-mail and website address have changed from wncc.edu to wnc.edu.
[PHP] Problem with filemtime
I'm running the following script (simplified for discussion) to create a CSV file. My problem here is that the first filemtime and the last filemtime always equal each other. What I am trying to get is the filemtime ($new_last_modified) of the file that was just executed 3 lines earlier. Is there something I need to do differently? I tried putting a sleep(20) after the fclose, but that didn't seem to help. $csv_file = "myFile.csv"; $last_modified_csv = filemtime($csv_file); $fh = fopen($csv_file, 'w') or die("can't open file"); fwrite($fh, "Data Goes Here"); fclose($fh); $new_last_modified = filemtime($csv_file); -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326
Re: [PHP] Checking Phone Numbers
Well, in my context where this is an application to apply to a community college, I think I can safely exclude non-us phone numbers. :-) The code that Robert supplied seems to work just great. Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326 On Jun 14, 2007, at 10:25 AM, Daniel Brown wrote: On 6/14/07, Edward Kay <[EMAIL PROTECTED]> wrote: > -Original Message- > From: Kevin Murphy [mailto:[EMAIL PROTECTED] > Sent: 14 June 2007 16:38 > To: php > Subject: [PHP] Checking Phone Numbers > > > I collect phone numbers via a web form that breaks the phone number > up into 3 parts (3-digit area, 3-digit prefix, etc). Occasionally, I > am having people put in a phone number such as 999-999- or > 000-000- or other numbers that are all the same. How would I go > about comparing those three fields to see if they are all the same > numbers. I can't just exclude it anytime that the numbers all match, > for example 444 is a valid area code. It should only fail if all the > numbers are exactly the same. > > All the processes I've come up with seem to be rather convoluted. Is > there a simple way to test for this? > > -- > Kevin Murphy > Webmaster: Information and Marketing Services > Western Nevada College > www.wnc.edu > 775-445-3326 Whilst there are several ways to do this, it's not going to make someone entering dummy data give you their real phone number. They'll just enter another one that bypasses your check, e.g. 111-222- or 321-321-4321. I'd also caution about forcing any specific format on telephone numbers. I'm in the UK and our phone numbers are in the format -xxx-, xxx-- or x-xx. This would not work with your form. If people are happy to give you their number, let them type it how it is. It could even include other characters, e.g. +44 (0)1234 567890 ex 324 Edward -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php My suggestion is that we require the United Kingdom and other countries around the world to conform to our standards of telephone numbers. After all, isn't that what we do in America; change the world to meet our expectations or choose to shun them for not doing so? Nevermind that would go far beyond list topics and wy too far into the realm of political dissent. -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Checking Phone Numbers
I collect phone numbers via a web form that breaks the phone number up into 3 parts (3-digit area, 3-digit prefix, etc). Occasionally, I am having people put in a phone number such as 999-999- or 000-000- or other numbers that are all the same. How would I go about comparing those three fields to see if they are all the same numbers. I can't just exclude it anytime that the numbers all match, for example 444 is a valid area code. It should only fail if all the numbers are exactly the same. All the processes I've come up with seem to be rather convoluted. Is there a simple way to test for this? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada College www.wnc.edu 775-445-3326
Re: [PHP] Include file questions
.inc files have a disadvantage in that if you view the file: http://www.yoursite.com/file.inc you can see the php code. I prefer not to use those just on the off chance that someone can see my code and use that as the basis for figuring out a way to exploit it (especially true of password files, etc). -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On May 23, 2007, at 1:48 PM, Stephen wrote: 1) Does the filename extension matter? I prefer *.inc? It seems to work fine, but I only see others using *.php 2) Does the include file need an opening ? Not big issues, but I am curious. Thanks Stephen
Re: [PHP] format date field
Leave the date as is, its a MySQL thing. To format it on your page, use the date function: $formattedDate = date("m-d-Y",strtotime($row["open"])); http://us2.php.net/manual/en/function.date.php -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On May 23, 2007, at 9:45 AM, Mike Ryan wrote: I am reading in a date field from a mysql database the field on the screen shows up as 2007-05-01 on the screen I would like the field to show 05-01-2007 currently I am issueing the following command print $row['open']; how can I format this field??? while I am at it how can I accept the date field as 05-01-2007; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Banner rotation with links
On my home page i have all my banners in a MySQL database which includes the image path, the link, and the description as separate fields. The then do a MySQL query with a query that will look something like this: $query = "select * FROM banner ORDER BY RAND() LIMIT 1"; Seems to work just fine. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Feb 14, 2007, at 8:29 AM, Chris Carter wrote: How can I rotate a banner as well as the link in it within a page using PHP. This can be done as a include file php. Anybody please supply some code or a link for this. Thanks in advance. Chris -- View this message in context: http://www.nabble.com/Banner-rotation- with-links-tf3228157.html#a8968148 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] To many connections error message
I'm working with my host to resolve why I am getting these error messages, but in the meantime, I am getting this message on the website: Warning: mysql_connect(): Too many connections in /path/number/user/ code/connect.php on line 10 Sorry: Could not connect to database. Please contact the webmaster at [EMAIL PROTECTED] Where my connection code is: $con = mysql_connect($host, $dbuser, $pw) or die("Sorry: Could not connect to database. Please contact the webmaster at [EMAIL PROTECTED]"); @mysql_select_db($db,$con); The questions is, since I don't have error reporting turned on, why am I getting an error message that includes the complete path to my connect script something I would like to not be telling the general public? Is there a way to suppress that? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
Re: [PHP] dynamic lists
On Jan 17, 2007, at 2:20 PM, Jochem Maas wrote: Kevin Murphy wrote: On Jan 17, 2007, at 1:39 PM, Brad Fuller wrote: -Original Message- From: Jay Blanchard [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 17, 2007 4:05 PM To: Don; php-general@lists.php.net Subject: RE: [PHP] dynamic lists [snip] By dynamic drop list I mean the type where the options contained in the subsequent list depend on what was picked in the previous list without clicking submit. [/snip] PHP is server side, you need to do this with AJAX or Javascript -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Don, There's a few different ways to do this. #1) Submit the form (to itself) when a user chooses an option from the first list (using onChange=form.submit()) then with PHP query the database for the second set of options. #2) Use JavaScript to store all the values and pop them in when the user chooses an option from the first list (using onChange=someFunction (...)). I like #2. If you need a starting point, google for "javascript dynamic select list" Hope that helps, Brad FYI... Neither #1 or #2 are considered good practice for Accessibility/ADA compliance. If you are using a keyboard or screen reader to view your website, it will always pick the first one in the list and you won't have the option of even seeing the rest of the list. Basically, anything that uses onchange or onselect will cause accessibility issues. The only way to accomplish this is using onclick or submitting the form. that stance basically negates everything 'ajax', flash, video and everything considered to be remotely 'web2.0' - is the 'low-common- denominator' case always the correct choice? I understand the importance of accessibility but the practicality of most peoples' job in this sector means satisfying the requirements of a client that demands such dynamic functionality such as the auto-selection example given here. is there not an argument that screen-reader and [braille] keyboard software are somwhat responsible for being capable of 'keeping up' - given that an onclick can be handled why not an 'onchange' (in theory)? Not saying I disagree with you. which is why i tossed it out there as an FYI rather than anything else. But its something that you should be aware of when designing a site and weighing your options. For me, working for a governmental institution, I really don't have a choice. I can't throw anything into the website that has a negative ADA impact unless of course I have an alternate way of accomplishing the same thing. And yes, there is an argument that screen-readers should keep up with the technology, and I totally agree with you. but that's not reality. Target.com got sued recently for lack of ADA compliance on their website. The screen reading software company wasn't the one sued. YMMV. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
Re: [PHP] dynamic lists
On Jan 17, 2007, at 1:39 PM, Brad Fuller wrote: -Original Message- From: Jay Blanchard [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 17, 2007 4:05 PM To: Don; php-general@lists.php.net Subject: RE: [PHP] dynamic lists [snip] By dynamic drop list I mean the type where the options contained in the subsequent list depend on what was picked in the previous list without clicking submit. [/snip] PHP is server side, you need to do this with AJAX or Javascript -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Don, There's a few different ways to do this. #1) Submit the form (to itself) when a user chooses an option from the first list (using onChange=form.submit()) then with PHP query the database for the second set of options. #2) Use JavaScript to store all the values and pop them in when the user chooses an option from the first list (using onChange=someFunction (...)). I like #2. If you need a starting point, google for "javascript dynamic select list" Hope that helps, Brad FYI... Neither #1 or #2 are considered good practice for Accessibility/ADA compliance. If you are using a keyboard or screen reader to view your website, it will always pick the first one in the list and you won't have the option of even seeing the rest of the list. Basically, anything that uses onchange or onselect will cause accessibility issues. The only way to accomplish this is using onclick or submitting the form. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Re: SOLVED: [PHP] Sort Array not working
Once you see it in email, sometimes the obvious jumps out at you. Fixed this on my own. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Jan 9, 2007, at 10:41 AM, Kevin Murphy wrote: I'm having trouble sorting an array. When I do, it empties the array for some reason. Take the following code: $data = "bird,dog,cat,dog,,horse,bird,bird,bird,lizard"; $array = explode(",",$data); // Create the array $array = array_diff($array, array("")); // Drop the empty elements $array = array_unique($array); // Drop the duplicate elements $array = array_merge($array); // Reset the array keys print_r ($array); Up to here it works great. The resulting output is: Array ( [0] => bird [1] => dog [2] => cat [3] => horse [4] => lizard ) Then if I do this: $array = sort($array); // Sorts the array print_r ($array); The output is "1". I've tried asort, rsort in the place of sort and get the same results. I've also tried putting the sort in between the first 4 steps and that doesn't work either. Obviously I'm doing something wrong here. I'm using PHP 4.3.4. Any suggestions? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Sort Array not working
I'm having trouble sorting an array. When I do, it empties the array for some reason. Take the following code: $data = "bird,dog,cat,dog,,horse,bird,bird,bird,lizard"; $array = explode(",",$data); // Create the array $array = array_diff($array, array("")); // Drop the empty elements $array = array_unique($array); // Drop the duplicate elements $array = array_merge($array); // Reset the array keys print_r ($array); Up to here it works great. The resulting output is: Array ( [0] => bird [1] => dog [2] => cat [3] => horse [4] => lizard ) Then if I do this: $array = sort($array); // Sorts the array print_r ($array); The output is "1". I've tried asort, rsort in the place of sort and get the same results. I've also tried putting the sort in between the first 4 steps and that doesn't work either. Obviously I'm doing something wrong here. I'm using PHP 4.3.4. Any suggestions? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Count empty array
I'm wondering why this is. $data = ""; $array = explode(",",$data); $count = count($array); $count will = 1 $data = "Test"; $array = explode(",",$data); $count = count($array); $count will = 1 $data = "Test,Test"; $array = explode(",",$data); $count = count($array); $count will = 2 Why doesn't the first one give me an answer of 0 instead of 1. I know I could do a IF $data == "[empty]" and then not count if its empty and just set it to 0, but am wondering if there was a better way. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
Re: [PHP] Preg_match - Find URL and convert to lower case
On Dec 1, 2006, at 1:56 PM, Richard Lynch wrote: On Thu, November 30, 2006 5:04 pm, Kevin Murphy wrote: Well the problem would be then that the entire string would be lower case, and I only can have the link as lower case. Is there a way to apply strtolower into the preg_match? Why not use lower(link) in SQL to get the link out in the first place? Also, the domain part cannot be case-sensitive, so you needn't worry about that part. For the 10% that don't work, a quick check with common variants on capitalization might help to fix those up. Since these are mostly instructor's websites, that last 10% I figure it would be easier to just ask the instructors to change their site addresses. Since these are in the middle of the text, I don't think that lower will work. Doesn't it just do the same thing as strtolower? The query as is right now is (edited) "select note_text as note_text from classes" where note_text is many lines of text and in the middle of some are links and emails. What I ended up with, is this, which takes care of website addresses and emails as well (although those stay all-caps). The str_replace is there because some have the HTTP and some don't and I figured it was easier to just wipe them all out first. $section_notes = str_replace("HTTP://","",$section_notes); $section_notes = preg_replace('/WWW.(.*?) /e', '"www." . strtolower("$1") . "\" target=\"_blank\">http://www."; . strtolower("$1") . ""', $section_notes); $section_notes = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*) ([[:alnum:]-]))", "mailto:\\1\";>\\1",$section_notes); Anyone have a better idea on how to accomplish the same thing? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Preg_match - Find URL and convert to lower case
On Nov 30, 2006, at 7:50 PM, Jonesy wrote: On Thu, 30 Nov 2006 14:16:16 -0800, Kevin Murphy wrote: I have some text that comes out of a database all in uppercase (old IBM Mainframe that only supports uppercase characters). I see via other followups that you have your kludge working. *But* , What do you mean by "old IBM Mainframe that only supports uppercase characters"? The EBCDIC codes X'81' > X'89' (a-i), X'91' > X'99' (j-r), and X'A2' > X'A9' (s-z) have been defined and used since probably before you were born. I have in front of me my first IBM Green Card (IBM System/360 Reference Data, GX20-1703-3) from 1966 which debunks that urban legend. If the data in the mainframe database is all upper case, it was sloppy programming or sloppy design that got it there. If it _is_ stored in the mainframe database in proper UC/lc form, then it is probably a sloppy extraction procedure that is to blame for your input. Jonesy -- Marvin L Jones| jonz | W3DHJ | linux 38.24N 104.55W | @ config.com | Jonesy | OS/2 *** Killfiling google posts: Yeah, that would be the problem. My website and its MySQL database are totally seperate from this data (its class schedule data). All the data in the database is uppercase and I've been told that all the data must remain as uppercase only. Why? I have no idea. Can I change that? Nope. Welcome to my world and the joys of working with governmental institutions. So I did misspeak before. The mainframe itself probably supports UC/ lc, but whatever program is on it, or maybe its just a procedure issue (its _always_ been done this way so we _must_ continue doing it that way). But, the data I see in my extract is all upper case and that's what I am dealing with. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Re: SOLVED: [PHP] Preg_match - Find URL and convert to lower case
$section_notes = preg_replace('/WWW.(.*?) /e', '"www." . strtolower("$1") . "\" target=\"_blank\">http://www."; . strtolower("$1") . ""', $section_notes); For some reason I can't get it to work if I decare those items as variables. They have to be inside the preg_replace as written. But, it works now. Thanks for the help. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Nov 30, 2006, at 3:04 PM, Kevin Murphy wrote: Well the problem would be then that the entire string would be lower case, and I only can have the link as lower case. Is there a way to apply strtolower into the preg_match? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Nov 30, 2006, at 2:26 PM, Dave Goodchild wrote: Why not use strtolower on the string after the replacements have been made? -- http://www.web-buddha.co.uk
Re: [PHP] Preg_match - Find URL and convert to lower case
Well the problem would be then that the entire string would be lower case, and I only can have the link as lower case. Is there a way to apply strtolower into the preg_match? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Nov 30, 2006, at 2:26 PM, Dave Goodchild wrote: Why not use strtolower on the string after the replacements have been made? -- http://www.web-buddha.co.uk
[PHP] Preg_match - Find URL and convert to lower case
I have some text that comes out of a database all in uppercase (old IBM Mainframe that only supports uppercase characters). Occasionally there are web addresses in this text and so I am trying to find them, convert them to a link, and convert them all to all lower case. Yes, I know that will not work for all links. However, it will work for about 90% of the links I have (vs. about 10% of them now). So anyway, here is my first stab at this, but it only finds the link and converts the first part to lowercase and converts it to a link. Is there anyway to convert the output to all lowercase by doing something like this? Or is there a better way? $pattern = "/WWW.(.*?) /i"; $replace = "http://www.\\1\";>http://www.\\1"; $section_notes = preg_replace($pattern,$replace,$section_notes); -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
Re: [PHP] Remove Spaces from Middle of String
Works perfect! Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Oct 3, 2006, at 3:30 PM, Robert Cummings wrote: On Tue, 2006-10-03 at 15:17 -0500, Richard Lynch wrote: On Tue, October 3, 2006 1:47 pm, Richard Lynch wrote: If you have this, it's better: $data = preg_replace("/ /", $data); D'oh! $data = preg_replace("/ /", " ", $data); Doesn't work on 3+ spaces in a row ;) $data = preg_replace("/ +/", " ", $data); Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `'
[PHP] Remove Spaces from Middle of String
This works, but I was wondering if this was the best way to accomplish this or not. I'm trying to remove any extra spaces (not whitespace like carriage returns) from the middle of a string mainly for times where people put extra spaces after periods in paragraph. while(preg_match('/ /',$data)) { $data = str_replace(" "," ",$data);} Is there a better way to accomplish this same task? (PHP 4.x). Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
Re: [PHP] Mail Problem
Why not validate the email address before you send. I use something like this to kick back an error that says you put in a bad email address. It won't tell you about a wrong email address, but it will tell you if they forgot to put in the @ sign and stuff. if (!preg_match("/^(.+)@[a-zA-Z0-9-]+\.[a-zA-Z0-9.-]+$/si", $data)) { $email_error = "yes"; } -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Sep 26, 2006, at 9:09 AM, [EMAIL PROTECTED] wrote: I have an issue with sending email via PHP which may be a configuration problem with either PHP, Apache, or possibly a Sendmail, but I don't know which yet. I figured I'd start here first. Here's the situation. I have several webpages that send email to users for various reasons. We have our webserver, an intranet webserver, configured to connect to our smtp server which sits on a different box. The script looks like this: This works great when it works. Users receive email as expected and when they hit reply it goes back to the webmaster email address. The problem is if the to email address isn't a valid one. When this happens, the mail server bounces the message back to [EMAIL PROTECTED] instead of [EMAIL PROTECTED] I've tried adding reply-to to the mail headers and that doesn't work either. We tried sending the same failed message using webmin and that worked great, which is why I believe this to be a PHP or Apache problem. Any ideas? Thanks, Robbert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse of date("w")
Kevin Murphy wrote: Not really. If it were always "today" that would work, but in this case, I was thinking of storing a day of the week in a database ("3"), and then display the info based on that digit. So assuming that the number was in fact 3, then: echo date("D","3"); Would return "Wed". Is there any function like that? Oh, and it has to run on PHP 4. Any reason you wouldn't write it yourself? No reason. and its what I was planning on. I just was hoping that there was a pre-built function that I was just not seeing. Your solution above is probably the best one. Thanks. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reverse of date("w")
Not really. If it were always "today" that would work, but in this case, I was thinking of storing a day of the week in a database ("3"), and then display the info based on that digit. So assuming that the number was in fact 3, then: echo date("D","3"); Would return "Wed". Is there any function like that? Oh, and it has to run on PHP 4. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Sep 18, 2006, at 3:18 PM, Jay Blanchard wrote: [snip] I'm looking for something that will convert a the opposite of the date ("w") function. In other words, if I have the number "3", I would like it to return "Wednesday". Is there such a beast out there besides writing a switch or array or something? [/snip] Perhaps http://www.php.net/idate -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Reverse of date("w")
I'm looking for something that will convert a the opposite of the date ("w") function. In other words, if I have the number "3", I would like it to return "Wednesday". Is there such a beast out there besides writing a switch or array or something? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Filter MS Word Garbage
I have a web form where trusted people will be inputing information that they usually copy/paste out of MS Word. While the people are trusted... MS Word isn't. I keep getting garbage characters in there, usually associated with Smart Quotes. If I take the content out of the DB, throw it into BBEdit and use the convert to ASCII command that solves the problem. Is there some way I can filter/convert this information before it gets to the mysql database? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
Re: [PHP] if statement with or comparison (newbie)
Shouldn't that be this instead: if (($_REQUEST['id'] != "black") OR ($_REQUEST['id'] != "white")) { echo "wrong color"; } else { echo "right color"; } -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Sep 8, 2006, at 2:28 PM, Prathaban Mookiah wrote: Let me rephrase it. Your color should be black or white to be the right colour. Is this correct? In that case you should change it to if ($_REQUEST['id'] != "black" AND $_REQUEST['id'] != "white") { echo "wrong color"; } else ( echo "right color"; } - Original Message - From: "JD" <[EMAIL PROTECTED]> To: Sent: Friday, September 08, 2006 5:03 PM Subject: [PHP] if statement with or comparison (newbie) I'm trying to set up a simple conditional, something like this: If my_variable is NOT equal to (black or white) echo "wrong color" else echo "right color" Here is what I have tried: if ($_REQUEST['id'] != ("black" or "white")) { echo "wrong color"; } else ( echo "right color"; ) However, no matter what I enter, I always get response "right color". I should add that if I change the if statement to: if ($_REQUEST['id'] != ("black")) then I get "right color" when I enter "black" and "wrong color" for everything else. Would you please point out what's the trivial thing I'm missing here... jd -- 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
Re: [PHP] Format of Encrypted Password
Yup, that's got it. It didn't occur to me that its a MySQL thing I'm used to doing this as a PHP thing and inserting an already encrypted password into MySQL. Anyone have any thoughts one way or another as to if this mysql password function is better/worse than doing it all in PHP? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Sep 7, 2006, at 12:50 PM, Eric Butera wrote: On 9/5/06, Kevin Murphy <[EMAIL PROTECTED]> wrote: $query = "select name from table where name = '$authuser' and password = password('$auth_pw')"; If you haven't tried this you can probably create accounts yourself manually in MySQL like this: INSERT INTO table (name, password) VALUES ('user', PASSWORD('pass'));
Re: [PHP] Format of Encrypted Password
The only thing I can find anywhere in the code is this: $auth_user = $_SERVER['PHP_AUTH_USER']; $auth_pw = $_SERVER['PHP_AUTH_PW']; $query = "select name from table where name = '$authuser' and password = password('$auth_pw')"; I've never seen that password('$auth_pw') part before. Is that a mysql part that I am not familiar with and that I should know? I've been known to miss obvious stuff before. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Sep 5, 2006, at 4:25 PM, Chris W. Parker wrote: Kevin Murphy <mailto:[EMAIL PROTECTED]> on Tuesday, September 05, 2006 3:27 PM said: The passwords are called in the application by: $_SERVER['PHP_AUTH_PW'] Is there any way to tell how these passwords were encrypted? Have you tried searching the entire codebase for that string? Might get you some clues. From the commandline (and at the root of the codebase): # grep -R PHP_AUTH_PW * Chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Format of Encrypted Password
On Sep 5, 2006, at 4:14 PM, Robert Cummings wrote: On Tue, 2006-09-05 at 15:27 -0700, Kevin Murphy wrote: I've inherited this website and there is an application that is running on it that has a bunch of passwords stored in a mysql table. The problem is, the previous webmaster didn't leave me any instructions on how they encrypted those passwords. I don't need to figure out what the old passwords were, I just need to be able to generate my own (until such time as I can rebuild this portion of the website). The passwords are called in the application by: $_SERVER['PHP_AUTH_PW'] The passwords appear to be 16 character strings that predominately have numbers in them (rather than letters) and don't appear to have any punctuation (although it could be just the few I am looking at that don't). Is there any way to tell how these passwords were encrypted? Yes, find the spot in the code responsible for creating new accounts or updating account passwords. Right there is where you'll find the information. Unless of course he used some kind of command line tool to manually add accounts --- which I doubt. Unfortunately, thats precisely what it appears that they did. There is no code anywhere I can find for updating/adding accounts. As far as I can tell the only place that the accounts exist or can be edited is directly into the mysql database, with the password all ready encrypted. Of course, I could be missing something. I'll keep looking. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- 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] Format of Encrypted Password
I've inherited this website and there is an application that is running on it that has a bunch of passwords stored in a mysql table. The problem is, the previous webmaster didn't leave me any instructions on how they encrypted those passwords. I don't need to figure out what the old passwords were, I just need to be able to generate my own (until such time as I can rebuild this portion of the website). The passwords are called in the application by: $_SERVER['PHP_AUTH_PW'] The passwords appear to be 16 character strings that predominately have numbers in them (rather than letters) and don't appear to have any punctuation (although it could be just the few I am looking at that don't). Is there any way to tell how these passwords were encrypted? -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Re: [css-d] Where CSS, XHTML and Javascript meet
Don't forget that you can also do the CSS inline: And then also in the CSS file have all the other declarations for the body tag. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On Aug 21, 2006, at 12:50 PM, Dave Goodchild wrote: You're right, a bit off-topic, as is my answer. You could use php, ie have more contro, as it's server-side ie the php array $classes = array('class1', 'class2', 'class3'); ?> the xhtml with php dynamics then in the css, for example body .class1 { background: url(/images/class1.jpg); } body .class2 { background: url(/images/class2.jpg); } ...let me know if this is a viable approach for you and we can continue off list. -- http://www.web-buddha.co.uk http://www.projectkarma.co.uk __ css-discuss [EMAIL PROTECTED] http://www.css-discuss.org/mailman/listinfo/css-d IE7b2 testing hub -- http://css-discuss.incutio.com/?page=IE7 List wiki/FAQ -- http://css-discuss.incutio.com/ Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Re: [PHP] Dividing, and keeping, text from the first space
On Aug 8, 2006, at 11:30 PM, Dave M G wrote: PHP List, This regular expression stuff is way tricky. Thanks to help from this list, I have an expression that will select the first word of a string, up to the first white space: "#^(.*)\s#iU" But after some consideration, I realized that I wanted to keep both parts of the original text. The first word, and then everything that came after it, should be divided and stored in separate variables. Now, I would do this different. Probably "wrong" but instead of a regular expression here, I would do something like this: $array = explode(" ",$string); $first_word = $array[0]; $rest_words = substr_replace($string,"",0,strlen($first_word)); -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Multiple Includes vs. One Long Include (Functions)
I was just wondering if there was any thought one way or another on the best practice for doing this. Lets say I have 10 functions that I want to reuse on my site. Not every page needs every function. So I move the function to an external page and then require it for the page. The question is, is it better to have all 10 of those functions in a single file that is called once from each PHP page, even though some will not be used, or is it better to put one function per include and then on each PHP page call just the functions that I need for that page? require ("all10.php"); // one long page, but only called once. vs. require ("function1.php");// multiple short pages with multiple calls. require ("function2.php"); require ("function4.php"); require ("function6.php"); require ("function8.php"); -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326
[PHP] Formatting of a.m. and p.m.
date("a"); > output = AM Is there any easy way to change the formatting of the output of above from "am" to "a.m." in order to conform to AP style? Something like this below would work, but I'm wondering if there is something I could do differently in the date() fuction to make it work: $date = date("a"); if ($date == "am") { echo "a.m." } elseif ($date == "pm") { echo "p.m." } -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Handling Large Check Box Data
I did something similar recently. Basically I have one MySQL field to handle several dozen checkboxes, my situation though was where the checkboxes are numerically sequential though so I am not sure if this helps. I also had only a couple hours to do this from start to finish so I am sure there is a better way, but maybe this helps. I wrote a function that generates the row of checkboxes, then a function that combines them all into one field and so the status of every checkbox is in one field. Function generates the checkboxes and checks in the array if that checkbox is checked or not. function row_generator($row,$number,$array) { echo "\n"; echo "\n\tRow $row"; $i = 1; while ($i <= "$number") { if ($i < "10") { $row_number = "{$row}-0{$i}"; } else { $row_number = "{$row}-{$i}"; } echo "\n\t"; echo "\""; if (strstr($array,$row_number) === FALSE) { echo ""; } else { echo " CHECKED"; } echo ">"; echo ""; echo $i; echo ""; $i++; } echo "\n"; } In use: $seats = $row['seats']; row_generator("A","23",$seats); Collect the posted Data and then later this gets input into a database $poster_A = ""; $i = 1; while ($i <= "30") { if ($i < "10") { $r = "0{$i}"; } else { $r = $i;} if (isset($_POST["A-$r"])) { $poster_A .= "A-$r"; $poster_A .= ":"; } $i++; } $seats = ("{$poster_A}{$poster_B} etc"); $query = "UPDATE seating_chart SET seats = '$seats' WHERE season = '2006'"; -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 On May 17, 2006, at 11:21 AM, Rahul S. Johari wrote: Ave, I’m a little confused as to what’s the best way to handle this. I have a form which, apart from lots of other fields, has a set of 25 – 30 Check Boxes, each of which asks the user for some kind of information which the user can check or leave unchecked. The information each Check Box collects will also appear in the “Listing” for users to view once the user has completed & submitted the form. Furthermore, there is an Advanced Search also available to users which will also provide the same 25 - 30 check boxes which define the search criteria. I’m not sure what’s the best, most efficient way to do this. The tedious way to do this is to make 30 fields in the mySQL database, and if the check box is checked, the data goes into the corresponding field... And similarly listing the data from the field if field is non- empty And similarly including each field in the Search options. I want suggestions for a better/faster way to do this. I did think about creating a single field and storing the data from each ‘checked’ check box as comma separated values in the single field. I’m not sure how to do that and if that’s the best way But even if I can, I’m not sure how to get the data to display separately out of that field in the Listings view and more importantly how to include that data in the Search options. Any help would be appreciated. Thanks, Rahul S. Johari Coordinator, Internet & Administration Informed Marketing Services Inc. 500 Federal Street, Suite 201 Troy NY 12180 Tel: (518) 687-6700 x154 Fax: (518) 687-6799 Email: [EMAIL PROTECTED] http://www.informed-sources.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Query for two fields with the same name
This is probably a simple question, but I can't seem to find the answer online. I'm using this query: $connection = "select * from connection, pr WHERE connection.area_id = '$gateway_link' and connection.pr_id = pr.id"; Both tables have a field called ID but they have different information in them. $row['id'] gets me the one from the table called "pr" but I need to call the ID from the table connection. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Join - Two Columns with the same name
This is probably basic, but I can't seem to find the answer. Is there a way to specify in a join a specific column when the two tables have columns with the same name? Something like: $row['table1.id'] vs $row['table2.id'] -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] File Types for Upload
For an expression such as this. $HTTP_POST_FILES['userfile']['type']=="image/gif" I'm looking for an up to date list of all the other media formats (non-images), such as Video and Audio. Does anyone have a list handy they could direct me to. -- Kevin Murphy Webmaster: Information and Marketing Services Western Nevada Community College www.wncc.edu 775-445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $i vs. $r
Hello all I simplified the code a bit, and I am guessing that it was too much. Below is the complete code that works fine. The weird part is, the part that I have the question on, is if I change $r to $i, it doesn't work anymore. $i doesn't count up as it should and instead gives me some unpredictible results. as it goes down the list sometimes its sequential (1,2,3 but never more than 3), other times its just the number 2 over and over). $r = 1; while ($row = mysql_fetch_array($website_result)) { if (is_int(($r+2)/3)) { echo ("\n");} echo ("\n"); include("$site_path/common/code/directory_format_name.php"); // Gets the name Formatter echo ("\nimages/directory/".$row['sup_picture']."\" border=\"0\">"); echo ("$full_namea>"); echo ("\n"); if (($r >= "$website_total") AND (is_int(($r+2)/3))) { echo (" "); } elseif (($r >= "$website_total") AND (is_int(($r+1)/3))) { echo (" "); } elseif (is_int(($r)/3)) echo ("\n"); $r++; } echo (""); -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 On Mar 27, 2006, at 3:11 PM, Jasper Bryant-Greene wrote: Kevin Murphy wrote: Does anyone have a clue why using this code doesn't work: Please specify what "doesn't work" means in this case :) $i = 0; while ($row = mysql_fetch_array($result)) { echo ("Blah blah blah"); $i++; } $r = 0; while ($row = mysql_fetch_array($result)) { echo ("Blah blah blah"); $r++; } Those two blocks of code are for all intents and purposes identical, and indeed probably end up as exactly the same opcodes. Jasper -- 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] $i vs. $r
Does anyone have a clue why using this code doesn't work: $i = 0; while ($row = mysql_fetch_array($result)) { echo ("Blah blah blah"); $i++; } but this code does? $r = 0; while ($row = mysql_fetch_array($result)) { echo ("Blah blah blah"); $r++; } I don't use $i anywhere else on the page. -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL NOT IN Query not working
Yup. Thats the problem. I'm running 4.0.21. Thanks. -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 On Mar 16, 2006, at 4:48 PM, Miles Thompson wrote: At 08:41 PM 3/16/2006, Kevin Murphy wrote: Anyone want to point me to why this isn't working: $hr_query = "select dp_lname,dp_fname,dp_id FROM dir_all WHERE dp_id NOT IN (SELECT sup_id FROM dir_title2) ORDER BY dp_lname"; There are two tables, dir_all (the main list of everyone) and dir_title2 (supplemental). If someone is in dir_title2 then the sup_id is the same as their dp_id. What I am trying to do is get a list of every person in dir_all that is NOT in dir_title2. Any thoughts as to what am doing wrong? -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 Kevin, Looks like an older version of MySQL. Check your version: subqueries were not supported until ver 4.1. The older docs at MySQL give a work around. Miles -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.375 / Virus Database: 268.2.1/279 - Release Date: 3/10/2006 -- 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] MySQL NOT IN Query not working
Anyone want to point me to why this isn't working: $hr_query = "select dp_lname,dp_fname,dp_id FROM dir_all WHERE dp_id NOT IN (SELECT sup_id FROM dir_title2) ORDER BY dp_lname"; There are two tables, dir_all (the main list of everyone) and dir_title2 (supplemental). If someone is in dir_title2 then the sup_id is the same as their dp_id. What I am trying to do is get a list of every person in dir_all that is NOT in dir_title2. Any thoughts as to what am doing wrong? -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Incremental Date Based ID
I think I have it all figured out now, so as promised, here is the code. Thanks everyone for your suggestions. $id_query = "select id from WHERE id LIKE '$post_date%' ORDER BY DESC LIMIT 1 "; $id_results = mysql_query($id_query,$conn); $id_row = mysql_fetch_array($id_results); $id_num_rows = mysql_num_rows($id_results); if ($id_num_rows != "0") { $id_last = $id_row["id"]; $id_letter = ord(ltrim($id_last,"\0..9,-")); $new_id = $post_date; $new_id .= chr($id_letter+1); } else { $new_id = $post_date; $new_id .= "a"; } So, it calls the database, gets the last rows with this date as part of the id (2006-05-08d), strips out the date part, adds one to the letter and outputs back the next ID (2006-05-08e). On Mar 8, 2006, at 8:39 AM, Kevin Murphy wrote: Thanks for the info, but I think you are misunderstanding what I am trying to do. I am simply trying to create a sequential ID based on a Date and a Letter (or number, if I have to) field that will be used as part of the link. After they are created, they will not change. And Its not about how they appear on the page in the HTML (I know how to make those be sequential in that way), I am more concerned with the ID making them unique. And yes, people do care about the way the link works. People, say for example, like my bosses, whom I am trying to accommodate. :-) And some SEO people will tell you that the link does indeed matter when doing that kind of stuff. I think I have figured it out using a combination of MAX and Limit to check to see what the last one is and then write the next one. Thanks all for your help. If I figure it out, I will post the code for future reference. On Mar 8, 2006, at 12:00 AM, Paul Novitski wrote: At 05:05 PM 3/7/2006, Kevin Murphy wrote: Well, part of the issue is that I want to be able to use this as part of the link: /news.php?article=2006-03-05a /news.php?article=2006-03-05b With respect, I too think you should re-examine your reasons for wanting to number (or letter) the links consecutively in the database. To whom does the spelling of an URL really matter? I believe that website visitors rarely care; they care about how things are labelled in the foreground and they want to get to the correct page, but I don't think many people really study the details of the address bar and even fewer make judgements about the quality or completeness of website content on that basis. There are in fact solid reasons for NOT changing URLs once they're established -- for example, the persistence of bookmarks, links from other websites, and search engine memory. Once you establish an URL pointing to a particular page it's going to be recorded, stored, and repeated by many other entities on the internet. If you're whimsically changing URLs at random intervals, old URLs will no longer point to the same content. You'll be doing your own material a disservice by frustrating one of the most powerful assets the internet can lend you: its persistence of vision. I wonder if your desire for contiguously lettered URLs can be satisfied by simply assigning consecutive letters to the display text that links to the articles: HTML: Title of article Title of article Title of article CSS: ol { list-style-type: lower-alpha; } RESULT: a. Title of article b. Title of article c. Title of article As others have pointed out, the sequence in which the URLs spill out from the database can be controlled by a timestamp in each record. The lettering of the articles a-z can be controlled by the ordered list for the benefit of the visitor. When an article is inserted into or deleted from the list, the list retains its contiguity IN THE PRESENTATION and you aren't put in the inelegant position of trying to renumber records in a database. Regards, Paul -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Incremental Date Based ID
Thanks for the info, but I think you are misunderstanding what I am trying to do. I am simply trying to create a sequential ID based on a Date and a Letter (or number, if I have to) field that will be used as part of the link. After they are created, they will not change. And Its not about how they appear on the page in the HTML (I know how to make those be sequential in that way), I am more concerned with the ID making them unique. And yes, people do care about the way the link works. People, say for example, like my bosses, whom I am trying to accommodate. :-) And some SEO people will tell you that the link does indeed matter when doing that kind of stuff. I think I have figured it out using a combination of MAX and Limit to check to see what the last one is and then write the next one. Thanks all for your help. If I figure it out, I will post the code for future reference. On Mar 8, 2006, at 12:00 AM, Paul Novitski wrote: At 05:05 PM 3/7/2006, Kevin Murphy wrote: Well, part of the issue is that I want to be able to use this as part of the link: /news.php?article=2006-03-05a /news.php?article=2006-03-05b With respect, I too think you should re-examine your reasons for wanting to number (or letter) the links consecutively in the database. To whom does the spelling of an URL really matter? I believe that website visitors rarely care; they care about how things are labelled in the foreground and they want to get to the correct page, but I don't think many people really study the details of the address bar and even fewer make judgements about the quality or completeness of website content on that basis. There are in fact solid reasons for NOT changing URLs once they're established -- for example, the persistence of bookmarks, links from other websites, and search engine memory. Once you establish an URL pointing to a particular page it's going to be recorded, stored, and repeated by many other entities on the internet. If you're whimsically changing URLs at random intervals, old URLs will no longer point to the same content. You'll be doing your own material a disservice by frustrating one of the most powerful assets the internet can lend you: its persistence of vision. I wonder if your desire for contiguously lettered URLs can be satisfied by simply assigning consecutive letters to the display text that links to the articles: HTML: Title of article Title of article Title of article CSS: ol { list-style-type: lower-alpha; } RESULT: a. Title of article b. Title of article c. Title of article As others have pointed out, the sequence in which the URLs spill out from the database can be controlled by a timestamp in each record. The lettering of the articles a-z can be controlled by the ordered list for the benefit of the visitor. When an article is inserted into or deleted from the list, the list retains its contiguity IN THE PRESENTATION and you aren't put in the inelegant position of trying to renumber records in a database. Regards, Paul -- 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
Re: [PHP] Re: Incremental Date Based ID
Well, part of the issue is that I want to be able to use this as part of the link: /news.php?article=2006-03-05a /news.php?article=2006-03-05b which i will eventually do a htacess rewrite to make it look like /news/2006-03-05a.php /news/2006-03-05a.php I don't think I can do that with just the Unix timestamp. On Mar 7, 2006, at 4:56 PM, Al wrote: Kevin Murphy wrote: I'm trying to set up an ID field that works like this for news articles that are posted to a website. 2006-03-05a 2006-03-05b I know how to generate the date, and I am pretty sure I can generate the letter code based on counting the number of rows and then assigning the next letter (we will never have more than 26 in a day... usually its closer to 1 or 2 per day). The problem is if there has been something deleted. 2006-03-05a 2006-03-05c If I then Count the rows with this date I get an answer of 2, and so the next letter should be "c" but there already is a "c" because "b" got deleted. So, is there any way of generating this style ID number automatically? --Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 Why not simply use the Unix time stamp. time() If more than one can arrive within the same second, append a letter. If users need to see the key, use date() to decode it for them -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Incremental Date Based ID
I'm trying to set up an ID field that works like this for news articles that are posted to a website. 2006-03-05a 2006-03-05b I know how to generate the date, and I am pretty sure I can generate the letter code based on counting the number of rows and then assigning the next letter (we will never have more than 26 in a day... usually its closer to 1 or 2 per day). The problem is if there has been something deleted. 2006-03-05a 2006-03-05c If I then Count the rows with this date I get an answer of 2, and so the next letter should be "c" but there already is a "c" because "b" got deleted. So, is there any way of generating this style ID number automatically? -- Kevin Murphy Webmaster - Information and Marketing Services Western Nevada Community College www.wncc.edu (775) 445-3326 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mkdir after mkdir
I'm still kind of a newbie at this, but couldn't you accomplish this by doing each MKDIR separately with a series of ELSE/IF statements. The basic logic would be: Check if parent DIR exists. If not, create one and then go on If yes: Check if Child DIR Exists If Not, Create one, if yes, go on.... Etc. -- Kevin Murphy Web Designer - Stubborn Donkey Productions www.stubborndonkey.com On Jun 6, 2004, at 11:08 AM, Gerben wrote: Unfortunately my server has no ftp (but SSH). It makes much sence what you said, but how can PHP (with uid=48) make a directory with uid=1042. both folder are (to be) made the same script, but only one is (with uid=1042). This is what makes it very peculiar. I think I have skip the idea of creating 2 nested folders. Thanks anyway "Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Gerben wrote: Hello, I have a problem with the mkdir function. I'm trying to make a seperate folder every photoalbum. inside I want to create another folder ('.../thumbnails/') for, you can guess, the thumbnails. At first it didn't work at all: Warning: mkdir() failed (Permission denied) in /home/virtual/site43/fst/var/www/html/beheer/albums/index.php on line 42 When I changed the rights of the folder I wanted to create the new folder in to chmod 0777, the first MKDIR did work, but the second did not. SAFE MODE Restriction in effect. The script whose uid is 1042 is not allowed to access /home/virtual/site43/fst/var/www/html/uploaded/images/albums/album_0 owned by uid 48 in /home/virtual/site43/fst/var/www/html/beheer/albums/index.php on line 43 this is very strange because the folders are both made in the same script. Another strange thing is that I user mkdir($dir, 0777), but when I look at the created folder it is 0755 and I can not change it. That's pritty much my problem. Your help would be very much appreciated. The first directory your script creates is owned by the uid apache runs under (48 in your case). Safe mode allows access only to files and directories owned by the uid of the executing script (1042 in your case). The workaround is to use ftp functions to create the directories. Simply use your ftp username and password to login to localhost and create the directories. HTH -- 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
Re: [PHP] Newbie error with cookies and headers already declared
I'm a newbie to PHP too, but I think its the HTML tag. Move it down below the PHP and see what happens. -- Kevin Murphy Web Designer - Stubborn Donkey Productions www.stubborndonkey.com On May 21, 2004, at 1:28 PM, GodFoca wrote: I'm getting this error: Warning: Cannot add header information - headers already sent by (output started at /home/tiempodemaria/main.php:3) in /home/tiempodemaria/main.php on line 11 With this code in "main.php": $has_visited = isset($_COOKIE["TdM_visited"]); if (!$has_visited) { setcookie("TdM_visited", (string) (time() + OFFSET_WITH_GMT), time() + OFFSET_WITH_GMT + SECONDS_IN_THREE_MONTHS); // the above (not blank) is line 11 } else { $latestVisit = (int) $_COOKIE["TdM_visited"]; setcookie("TdM_visited", (string) (time() + OFFSET_WITH_GMT), time() + OFFSET_WITH_GMT + SECONDS_IN_THREE_MONTHS); } ?> . Does anybody knows what's going on? I don't understand which header is being sent before the setting of the cookie, and I don't understand the ":3" in the error description. This page is a frame, so I don't have any head tag, does that matter to php? Thanks in advance, Nicolas -- 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