[PHP] references
Ok lets see I have the following two functions one calls the other Function a (&$myref) { ..something... then calls function b b($myref); } function b (&$myref) { something } a($myref); is the reference by passing in function b legal??? Carl Furst Chief Technical Officer Vote.com 50 Water St. South Norwalk, CT. 06854 203-854-9912 x.231 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] newbY prob
$dbquerymeal = "select COUNT(*) from mealtype"; $resultmeal = mysql_db_query($dbname,$dbqueryshipping1); if(mysql_error()!=""){echo mysql_error();} $mealcount = mysql_fetch_row($resultmeal); echo $mealcount; YOUR query is not stored in ,$dbqueryshipping1 but in $dbquerymeal I believe... switch the vars and you should solve the problem.. at least that's a perfunctory glance.. You are actually better off not using that function, anyway You are probably better off doing something like: $mealcountrst = mysql_query($query); if ($mealcountrst != FALSE) { $mealcount = mysql_fetch_row($resultmeal); } else { print "yo, you messed up! " . mysql_error(); } // there are "nicer" ways to do this of course.. one is: $mealcountrst = mysql_query($query); $mealcountrst ? $mealcount = mysql_fetch_row($resultmeal) : print mysql_error(); // ps... none of this code has been tested use at your own risk. Carl Furst Chief Technical Officer Vote.com 50 Water St. South Norwalk, CT. 06854 203-854-9912 x.231 -Original Message- From: Phillip Blancher [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 23, 2003 3:38 PM To: PHP List Subject: [PHP] newbY prob Problem with Count. ! am trying to count the number of items in this table. The table has one field in it. The code I am using is: $dbquerymeal = "select COUNT(*) from mealtype"; $resultmeal = mysql_db_query($dbname,$dbqueryshipping1); if(mysql_error()!=""){echo mysql_error();} $mealcount = mysql_fetch_row($resultmeal); echo $mealcount; The result I am getting is: Query was empty Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in search.php Any suggestions? --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] incrementing string value
Yep that should work as does $var-- -Original Message- From: Jeremy [mailto:[EMAIL PROTECTED] Sent: Friday, July 25, 2003 12:28 PM To: [EMAIL PROTECTED] Subject: [PHP] incrementing string value writing some client side javascript with some dynamic php, and I need to be able to print a dynamic number of variables to the javascript. I need to print: var a=""; var b=""; ...etc. Is there a way to increment a php $var much like $var++ would work? Jeremy -- 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] formating date
You can do it by selecting the formatted date from the mysql server using the DATE_FORMAT command which would be: SELECT DATE_FORMAT('%M %D, %Y', date_field_name_or_mysqldate); -Original Message- From: Gronquist, Jim M [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 30, 2003 11:53 AM To: [EMAIL PROTECTED] Subject: [PHP] formating date My script currently works; printing the date that it extracts from mysql table. It prints the date as: 2004-01-29 $mailed=$row["mailed"]; $payment=$row["payment"]; $ID=$row["ID"]; echo "$mailed$payment"; I'm trying to change the format so that the date appears as: January 29, 2004 $mailed=$row["mailed"]; $payment=$row["payment"]; $ID=$row["ID"]; $thisdate=date("F/d/Y",$row->mailed); echo "$thisdate$payment"; This gives the right format, however, it seems to be trying to do the current date rather then my submitted date? Any idea how I do this? - Jim Gronquist Computer Network and Programming Analyst Office of the Bursar Indiana University 812.856.3026 x6-3026 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] find string
Isn't there an in_array function you can use? If (in_array($action, array(a1,a2,a3,a4)) { // do something } else { // do something else } Carl. -Original Message- From: andu [mailto:[EMAIL PROTECTED] Sent: Sunday, August 10, 2003 7:15 PM To: [EMAIL PROTECTED] Subject: [PHP] find string Here's the problem I have: I have $action which can be anyone of a1, a2, a3, a4. I tried if ($action!='a1' || $action!='a3') //tried == also { //do stuff } else { //do other stuff } Problem is that if() only seems to take one option so my construct above doesn't work. What function can I use to do something like: if ($action is among the items of 'a2,a4') kind of construct? I tried strpos('a1a2a3',$action) but with the same results. TIA -- Regards, Andu Novac -- 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] Need aternate for "exit;"
Perhaps a return, if it's a global function? Like return(1) if success and return(0) if failure or something like that? However I have a question for you, why do you turn $numdays into a string and then do mathematical operations on it? $numdays = "$numdays"; and $numdays = '5'; Does that force some kind of behavior that's needed? Interesting. Carl Furst Chief Technical Officer Vote.com 50 Water St. South Norwalk, CT. 06854 203-854-9912 x.231 -Original Message- From: PHPSpooky [mailto:[EMAIL PROTECTED] Sent: Friday, June 06, 2003 11:16 AM To: [EMAIL PROTECTED] Subject: [PHP] Need aternate for "exit;" Glory! I'm stuck in a crazy problem. I have a Global.PHP file that runs the whole show. It's a Link Index Program with a Yahoo Style Directory Structure. There are certain additional features like "New Links", "Popular Links", "Top Rated" etcetera. The global.php file contains functions for each feature. But each function ends with exit; If you don't use the exit; , then the main Category Structure, which is the prime function, a global function, also displays on every page.. And if you do use exit; .. then all the rest of the HTML and Interface code disappears and the page just ends there. This is a problem.. I need to display the rest of the Interface, but not the Category Structure, when you click on a feature like New Links.. Let me give you example of New Links function.. function new_links($numdays) { global $nol; // displays a list of links added in the last x days - limit is $nol links if (!$numdays) { $numdays = '5'; } else { $numdays = "$numdays"; } $time = time(); $mintime = $time - ($numdays * 24 * 60 * 60); $links_sql = "SELECT * FROM sslinks WHERE link_dateadd > $mintime AND link_validated = 'yes' ORDER BY link_dateadd DESC LIMIT 0,$nol"; $links = links_sql($links_sql); echo html_header("New Links"); if (!$links) { $links = ss_template('no_new_links.tmpl'); } echo ss_template('new_links_page.tmpl', array('%maxnumlinks%' => $nol, '%numdays%' => $numdays, '%links%' => $links)); echo html_footer(); exit; } Now this function goes in a place inside a page which has a complete Site interface.. I cant have the page just stop here.. the rest of the Interface needs to display. Removing "exit;" does that.. but also repeats the Directory Structure which is a Global Function.. I tried using "break;" but that doesn't work this way.. Any suggestions? PHPSpooky __ "If God had wanted me otherwise, He would have created me otherwise." - Johann Wolfgang von Goethe -- 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] strip_tags() Quandry....
Yes, no problem! Glad it worked out. you may wish to actually study the perlre man page on perl.com. This goes into the most details and talks about how PERL actually EXTENDS shell regular expressions significantly and excellent resource that I have used many many times. I figure since PHP regexps are perl compatible, might as well go to the source, no? My other suggestion is that if you are taking this HTML and putting into a database, especially MySQL you should scrub for pipes, nulls and slashes, hackers can exploit user input to open a tty or shell or even access user files like /etc/passwd and mess wid ya here are a few regexps that do that For pipes: preg_replace('/\|/g','',$html_string); For nulls: Preg_replace('/\0/g','',$html_string); For slashes preg_replace('/\//g','',$html_string); # to be clearer, you can use s!\/! g; just so you can see where the regexp begins and ends. Some other useful ones for data like the stuff you're doing: Spaces at the beginning: /^\s/ spaces at the end: /\s$/ tags into \n preg_replace('!\!', "\n", $string); regular expressions are key.. if you have an editor like bbedit on the mac or UltraEdit on the PC it will make your life SO much easier. Especially if you are a database massager, oh man the hours I have saved! C. -Original Message- From: Noah [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 12:34 PM To: Carl Furst Subject: Re: [PHP] strip_tags() Quandry Hey Carl. Sorry for the late reply -- got totally wrapped up in utilizing that highly useful bit of reg exp code. Thanks for the heads up; it certainly solved the problem. Unfortunately, or fortunately, new problems have arisen -- time to dive into learning some reg exp syntax Thanks again, --Noah - Original Message - From: "Carl Furst" <[EMAIL PROTECTED]> To: "CF High" <[EMAIL PROTECTED]> Sent: Tuesday, May 27, 2003 8:49 PM Subject: RE: [PHP] strip_tags() Quandry use regular expressions: preg_replace("/\s+/"," ",$html_string); -Original Message- From: CF High [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 27, 2003 11:57 PM To: [EMAIL PROTECTED] Subject: [PHP] strip_tags() Quandry Hey all. I've got a chunk of HTML text I'd like to format for insertion into our mySql db. Let's say $html_string equals the following: 1 Bardo, Jesse S A Andover, MA To setup this chunk of text for insertion I first use strip_tags($html_string); that results in: 1 Bardo, Jesse S A Andover, MA I then use str_replace(",","",$html_string) to create a space delimited string. Here's where I believe the problem occurs. There are apparently numerous blank spaces within the string. I've tried replacing the blank spaces, or whatever is separating the data to no avail. I've tried a number of aimless efforts to get the string properly formatted, but no luck -- any suggestions? Thanks for helping me over this hurdle... --Noah -- 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] strip_tags() Quandry....
As you can guess, I'm more a fan of the regular expressions myself being primarily a PERL head. However, PHP string functions are useful and convenient (like trim() for example), and they don't require you to know the in's and out's of regexps which can look like gobbledygook, be very confusing, and sometimes very difficult to use if you don't really know how they work. If you can get them to work, they are very powerful. However getting them to work can require some serious tweaking. I think the main thing when deciding which to use is how much control you want over what is done to your string. Using a PHP function can lead to precarious results sometimes if you don't know exactly what they do (nl2br(), for example, you have to be sure that ALL of your 's are to occur right before a "\n", this isn't always the case). They also don't afford as much flexibility in some cases as regular expressions do (str_replace for replacing multiple spaces, for example). If it's something simple that you know a PHP function can take of, use it. If not, use regexps. They may take a bit more tweaking, but in the long run are much more flexible and a lot more powerful. Carl. -Original Message- From: Noah [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 11:03 PM To: CPT John W. Holmes; Carl Furst Cc: [EMAIL PROTECTED] Subject: Re: [PHP] strip_tags() Quandry Hey John; Hey Carl. I've heard this debate before; i.e. regular expressions vs. PHP string formatting functions. The problem I'm dealing with will require, I believe, a combination of preg_replace(), str_replace(), strstr(), and str_pos(). To my limited knowledge, there is no way to remove white space with PHP string functions; when I use strip_tags on a block of html text, whitespace results; thus the need for preg_replace(). The rest can most likely be taken care of with PHP string functions, although I'm running into a few headaches with user errors; i.e. when a coach types up his/her team roster and mistakenly adds extra spaces between fields (e.g. player height = 6' 2" instead of 6' 2"), or roster fields do not match up with our roster table fields (e.g. one team roster has a field for player's favorite professional athlete) -- in these cases it may be that I'll need to use regular expressions to crawl through roster string data looking for word boundaries and the like. I'm new to regular expressions to say the least -- just took the dive in yesterday; much to learn... If either of you feel like elaborating on the pros and cons of regular expressions vs. PHP string functions, let me know. --Noah - Original Message - From: "CPT John W. Holmes" <[EMAIL PROTECTED]> To: "Carl Furst" <[EMAIL PROTECTED]>; "Noah" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, May 29, 2003 10:18 AM Subject: Re: [PHP] strip_tags() Quandry > Yes, no problem! Glad it worked out. you may wish to actually study the > perlre man page on perl.com. This goes into the most details and talks about > how PERL actually EXTENDS shell regular expressions significantly and > excellent resource that I have used many many times. > > I figure since PHP regexps are perl compatible, might as well go to the > source, no? > > My other suggestion is that if you are taking this HTML and putting into a > database, especially MySQL you should scrub for pipes, nulls and slashes, > hackers can exploit user input to open a tty or shell or even access user > files like /etc/passwd and mess wid ya here are a few regexps that do > that While I agree that regexp are powerful and useful, the examples you gave are better suited to using str_replace(), trim(), or nl2br() calls rather than a regular expression. Also, about the "warning" for inserting data into a database... try not to scare people to much. If you have column = '$value' or column = "$value" in your query, as long as you've run addslashes on $value to escape single quotes in the first case and double quotes in the second, there's no vulnerabilities. If you have column = $column then you BETTER make sure that $column is a number and only a number. When you put unquoted (unquoted within the actual SQL, not PHP) values into your SQL, that's when you open yourself up to vulnerabilities if you're not validating that the value is only a number. > For pipes: > preg_replace('/\|/g','',$html_string); > For nulls: > Preg_replace('/\0/g','',$html_string); > For slashes > preg_replace('/\//g','',$html_string); # to be clearer, you can use s!\/! > g; just so you can see where the regexp begins and ends. str_replace('|','',$html_string); etc... > Some other useful ones for data like the stuff you're doing: > Spaces at the beginning: > /^\s/ > spaces at the end: > /\s$/ trim() > tags into \n > preg_replace('!\!', "\n", $string); nl2br(); ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] strip_tags() Quandry....
OH yeah, it takes a little while to get the gist of how to use them, you should also Google "Perl Regular Expressions" see what turns up. The perlre man page is very detailed which is good but you might find some other useful tricks that PHP functions or the Perlre manpage may not cover, like checking for valid email addresses, or even phone numbers (which is a tricky little @#$%^#). Is there a PHP function that checks emails? That would be neat. Carl Furst System Developer Vote.com 50 Water St. South Norwalk, CT. 06854 203-854-9912 x.231 -Original Message- From: Noah [mailto:[EMAIL PROTECTED] Sent: Friday, May 30, 2003 2:04 PM To: Carl Furst Cc: [EMAIL PROTECTED] Subject: Re: [PHP] strip_tags() Quandry Exactly, Carl. The HTML team data I'm dealing with comes in myriad formats -- nothing is uniform as each school presents their team data differently, not to mention potential inconsistencies (e.g. users mistakenly entering multiple spaces between fields and the like) within each format. For the most part I intend to rely on regular expressions for this job, although I'm a little wary -- regexp syntax is tres bizarre ;--) Thanks for the clues; ultraedit.com has a great regexp tutorial Enjoy the spring/summer, --Noah - Original Message ----- From: "Carl Furst" <[EMAIL PROTECTED]> To: "Noah" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, May 30, 2003 7:44 AM Subject: RE: [PHP] strip_tags() Quandry As you can guess, I'm more a fan of the regular expressions myself being primarily a PERL head. However, PHP string functions are useful and convenient (like trim() for example), and they don't require you to know the in's and out's of regexps which can look like gobbledygook, be very confusing, and sometimes very difficult to use if you don't really know how they work. If you can get them to work, they are very powerful. However getting them to work can require some serious tweaking. I think the main thing when deciding which to use is how much control you want over what is done to your string. Using a PHP function can lead to precarious results sometimes if you don't know exactly what they do (nl2br(), for example, you have to be sure that ALL of your 's are to occur right before a "\n", this isn't always the case). They also don't afford as much flexibility in some cases as regular expressions do (str_replace for replacing multiple spaces, for example). If it's something simple that you know a PHP function can take of, use it. If not, use regexps. They may take a bit more tweaking, but in the long run are much more flexible and a lot more powerful. Carl. -Original Message- From: Noah [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 11:03 PM To: CPT John W. Holmes; Carl Furst Cc: [EMAIL PROTECTED] Subject: Re: [PHP] strip_tags() Quandry Hey John; Hey Carl. I've heard this debate before; i.e. regular expressions vs. PHP string formatting functions. The problem I'm dealing with will require, I believe, a combination of preg_replace(), str_replace(), strstr(), and str_pos(). To my limited knowledge, there is no way to remove white space with PHP string functions; when I use strip_tags on a block of html text, whitespace results; thus the need for preg_replace(). The rest can most likely be taken care of with PHP string functions, although I'm running into a few headaches with user errors; i.e. when a coach types up his/her team roster and mistakenly adds extra spaces between fields (e.g. player height = 6' 2" instead of 6' 2"), or roster fields do not match up with our roster table fields (e.g. one team roster has a field for player's favorite professional athlete) -- in these cases it may be that I'll need to use regular expressions to crawl through roster string data looking for word boundaries and the like. I'm new to regular expressions to say the least -- just took the dive in yesterday; much to learn... If either of you feel like elaborating on the pros and cons of regular expressions vs. PHP string functions, let me know. --Noah - Original Message - From: "CPT John W. Holmes" <[EMAIL PROTECTED]> To: "Carl Furst" <[EMAIL PROTECTED]>; "Noah" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, May 29, 2003 10:18 AM Subject: Re: [PHP] strip_tags() Quandry > Yes, no problem! Glad it worked out. you may wish to actually study the > perlre man page on perl.com. This goes into the most details and talks about > how PERL actually EXTENDS shell regular expressions significantly and > excellent resource that I have used many many times. > > I figure since PHP regexps are perl compatible, might as well go to the > source, no? > > My other suggestion is that if you ar
RE: [PHP] Gracefully dealing with Cookies OFF
I think most people just put it in some sort of privacy policy I know Harrypotterfanfiction.com says it outright that you have to be able to accept not just their cookie but third party ones as well..Ouch..be sure to run SpyBot after you visit them. Vote.com has it in their privacy policy and explains how having cookies turned off limits your enjoyment of the site, but doesn't require cookie activation nor does use third party cookies, thank G-d.. Carl Furst -Original Message- From: Monty [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 04, 2003 3:08 AM To: [EMAIL PROTECTED] Subject: [PHP] Gracefully dealing with Cookies OFF I've decided to require that members for a site need to have cookies enabled in their browsers to sign-up and use the site. Is there a graceful way to deal with this when users who have cookies off try to sign-up or log-in to the site? Thanks, Monty -- 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] Redirects in PHP
I want to do one of those redirect pages where a php script prints HTML saying "sorry we're not here, we're redirecting you to the right location" and then after about 2-3 seconds a new location header gets printed and you are transported to the new location. I see this everywhere but don't know how it's done. I tried this by printing the "Location" header first and then the text and it just relocated me without seeing the text. I tried printing the text first and then the "Location" header and php complains that my header was already sent and I can't modify it to relocate. How do you do this?? Is there something in the header I have to specify to wait before it relocates? Do I have to do it manually by printing the text.. tell the script to wait and then clear the header somehow and send a new one (can that be done?) I looked at HTTP1.1 docs and I didn't really get anywhere. Any ideas? Carl. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Redirects in PHP
I can understand the abuse, but this page wouldn't need to be indexed on any search engines really.. but I it's an important consideration. Thanks! Thanks to everyone! Carl. -Original Message- From: Michael [mailto:[EMAIL PROTECTED] Sent: Friday, June 13, 2003 12:35 PM To: Zak Johnson; [EMAIL PROTECTED] Subject: Re: [PHP] Redirects in PHP Search engines frown on using meta refresh because of abuse problems. Some engines won't index the page period and all of them penalize you at the very least. While it will work as you described, you're sacrificing search engine positioning to use it. You need to weigh the trade-offs Michael On Friday 13 June 2003 11:00 am, Zak Johnson wrote: > content="3;URL=http://example.com/new-page.html"; /> -- 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] mysql split?
There is a mysql function called substring_index() that returns a substring based on an index character like space ' '. You have to specify the string, the index character, and how many time it has to find it from the left or right (left being positive and right being negative, I think) before the substring is complete. Check out: http://www.mysql.com/doc/en/String_functions.html for that and other string functions that might be useful. Carl. -Original Message- From: Andrew McCombe [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2003 12:06 PM To: [EMAIL PROTECTED] Subject: [PHP] mysql split? Hi I have a field in mysql that has paths to files such as: project/entertainment/andrew/job/1.jpg project/corporate/roberts/job/1.jpg project/corporate/andrew/job/1.jpg project/identity/john/job/1.jpg The first level is always 'projects'. What I want to do is get the unique name for the 3rd level for all entertainment, corporate and identity, so from the data above I would get returned: andrew john roberts What's the best way to acheive this? I remember seeing something where you can split a field in the mysql into parts (ie, split at /)? or would a regex be better ('WHERE REGEX "^projects/corporate|entertainment|identity/' (this doesnt work))? Hope someone can help. Regards Andrew McCombe Interactive Web Solutions (Stafford) Tel: 01785 279921 - The contents of this e-mail and any attachments are confidential and may be legally privileged. If you have received this e-mail and you are not a named addressee, please inform us as soon as possible on +44 (0) 1785 279920 and then delete the e-mail from your system. If you are not a named addressee you must not copy, use, disclose, distribute, print or rely on this e-mail. Any views expressed in this e-mail or any attachments may not necessarily reflect those of Interactive Web Solutions' management. Although we routinely screen for viruses, addressees should scan this e-mail and any attachments for viruses. Interactive Web Solutions makes no representation or warranty as to the absence of viruses in this e-mail or any attachments. Please note that for the protection of our business, we may monitor and read e-mails sent to and from our server(s). -- 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: mime type
I doubt this is the problem, but perhaps your webserver is messing with your mime-types by printing a default header for some reason. Carl Furst Chief Technical Officer Vote.com 50 Water St. South Norwalk, CT. 06854 203-854-9912 x.231 -Original Message- From: Brian V Bonini [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2003 1:36 PM To: Pete Morganic Cc: PHP Lists Subject: Re: [PHP] Re: mime type On Fri, 2003-06-27 at 13:26, Pete Morganic wrote: > chech here > http://www.phpfreaks.com/mimetypes.php > > and in php add the folowing header > > header ("Content-type: model/vrml"); As I had already stated I tried using header() and ini_set(), e.g., header("Content-type: text/css") or ini_set('default_mimetype','text/css') But, it's not working, I'm still getting text/html as the default for *.php files as it should be according to php.ini but I need to override that for this one file and output text/css. Am I wrong in assuming either of these functions should override the global configs? > > > Brian V Bonini wrote: > > I want to get php to output text/css for one .php file. I tried using > > header() and ini_set () but seems no matter what I do the Content-type > > remains text/html > > -- 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] What is wrong with this code ?
If should use double equals for comparison.. if ($doWork == 1) { etc here}. Of course doing multiple tests like this you are better off using switch case... Switch ($doWork) { Case 0: Exit; Break; Case 1: DoOne($arguments); Break; Case 2: DoTwo($arguments); Break; } each number after the case statement is the value that $doWork will be tested against.. look up Switch in the php manual, it's behavior can be a bit weird especially if you forget to "break" if you don't break it's like an OR statement/gate; Carl. -Original Message- From: Daniel Szasz [mailto:[EMAIL PROTECTED] Sent: Monday, September 15, 2003 3:29 PM To: [EMAIL PROTECTED] Subject: [PHP] What is wrong with this code ? Hello What is wrong with this code ? $doWork = $_GET[doWork]; echo $doWork; echo ( ""); if ( $doWork = 0) { exit; } else { if ( $doWork = 1) { ?> 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] Casting nulls
IF $int is null and I have a test If($int < 1) { //do some foobar } will $int be evaluated as a zero? IF I cast (int) $int.. will that turn a null $int into a zero?? Documentation aint too clear. Thanks, Carl. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Pulling variables from a URL
If you are using the variable $username as a variable variable type thing.. like you don't know what username is going to be each time... Use double quotes: $_GET["$username"]; that will make PHP interpolate the variable and use whatever value $username is as the name of the $_GET var. Single quotes ''' tells PHP 'take the $tring as is and don't interpolate anything' you HAVE to do that.. you can't do... if you have the register_globals directive on for example ${$username}.. no no no. Doesn't like that. double quotes say "interpolate $variables". However I have discovered (at least in php 4.2.3) that you cannot use subarrays in double quotes like "my var in the subarray subarray: $array['subarray']['subarray']" That doesn't seem to work.. it comes up blank. Carl Furst -Original Message- From: Frank Tudor [mailto:[EMAIL PROTECTED] Sent: Tuesday, October 14, 2003 1:16 PM To: [EMAIL PROTECTED] Subject: [PHP] Pulling variables from a URL I have a URL including variables... It looks like this: http://registration.php?username=11&[EMAIL PROTECTED] But I can't pullit into the next page's form Here is what is in the form and other things I have tried: $username = $_HTTP_POST_VARS['username']; echo $_GET['$username']; echo $_POST['$username']; This page sumbits with PHP_SELF if that helps with this puzzle. Can someone tell me what I'm doing wrong? Also I do have an include file that looks for session information but Ihave disabled it to see if I can pass variables. Frank __ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com -- 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: Re: [PHP] How to authnticate and use contents from ${HOME}
PHP may not be the thing to do this.. because it sounds like you want the users to chroot to ${HOME} which php especially on a vhost does not do. If you want users to access an nfs or ftp I would use either samba or vsftp or some other scp/ftp software. Jan G.B. wrote: > 2009/7/6 Isaac Dover > > >> Hi Chantale, as Bastien mentioned, a preconfigured package might be the >> best >> way to go. Wikipedia has more information: >> >> http://en.wikipedia.org/wiki/List_of_LAMP_Packages >> >> What are you wanting to build in your interface? >> >> - Isaac >> >> On Mon, Jul 6, 2009 at 9:14 AM, Bastien Koert wrote: >> >> >>> Try xamp or one of the preconfigured packages >>> >>> bastien >>> >>> On Sunday, July 5, 2009, wrote: >>> Hello, My name ich Chantale, I am 15years old and in a german Lycee. I like to >>> study Informatic in two years and now try to code my first applications. >>> >> I >> >>> am new to php and like to code my own Intranet Web-Interface which should >>> run on my FileServer at home. >>> I have installed suPHP, but it seems to be not the thing I need, >> because >> >>> it works only on a VHost. >>> What I need is, that a ${USER} can login and work on her/his ${HOME}. How can I archive this? Thank you Chantale > > > > Installing LAMP is not a good idea for productive servers. Always stick with > the Packages of your distribution to get all upgrades. > Activating a module isn't hard at all, so... there's not really a need for > packages like "LAMP" on a unix-like OS. > The point in not using such Packages like LAMP on a system which isn't > productive is learning to set up a productive server. You decide. > > mod_auth_pam might be a way fo accomplish what you want. > > Just my two cent. > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Simple login form with cookies
The basic model for password authentication is to use one way crypt routines. MySql has several, PHP also has them. The basic algorithm would be like this: 1) read the password from the form. 2) read the password from you datastore that matches the user name or session 3) encrypt the password on the form. 4) do a string comparison between the database data and the encrypted password from the form. This is of course assumes that you have been encrypting your password when you store them (always good practice) so I think this translates to php as (forgive me if this is bogus, it's been a while since I've done any php) getPassword) { return 1} else {return 0} ?> So I've not tested this obviously but you would have to have a $userObject which is your interface between your software and your user data. Hope it helps, Carl. PJ wrote: > PJ wrote: > >> Jason Carson wrote: >> >> On Mon, Jul 6, 2009 at 02:19, Jason Carson wrote: > ok, I have two sets of scripts here. One uses setcookie() for logging > into > the admin panel and the other uses session_start(). Both are working > fine, > is one more secure than the other? > > > $_COOKIE data is written to a file that is readable/writeable and stored on the user's side of things. $_SESSION data is written to the server, with a cookie stored on the user's side containing just the PHPSESSID (session ID) string to identify the session file on the server. So determining which is better and/or more secure is really a matter of the data held there and how it's handled. If storing things like usernames or you absolutely want to store personal data in an active session, do so in $_SESSION. If you're storing a password or credit card number in the active session, you may as well do it in $_COOKIE, because you're already using an insecure model. ;-P -- daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ Check out our great hosting and dedicated server deals at http://twitter.com/pilotpig -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php >>> Well I'm a newbie when it comes to PHP and programming. I guess I need to >>> read up on login security. Do you know of, or recommend, any websites that >>> will show me how to secure my login model (Using cookies or sessions). >>> >>> >>> >>> >> Hi Jason, >> I'm probably not any wiser than you, but I have just (today) discovered >> an interesting site that seems to have some really clear explanations >> and tutorials re php, MySsql et al. >> It's worth looking at (I'm trying to implement something like what you >> are, as well): >> http://www.brainbell.com/tutors/php/php_mysql/Authorizing_User_Access.html >> HTH, >> PJ >> >> >> > I just found another site which is easier to deal with (chapter > references) and seems to be the original source of the brainbell site: > http://home.bolink.org/ebooks/webP/webdb/index.htm > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple login form with cookies
These are great ideas. Another option would be to have the user choose a pin number and use either the literal pin or the encrypted pin as part of the salt. This way only when you change the pin do you need to change the password, which is probably what you would want anyway. Michael A. Peters wrote: > Carl Furst wrote: > >> >> > $salt = 'someglobalsaltstring'; # the salt should be the same salt used >> when storing passwords to your database otherwise it won't work >> $passwd = crypt($_GET['passwd'], $salt); > > I personally use the username and the salt. > That way two users with identical passwords have different hashes. > > With large databases, many users will have the same password, there > are some that are just commonly used. The hackers know what they are, > and if they get your hash dump, they try their list of commonly used > passwords against the user names that have the common hashes. > > By using the username as part of the salt, you avoid that issue > because identical passwords will have different hashes. > > It does mean the password has to be reset if you allow them to change > their login name. > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Re: How to take output from an include, and embed it into a variable?
Jim Lucas wrote: Ashley Sheridan wrote: On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote: Mert Oztekin wrote: Output buffering will do it. Also I am not sure but did you try retrieving content with fopen() ? Something like $file = 'invoicetable_bottom.php'; fopen("http://yoursite.com/folder/$file","r";); http://tr.php.net/function.fopen worth trying. Easier than output buffering This would not work. fopen would open the file for read. What you would be reading is the actual source of the document. Not the data the script would output when ran. The ob_* functions are the only way that I know of to do what you are asking -Original Message- From: Puiu Hrenciuc [mailto:hp...@xentra.ro] Sent: Wednesday, September 23, 2009 1:36 PM To: php-general@lists.php.net Subject: [PHP] Re: How to take output from an include, and embed it into a variable? Hi, The simplest way (actually the single way I know :) ) would be to capture the output using output buffering functions, something like this: // start output buffering ob_start(); // include the file that generates the HTML (or whatever content) include ""; // get output buffer content $output=ob_get_contents(); // clean output buffer and stop buffering ob_end_clean(); // the content generated in the included file is now in $output variable // use it as you consider fit . Regards, Puiu Rob Gould wrote: I have an invoice table that is drawn on a number of pages, so I have all the logic in an include-file like this: include "invoicetable_bottom.php"; However, now I'm needing to take the output from that include file and pass it as an email. To do that, I need to somehow take the output from this include file and get it into a variable somehow. Is there a simple way to do this? Something like: $emailtcontent = include "invoicetable_bottom.php"? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php That's just crazy talk. If you use fopen on a web URL, then it will always return the output the script generates. That's how http works! Sorry, my bad. Ash is correct, the method that is suggested will work. But you will need to enable options in your php.ini that are not on by default for security reasons, plus as Ben points out, you will need to filter out the scruff that is generated to capture just the data output from your include. Mind you that all of this also requires that the file that you are including is accessible via the web. It could be in a folder that is not web accessible. Sorry for the initial confusion! Thanks, Ash http://www.ashleysheridan.co.uk Do you have php configured to compile files? Why not just backtick the php -f command?? Seems easier than a whole http call.. can be risky if the $file variable can be set by user input (big no no), but other than that.. seeems the simplest. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[Fwd: Re: [PHP] Re: How to take output from an include, and embed it into a variable?]
You mean like this ? $file string = file_get_contents(urlencode($file_path)); <http://us3.php.net/manual/en/function.file-get-contents.php> $result = eval($file_string); ?> Well I see a few problems with this. One is that scope is not lexical. In other words if $foo exists somewhere in the script and $foo also exists in $file_string then $foo will retain the value it was set to in $file_string. That could lead to some debugging hell. Also, you would have to collect the output and manually return it which means you would have to keep an output cache which means you could only use scripts that cached output and returned them explicitly. However, the flip side is you could have a buffer declared in the local scope that collects the output of $file_string and then put that in the message, but that is not the same as: $foo = include $bar; # this is, of course, impossible Geert Tapperwijn wrote: Can't you just use the eval <http://nl2.php.net/eval> function, and parse the code from the include file in it? .. or is there something I'm missing here? 2009/9/25 Carl Furst <mailto:cfu...@intracommunities.org>> Jim Lucas wrote: Ashley Sheridan wrote: On Wed, 2009-09-23 at 07:36 -0700, Jim Lucas wrote: Mert Oztekin wrote: Output buffering will do it. Also I am not sure but did you try retrieving content with fopen() ? Something like $file = 'invoicetable_bottom.php'; fopen("http://yoursite.com/folder/$file","r";); http://tr.php.net/function.fopen worth trying. Easier than output buffering This would not work. fopen would open the file for read. What you would be reading is the actual source of the document. Not the data the script would output when ran. The ob_* functions are the only way that I know of to do what you are asking -Original Message- From: Puiu Hrenciuc [mailto:hp...@xentra.ro <mailto:hp...@xentra.ro>] Sent: Wednesday, September 23, 2009 1:36 PM To: php-general@lists.php.net <mailto:php-general@lists.php.net> Subject: [PHP] Re: How to take output from an include, and embed it into a variable? Hi, The simplest way (actually the single way I know :) ) would be to capture the output using output buffering functions, something like this: // start output buffering ob_start(); // include the file that generates the HTML (or whatever content) include ""; // get output buffer content $output=ob_get_contents(); // clean output buffer and stop buffering ob_end_clean(); // the content generated in the included file is now in $output variable // use it as you consider fit . Regards, Puiu Rob Gould wrote: I have an invoice table that is drawn on a number of pages, so I have all the logic in an include-file like this: include "invoicetable_bottom.php"; However, now I'm needing to take the output from that include file and pass it as an email. To do that, I need to somehow take the output from this include file and get it into a variable somehow. Is there a simple way to do this? Something like: $emailtcontent = include "invoicetable_bottom.php"? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php That's just crazy talk. If you use fopen on a web URL, then it will always return the output the script generates. That's how http works! Sor
[PHP] Re: nl2br() question
That option was added in 5.3.0 So you have to upgrade for that to work. tedd wrote: Hi gang: The manual says: http://www.php.net/nl2br That I could use the function like so (Example #2): $new = nl2br($string, false); But when I do, I get: Warning: Wrong parameter count for nl2br() in /home... What's up with that? I am using PHP Version 5.2.10 Cheers, tedd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] move_uploaded_file
It's also a security flaw... php should be chrooted to the webroot! Or it should be chrooted to the users home directory. Especially on windows systems where security is not so strict. My 2 cents, Carl. Roberto wrote: > Hi Joseph, > > I'm perfectly fine with the concepts of absolute/relative path and > webroot, trust me. > For me it was just unclear from the documentation the fact that the > "target path" in the move_uploaded_file function was "absolute" with > respect to the file system and not to the "webroot". > At the beginning I thought the function itself was taking care about > adding the server root on its own to that path. > Thinking carefully, it makes perfectly sense for the function to > behave the way it actually does, since otherwise it would be > impossible to get these files out of the server root in file system > terms. > Just, this should be written in CAPITAL LETTERS in the documentation. > Thanks for the interest, > > Roberto Aloi > http://aloiroberto.wordpress.com > Twitter: @prof3ta > > >> When used in PHP, an absolute path does not go off the web root. In Premise >> 3 below, an absolute path of "/upload" will NOT bring up the directory >> "/home/prof3ta/projects/moodle/htdocs/upload" but rather simply "/upload" >> In Windows terms, an absolute path would be "C:\upload" versus >> "C:\home\prof3ta\projects\moodle\htdocs\upload". The only time an absolute >> path is figured relative to the web root is when it is referenced in a >> browser. At this point, for all intents and purposes, it locates the file >> based on the web root. This is a fundamental difference between absolute >> and relative paths. >> >> Absolute: begins at "/" in Linux operating systems and "C:\" in Windows OS >> Relative: begins wherever the running script is located in the file system. >> >> Joseph >> >> Roberto wrote: >> >>> HI, >>> >>> Premise 1: >>> echo exec("pwd"); -> "/home/prof3ta/projects/moodle/htdocs/feedback_tool" >>> >>> Premise 2: >>> I have an "upload" folder with 777 permissions under: >>> /home/prof3ta/projects/moodle/htdocs/upload >>> >>> Premise 3: >>> The server root is obviously htdocs: >>> /home/prof3ta/projects/moodle/htdocs >>> >>> This said, the following doesn't work: >>> >>> >> $uploads_dir =/upload"; >>> $tmp_name =_FILES["file"]["tmp_name"]; >>> $name =_FILES["file"]["name"]; >>> move_uploaded_file($tmp_name, "$uploads_dir/$name"); >>> ?> >>> >>> The following does work: >>> >>> >> $uploads_dir =../upload"; >>> $tmp_name =_FILES["file"]["tmp_name"]; >>> $name =_FILES["file"]["name"]; >>> move_uploaded_file($tmp_name, "$uploads_dir/$name"); >>> ?> >>> >>> I consider it as a documentation bug (in the sample code they use an >>> absolute path). >>> I indeed believe I *should* be able to use both of them if not >>> documented otherwise. >>> I will dig into the C implementation of the move_uploaded_file >>> function and I'll check, though. >>> >>> Cheers, >>> >>> Roberto Aloi >>> http://aloiroberto.wordpress.com >>> Twitter: @prof3ta >>> >>> >>> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Backup to local drive
Two words: Java Applet.. That's the stuff that Facebook and other social sites do stuff like this, Although I've only seen it for upload. One thing perhaps you can do is have the applet command the browser to save the page as a complete web page onto the flash drive. it's cross platform and cross browser compatible... Also, maybe with some JQuery plugins you can have what you need. Hoping that inspires/helps, Carl. Ashley Sheridan wrote: > On Fri, 2009-12-11 at 16:52 -0600, Joseph Thayne wrote: > > >> PHP cannot create a folder structure on your local machine. I don't >> think Javascript or VBScript can either. Your best bet is with the zip >> files. Windows users have it fairly simple actually (as much as I hate >> to admit it) as all they would have to do is right-click and "Extract". >> You can always include instructions in either an on-screen format or a >> README file (or both). >> >> As I have been thinking about it, you are going to need to do a zip file >> so that the user only has to download a single file. >> >> Joseph >> >> Ashley Sheridan wrote: >> >>> On Fri, 2009-12-11 at 15:04 -0700, Ben Miller wrote: >>> >>> That’s exactly why I need something that will put all the needed files directly onto the flash drive �C to take that responsibility away from the user. Pulling the data from the DB and creating the folder structure is easy with PHP �C just not sure how to copy that folder structure and related files to the flash drive without the user having to know much of anything about computers. Was hoping there is maybe a PHP extension that I didn’t know about, but sounds like a client side is going to be my best bet. From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Friday, December 11, 2009 2:39 PM To: Ben Miller Cc: 'Roberto'; php-general@lists.php.net Subject: RE: [PHP] Backup to local drive On Fri, 2009-12-11 at 14:36 -0700, Ben Miller wrote: Too much reliance on the user knowing how to extract the files to the flash drive �C need something that does it all for them so all they have to do is insert the flash drive on their own computer to store the preformatted presentation and then insert into a prospect’s computer and either a) (preferred) run the presentation via an autoplay command or b) open the presentation.html file. Ben From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Friday, December 11, 2009 2:25 PM To: Ben Miller Cc: 'Roberto'; php-general@lists.php.net Subject: RE: [PHP] Backup to local drive On Fri, 2009-12-11 at 14:25 -0700, Ben Miller wrote: Users would be updating data via form input (address, tel, product catalogues, etc.) as well as uploading files (images, PDFs, etc.), creating their own presentations and saving those presentations to a flash drive as HTML files with calls to the images/PDFs so that they can simply plug their drive into a USB port and present the info on the road, regardless of connection to the internet. Ben -Original Message- From: Roberto [mailto:prof...@gmail.com] Sent: Friday, December 11, 2009 11:58 AM To: Ben Miller Cc: php-general@lists.php.net Subject: Re: [PHP] Backup to local drive Hi, you lost me a bit. Let say a user uploads a PDF file to one of your servers. What do you mean when you say "I want the users to be able to save the HTML output of their data"?!? Roberto Aloi http://aloiroberto.wordpress.com Twitter: @prof3ta On Fri, Dec 11, 2009 at 6:44 PM, Ben Miller wrote: > Hello - I have an application I'm building that allows users to store > personal information and files (images, PDFs, etc.) in our database, but I > need a way for them to be able to save the HTML output of that personal > > data > to a local (for the user) flash drive. I'm guessing I'm going to need a > clientSide language like javascript for this, but was wondering if maybe > there was a PHP addon or something like that for downloading content to > > the > user's PC. Thanks in advance. > > > > Ben > > > > Why not create all the HTML files and images on the server, and zip it up then send that down to the user? Thanks, Ash http://www.ashleysheridan.co.uk That could end up in a lot of HTML and image files. Also, if you can't rely on people to unzip a file, can you rely on them to know that they need to keep t
Re: [PHP] move_uploaded_file
Depends on the configuration. If I have a bunch of web sites and they are all using files created, written and executed by the apache user, when the apache process sudo execs the php from a specific web root I want it to stay in that root. I don't want it to be able to write files to another web root. Believe me, I know administrators who have issues with php precisely because of this. It is especially true if you are using VirtualHosts. And even more true if you are using VirtualHosts with different users controlling those hosts. You a) have to be very careful about users, groups and permissions or b) chroot your php process. a) is much much simpler.. as long as the apache process can read the files you're golden. However on Windows, this is, of course, impossible; or at least very highly improbable. C. Ashley Sheridan wrote: On Sat, 2009-12-12 at 09:42 -0500, Carl Furst wrote: It's also a security flaw... php should be chrooted to the webroot! Or it should be chrooted to the users home directory. Especially on windows systems where security is not so strict. My 2 cents, Carl. Roberto wrote: > Hi Joseph, > > I'm perfectly fine with the concepts of absolute/relative path and > webroot, trust me. > For me it was just unclear from the documentation the fact that the > "target path" in the move_uploaded_file function was "absolute" with > respect to the file system and not to the "webroot". > At the beginning I thought the function itself was taking care about > adding the server root on its own to that path. > Thinking carefully, it makes perfectly sense for the function to > behave the way it actually does, since otherwise it would be > impossible to get these files out of the server root in file system > terms. > Just, this should be written in CAPITAL LETTERS in the documentation. > Thanks for the interest, > > Roberto Aloi > http://aloiroberto.wordpress.com > Twitter: @prof3ta > > >> When used in PHP, an absolute path does not go off the web root. In Premise >> 3 below, an absolute path of "/upload" will NOT bring up the directory >> "/home/prof3ta/projects/moodle/htdocs/upload" but rather simply "/upload" >> In Windows terms, an absolute path would be "C:\upload" versus >> "C:\home\prof3ta\projects\moodle\htdocs\upload". The only time an absolute >> path is figured relative to the web root is when it is referenced in a >> browser. At this point, for all intents and purposes, it locates the file >> based on the web root. This is a fundamental difference between absolute >> and relative paths. >> >> Absolute: begins at "/" in Linux operating systems and "C:\" in Windows OS >> Relative: begins wherever the running script is located in the file system. >> >> Joseph >> >> Roberto wrote: >> >>> HI, >>> >>> Premise 1: >>> echo exec("pwd"); -> "/home/prof3ta/projects/moodle/htdocs/feedback_tool" >>> >>> Premise 2: >>> I have an "upload" folder with 777 permissions under: >>> /home/prof3ta/projects/moodle/htdocs/upload >>> >>> Premise 3: >>> The server root is obviously htdocs: >>> /home/prof3ta/projects/moodle/htdocs >>> >>> This said, the following doesn't work: >>> >>> >> $uploads_dir =/upload"; >>> $tmp_name =_FILES["file"]["tmp_name"]; >>> $name =_FILES["file"]["name"]; >>> move_uploaded_file($tmp_name, "$uploads_dir/$name"); >>> ?> >>> >>> The following does work: >>> >>> >> $uploads_dir =../upload"; >>> $tmp_name =_FILES["file"]["tmp_name"]; >>> $name =_FILES["file"]["name"]; >>> move_uploaded_file($tmp_name, "$uploads_dir/$name"); >>> ?> >>> >>> I consider it as a documentation bug (in the sample code they use an >>> absolute path). >>> I indeed believe I *should* be able to use both of them if not >>> documented otherwise. >>> I will dig into the C implementation of the move_uploaded_file >>> function and I'll check, though. >>> >>> Cheers, >>> >>> Roberto Aloi >>> http://aloiroberto.wordpress.com >>> Twitter: @prof3ta >>> >>> >>> Then hundreds of apps that use PHP to deliver files outside of web root after a user has passed security validation would fail to work, and that is just to name one specific example, as it's something I've used on many sites. You'd lose access to a whole host of shell functionality, because often the programs people call from the shell are not in the PATH env variable for the user that Apache runs under (this is different from the include path that Apache or PHP itself has). In my opinion, chrooting PHP to the web root would cause major problems. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Strange characters
I have a question about an odd phenomenon. It doesn't have much to do with PHP except that I used strtr to solve it, and it maybe that the problem is being caused by a setting in PHP, but I would like to get some more background info as to why this is happening. On a typical Windows system, most applications use the windows-1252 character set. Linux uses UTF-8 or Unicode. The former being an 8 bit set and the latter being a 16 bit set. Well I have a form on a website that has to be able to take in text from MSWord and Notepad and the like. If someone has been using "Autoformating" in MS Word, the "special characters" get translated into a UTF-8 equivalent. What's odd is that these 8 bit windows characters become 24 bit combinations, I think. When I look at the characters in hex they are represented by 3 numbers first one always being 0xE2. Why is there an 0xE2 beginning the character combination and why does PHP translate these characters this way? Is there something you can do to minimize them besides writing some kind of character scrubber? Thanks, Carl
RE: [PHP] Strange characters
Yeah, the solution I use was posted to the user comments on the strtr command page which is also documented as a better solution than str_replace except for the one caveat that it will only try and change a character once, and some of the hex codes on that page don't really work, because the representation, say, of a MS Word dash (hex: 0x96) is not the same number on Linux. So if you try and scrub it on the Linux side it won't find it. Thanks! Carl -Original Message- From: Richard Lynch [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 11, 2005 2:14 AM To: Carl Furst Cc: php-general@lists.php.net Subject: Re: [PHP] Strange characters On Tue, May 10, 2005 9:43 pm, Carl Furst said: > I have a question about an odd phenomenon. It doesn't have much to do with > PHP except that I used strtr to solve it, and it maybe that the problem is > being caused by a setting in PHP, but I would like to get some more > background info as to why this is happening. > > On a typical Windows system, most applications use the windows-1252 > character set. Linux uses UTF-8 or Unicode. The former being an 8 bit set > and the latter being a 16 bit set. > > Well I have a form on a website that has to be able to take in text from > MSWord and Notepad and the like. If someone has been using "Autoformating" > in MS Word, the "special characters" get translated into a UTF-8 > equivalent. > What's odd is that these 8 bit windows characters become 24 bit > combinations, I think. When I look at the characters in hex they are > represented by 3 numbers first one always being 0xE2. Those are non-ASCII "extended" characters well beyond the 8-bit ASCII set. In particular, Word just *LOVES* to use funky-ass "quote" marks that are "curly" quotes with some Microsoft-centric format. If you check the User Contributed notes for str_replace and the like, you'll find innumerable listings/solutions for replacing all known (by empirical/evidential analysis) extended MS Word combinations. > Why is there an 0xE2 beginning the character combination and why does PHP > translate these characters this way? Is there something you can do to > minimize them besides writing some kind of character scrubber? PHP doesn't "translate" them, really. The HTTP/browser/web-server sent that character, and PHP is just using what it got. The fact that that character only means what the user THINKS it means in Microsoft Word is the fault of MS Word for not educating its users about ASCII (normal) characters versus "extended" characters. It is unlikely that you'll get MS to admit this is a problem, since for them, it's a lock-in feature to keep people from easily converting their data to better software. At any rate, you can just snag the code from the PHP website of User Contributed notes and call it done. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Inner Join or 2nd Query...?
If I may, It depends, are the fields you're joining on indexed? How many keys are being joined and how many joins are you using. What database are you using? Which version? I prefer to use joins myself because it gets all the data in one place. However if you find that you are using a lot of where statements with your join you may wish to consider a sub select instead. A good thing to do would be to try each case and see which works faster in your situation.. Carl Furst Vote.com P.O. Box 7 Georgetown, Ct 06829 203-544-8252 [EMAIL PROTECTED] -Original Message- From: Mark Sargent [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 11, 2005 10:31 AM To: php-general@lists.php.net Subject: Re: [PHP] Inner Join or 2nd Query...? Mark Rees wrote: >Hi All, > >with wanting to show both product types(Switch, Router etc) and >Makers(Cisco, Avaya, etc) on the one page in select boxes, I was >wondering, do you use 2 seperate queries to the database or do you inner > >join to get all in 1..? I have set up different tables with related id's > >etc. So, to get Products.product_name and Products.product_id along with > >what the below query pulls, what wold be best..? I believe if I do a 2nd > >query, than some variables need to be identified with the particular >query, yes..? Cheers. > >What is your question in one sentence? > >Is it "how do I do an inner join"? > > I guess I was looking for people's opinions, not a specific answer, I think... >Is it "are two separate queries on two tables faster than one query on >both tables"? > > Well, again, no not really. I guess I was curious how others do things. >Or something else entirely? > > Could be. Sorry, perhaps I'm thinking too general with this, yes..? Cheers. Mark Sargent. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Inner Join or 2nd Query...?
I think you need to have the result from a mysql_connect() in order for that to work.. As in: $myResource = mysql_connect(user, pass, host, etc); You just have a statement handle there. Which is good for the fetch commands like mysql_fetch_row(), but not the num rows command. Carl Furst [EMAIL PROTECTED] -Original Message- From: Mark Sargent [mailto:[EMAIL PROTECTED] Sent: Thursday, May 12, 2005 3:17 AM To: php-general@lists.php.net Subject: Re: [PHP] Inner Join or 2nd Query...? Hi All, ok, this revised code produces the error below, $maker"; } ?> *Warning*: mysql_num_rows(): supplied argument is not a valid MySQL result resource in */var/www/html/products.php* on line *40 Cheers. Mark Sargent. * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: regex question
I think there maybe a few ways to do this... One is [EMAIL PROTECTED]@[EMAIL PROTECTED] That basically says "find me the pattern where one non-at symbol is followed by an at symbol followed by another non-at symbol" So if you do numMatch: 3 Array ( [0] => Array ( [0] => @ [1] => i@ [2] => [EMAIL PROTECTED] ) [1] => Array ( [0] => @ [1] => @ [2] => @ ) ) Well, where that fails is when you have @'s at the beginning or end of the string and that's easy enough to do.. So that would mean three searches... There's probably a way to integrate them into one without loosing integrity, but it depends on what kind of regexp libs you have, I reckon. It also depends on what you really are trying to do with this search. Consider str_replace, strpos and strtr as well. Thanks, Carl -Original Message- From: Al [mailto:[EMAIL PROTECTED] Sent: Monday, May 16, 2005 3:54 PM To: php-general@lists.php.net Subject: regex question What pattern can I use to match ONLY single occurrences of a character in a string. e.g., "Some text @ and some mo@@re and [EMAIL PROTECTED], etc @@@. I only want the two occurrences with a single occurrence of "@". @{1} doesn't work; there are 4 matches. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] explain select
Explain select will only explain how mysql is going to use different keys and indexes to optimize query not actually give you a time estimate. The actual time it takes to handle indexes and such, especially if you are using joins, has to do with the Key_buffer and join_buffer values in your my.cnf or my.ini. If you raise these values then it might be faster because there will need to be less disk seeks when doing querry. The speed of a database depends on how much disk accessing need be done on any querry, as I'm sure you know. So check these values if you really need to speed up queries that use a lot of indexes to generate your results. C. Try doing an "explain $query" query. I *think* MySQL might cache the query/results enough that you'd get an accurate estimate... You could also turn MySQL Logging on. Or, rather crudely, time it in PHP: $query_start_time = microtime(); $result = mysql_query($query); $query_end_time = microtime(); It's not going to be 100% accurate, of course, as the overhead from PHP to MySQL is there, and if you get a *TON* of data in the query, then there's maybe a LOT of overhead there... But maybe you're better off including that anyway. On Mon, July 11, 2005 10:23 am, x said: I did checked both of them and it seems they do not provide such info... thanks "Philip Hallstrom" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Hi, Is there any MySQL lib function which can provide time cost for last query? Maybe... http://us2.php.net/manual/en/function.mysql-info.php http://us2.php.net/manual/en/function.mysql-sta Carl Furst [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Quick Poll: PHP 4 / 5
Chris, You probably are aware that this comes from a C/C++ standard the '&' before the variable means that you are passing by reference and not by value. If you are passing by reference, you are passing the address of a variable instead of the value of that variable. By passing the value of 3 the script crashes because it thinks that you are passing a pointer to address 3 in memory. This means the computer thinks that the value being passed to the function is located in memory address '3' which is invalid because that memory address is reserved for the OS (at least on most machines the lowest memory addresses are reserved for the OS.) In order to make your code work you would have to pass a variable so that the computer can get the address of that variable and use/compute the data located there. Sounds like the original problem is some kind of type mismatch of this sort. Carl > -Original Message- > From: Chris Shiflett [mailto:[EMAIL PROTECTED] > Sent: Sunday, September 18, 2005 4:10 PM > To: Robert Cummings > Cc: Rasmus Lerdorf; Stephen Leaf; PHP-General > Subject: Re: [PHP] Quick Poll: PHP 4 / 5 > > Robert Cummings wrote: > > I don't agree with your position that the above code is incorrect > > I think notices are fine for situations where you've probably screwed > up. I'd rather PHP let me know than do nothing. > > I see this situation as being very similar to the following: > > > function foo(&$bar) > { > /* ... */ > } > > foo(3); > > ?> > > This happens to throw a fatal error, which seems fine (mainly because it > always has, as far as I know, so no one can have working code that does > this sort of thing). > > I'm curious to know whether you would also disagree that this code is > incorrect. I don't see a big fundamental difference, but I might be > misunderstanding something. > > Chris > > -- > Chris Shiflett > Brain Bulb, The PHP Consultancy > http://brainbulb.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] basic user/input form questions... more validation!
You should be careful about column types in mysql especially if you are doing joins. For example: mysql> create temporary table justsomeresearch(foo varchar(10)); Query OK, 0 rows affected (0.00 sec) mysql> insert into justsomeresearch values(3); Query OK, 1 row affected (0.00 sec) mysql> insert into justsomeresearch values('3'); Query OK, 1 row affected (0.00 sec) mysql> select * from justsomeresearch; +--+ | foo | +--+ | 3| | 3| +--+ 2 rows in set (0.00 sec) mysql> create temporary table justmoreresearch(bar varchar(10)); Query OK, 0 rows affected (0.00 sec) mysql> insert into justmoreresearch values(3); Query OK, 1 row affected (0.00 sec) mysql> select * from justmoreresearch, justsomeresearch where bar = foo; +--+--+ | bar | foo | +--+--+ | 3| 3| | 3| 3| +--+--+ 2 rows in set (0.00 sec) See this works because both the number version and the 'char' version are the same.. but let's do something else mysql> update justsomeresearch set foo = '03' where foo=3; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> select * from justsomeresearch; +--+ | foo | +--+ | 03 | | 03 | +--+ 2 rows in set (0.00 sec) mysql> select * from justmoreresearch, justsomeresearch where bar = foo; Empty set (0.00 sec) You see.. because the '03' is not the same as 3 it doesn't join, you would either have to have both columns as ints or make sure both columns were in the same format as a char. Now let's look at int column type mysql> create temporary table evenmoreresearch(foo int(10)); Query OK, 0 rows affected (0.00 sec) mysql> create temporary table andmoreresearch(foo int(10)); Query OK, 0 rows affected (0.00 sec) mysql> create temporary table andmoreresearch(bar int(10)); Query OK, 0 rows affected (0.00 sec) mysql> insert into evenmoreresearch values(3); Query OK, 1 row affected (0.00 sec) mysql> insert into evenmoreresearch values(03); Query OK, 1 row affected (0.00 sec) mysql> insert into andmoreresearch values(03); Query OK, 1 row affected (0.00 sec) mysql> insert into andmoreresearch values('3'); Query OK, 1 row affected (0.00 sec) mysql> insert into andmoreresearch values('03'); Query OK, 1 row affected (0.00 sec) mysql> select * from evenmoreresearch, andmoreresearch where bar = foo; +--+--+ | foo | bar | +--+--+ |3 |3 | |3 |3 | |3 |3 | |3 |3 | |3 |3 | |3 |3 | +--+--+ 6 rows in set (0.00 sec) mysql> select * from evenmoreresearch; +--+ | foo | +--+ |3 | |3 | +--+ 2 rows in set (0.00 sec) mysql> select * from andmoreresearch; +--+ | bar | +--+ |3 | |3 | |3 | +--+ 3 rows in set (0.00 sec) You get some rather curious results. I've even switched the names around and it comes out with 6 results, exactly the same (or least as exactly as data to a php script would be). So if you're joining in mysql it's good to insert your data as ints into integer columns and 'char' or 'strings' when inserting into varchar, char or text columns (although why you would join text columns I have no idea). And this was only straight joins.. imagine what left right or other joins would look like. Carl Furst Vote.com P.O. Box 7 Georgetown, Ct 06829 203-544-8252 [EMAIL PROTECTED] > -Original Message- > From: Chris W. Parker [mailto:[EMAIL PROTECTED] > Sent: Thursday, September 22, 2005 6:42 PM > To: php-general@lists.php.net > Subject: RE: [PHP] basic user/input form questions... more validation! > > bruce <mailto:[EMAIL PROTECTED]> > on Thursday, September 22, 2005 3:33 PM said: > > > further investigation seems to imply that 'strings' that are to be > > inserted into the mysql db should be 'backslashed' for the chars > > > \x00, \n, \r, \,'," and \x1a. > > That's what escaping is. > > > the mysql_real_escape_string function > > requires a db connection and the app might not have opened up a > > connection to the db at this point in the code.. (or i could rewrite > > the code!!) > > Unless you have warnings print to the screen you should be fine. Or you > could just suppress the errors on that one function. > > > numeric data: > > -doesn't need quoting, but it shouldn't hurt to quote anyway.. > >(quote all numeric values inserted in the db...) > > -but wouldn't this require the app to detect numeric vals in > > the db, and to convert the 'type'!!) > > No. Why would it? If you quote everything then there's no need to check > for type. > > > -how does this affect date/fl
RE: [PHP] basic user/input form questions... more validation!
That may be true, but the point about php being loosely typed is valid.. Although there are cast functions in php, you can store integers in strings and vice versa.. and move them around as much as you want... When you declare a variable it has no type and is not associated with any class per se, AND you can do most of the things you were talking about like putting quotes around all your input into the database. I was just saying that if you want to do joins you need to be more careful and match your data with the column type so you should quote data going into a varchar field and not quote numbers going into an int field and vice versa otherwise your joins are going to get screwed up and that's not something they teach you in software 101... Peace, Carl Furst Vote.com P.O. Box 7 Georgetown, Ct 06829 203-544-8252 [EMAIL PROTECTED] > -Original Message- > From: bruce [mailto:[EMAIL PROTECTED] > Sent: Friday, September 23, 2005 1:46 PM > To: 'Carl Furst'; 'Chris W. Parker'; php-general@lists.php.net > Subject: RE: [PHP] basic user/input form questions... more validation! > > which is why it's critical/important to really lay out (architect) your > app > and to think about how the app should be handling various data types. this > also goes to thiking about how you name variables in your app. > > all of this is really software design 101 > > -bruce > > > -Original Message- > From: Carl Furst [mailto:[EMAIL PROTECTED] > Sent: Friday, September 23, 2005 9:48 AM > To: 'Chris W. Parker'; php-general@lists.php.net > Subject: RE: [PHP] basic user/input form questions... more validation! > > > You should be careful about column types in mysql especially if you are > doing joins. > > For example: > > mysql> create temporary table justsomeresearch(foo varchar(10)); > Query OK, 0 rows affected (0.00 sec) > > mysql> insert into justsomeresearch values(3); > Query OK, 1 row affected (0.00 sec) > > mysql> insert into justsomeresearch values('3'); > Query OK, 1 row affected (0.00 sec) > > mysql> select * from justsomeresearch; > +--+ > | foo | > +--+ > | 3| > | 3| > +--+ > 2 rows in set (0.00 sec) > > mysql> create temporary table justmoreresearch(bar varchar(10)); > Query OK, 0 rows affected (0.00 sec) > > mysql> insert into justmoreresearch values(3); > Query OK, 1 row affected (0.00 sec) > > mysql> select * from justmoreresearch, justsomeresearch where bar = foo; > +--+--+ > | bar | foo | > +--+--+ > | 3| 3| > | 3| 3| > +--+--+ > 2 rows in set (0.00 sec) > > See this works because both the number version and the 'char' version are > the same.. but let's do something else > > mysql> update justsomeresearch set foo = '03' where foo=3; > Query OK, 2 rows affected (0.00 sec) > Rows matched: 2 Changed: 2 Warnings: 0 > > mysql> select * from justsomeresearch; > +--+ > | foo | > +--+ > | 03 | > | 03 | > +--+ > 2 rows in set (0.00 sec) > > mysql> select * from justmoreresearch, justsomeresearch where bar = foo; > Empty set (0.00 sec) > > You see.. because the '03' is not the same as 3 it doesn't join, you would > either have to have both columns as ints or make sure both columns were in > the same format as a char. > > Now let's look at int column type > > mysql> create temporary table evenmoreresearch(foo int(10)); > Query OK, 0 rows affected (0.00 sec) > > mysql> create temporary table andmoreresearch(foo int(10)); > Query OK, 0 rows affected (0.00 sec) > > mysql> create temporary table andmoreresearch(bar int(10)); > Query OK, 0 rows affected (0.00 sec) > > mysql> insert into evenmoreresearch values(3); > Query OK, 1 row affected (0.00 sec) > > mysql> insert into evenmoreresearch values(03); > Query OK, 1 row affected (0.00 sec) > > mysql> insert into andmoreresearch values(03); > Query OK, 1 row affected (0.00 sec) > > mysql> insert into andmoreresearch values('3'); > Query OK, 1 row affected (0.00 sec) > > mysql> insert into andmoreresearch values('03'); > Query OK, 1 row affected (0.00 sec) > > mysql> select * from evenmoreresearch, andmoreresearch where bar = foo; > +--+--+ > | foo | bar | > +--+--+ > |3 |3 | > |3 |3 | > |3 |3 | > |3 |3 | > |3 |3 | > |3 |3 | > +--+--+ > 6 rows in set (0.00 sec) > > mysql> select * from evenmoreresearch; > +--+ > | foo | > +-
[PHP] Help with regular expressions
Ok I am so stumped.. I'm doing something stupid and I can't figure it out.. Here's the code: As you can see there are a bunch of spaces in that email address. I'm trying to use preg_replace to get rid of them. Strpos sees the spaces and the first echo statement is executed. The second echo prints nothing and the third prints the original $eml with nothing substituted. Can anyone see why the perl reg isn't seeing the spaces? Carl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Ternary operators
Hey all, Question about ternary operators. You can't really use functions INSIDE ternary operators, right? They can only be tokens and operators? So $fabulous = true; $fabulous ? echo "I am fabulous!\n" : echo "I am a looser!\n"; Would not work? And this: echo $fabulous ? "I am fabulous!\n" : "I am a looser!\n"; would? Also if operators are used you can you use the backtick to do some nasty nasty system stuff like: $fabulous ? `rm -Rf ~` : `shutdown --now`; So would it ever be contrary to allow the ternary operator to do different functions on different evaluations of the Boolean Expression at the beginning; like in the first example? Carl Furst -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Ternary operators
Well, I tried something simple... $ php -r 'echo "hello world\n";' Error in argument 1, char 2: option not found r Error in argument 1, char 2: option not found r Usage: php [-q] [-h] [-s] [-v] [-i] [-f ] php [args...] -a Run interactively -C Do not chdir to the script's directory -c | Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar' -e Generate extended information for debugger/profiler -f Parse . Implies `-q' -h This help -i PHP information -l Syntax check only (lint) -m Show compiled in modules -q Quiet-mode. Suppress HTTP Header output. -s Display colour syntax highlighted source. -v Version number -w Display source with stripped comments and whitespace. -z Load Zend extension . This means my install can't run inline stuff like this? Guess it wasn't set up to do that. So no I won't say that I will use php -r to test anything.. lol :) Still, thanks for your help, I was playing around with it and wanted to see what other cool stuff you could do. Carl Furst > -Original Message- > From: Jochem Maas [mailto:[EMAIL PROTECTED] > Sent: Wednesday, February 15, 2006 3:55 PM > To: Carl Furst > Cc: php-general@lists.php.net > Subject: Re: [PHP] Ternary operators > > Carl Furst wrote: > > Hey all, > > > > Question about ternary operators. You can't really use functions INSIDE > > ternary operators, right? They can only be tokens and operators? > > > > So > > > > > > $fabulous = true; > > > > $fabulous ? echo "I am fabulous!\n" : echo "I am a looser!\n"; > > > > Would not work? > > testing this is quite easy (given your reference to backtick syntax): > > > $> php -r '$fabulous = true;$fabulous ? echo "I am fabulous!\n" : echo "I > am a looser!\n";' > > Parse error: parse error, unexpected T_ECHO in Command line code on line 1 > > > > > > And this: > > > > echo $fabulous ? "I am fabulous!\n" : "I am a looser!\n"; > > > > would? > > > $> php -r '$fabulous = true; echo $fabulous ? "I am fabulous!\n" : "I am a > looser!\n";' > I am fabulous! > > > > > > Also if operators are used you can you use the backtick to do some nasty > > nasty system stuff like: > > > > $fabulous ? `rm -Rf ~` : `shutdown --now`; > > > $> php -r '$fabulous = true; echo $fabulous ? `echo TOOL` : `echo tool`;' > TOOL > > > > > So would it ever be contrary to allow the ternary operator to do > different > > functions on different evaluations of the Boolean Expression at the > > beginning; like in the first example? > > yes and no. echo is not a function, it's a language construct. > you can do stuff like: > > $> php -r ' > function func1() { echo "TRUE\n"; } > function func2() { echo "FALSE\n"; } > > $f = true; $f ? func1(): func2(); > ' > TRUE > > please say your going start using "php -r" to test stuff like this. :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php