[PHP] Getting IP from behind proxies
I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] saving temporary image to database
There is no imagejpeg() call in the code snippet you provided. And you don't say how it is failing. You haven't provided us with enough data to answer this question. -Rasmus On Sat, 29 Jun 2002, andy wrote: Hi there, I would like to save a jpg into a blob field of mysql. The function underneath works fine if I read the image from the temporary destination where php did put it after uploading. My problem is, that I would like to do some funky stuff to the image like changing colors or adding watermarks. So I have several functions ahead before I used to store them successfully to the file system. Now I would like to store it to a blob field, but this does not work. Like I said it works to store the temp file, but not the other one. I guess it has to do with something regarding the imagejpeg function. Here is what I tryed: # # save image to db into blob // this does not work (outputImg is a the colorcorrected file) $data = addslashes($outputImg); // this one would work # $data = addslashes(fread(fopen($picture_location, r), filesize($picture_location))); $stmt = INSERT INTO test.picture_test (file_name, file_type, picture) VALUES ('$name', '$picture_location_type', '$data') ; execute_stmt($stmt, $link); # Maybe some of you guy has a good idea on that. Thanx for any help, Andy -- 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] Getting IP from behind proxies
You can only get it if the proxy provides you with this data. Most don't, so this is not a reliable approach. -Rasmus On Sat, 29 Jun 2002, JJ Harrison wrote: I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.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
[PHP] need to change $ char in string
I've tried everything I can think of to change a dallar sign in a string to something else or to split the string on the $ but I can't the the information that comes after the $. Typical string contains: 1.2$General/ms1.zip when I try: $new_string = preg_replace(/\$/, %, $test_string); or (trying to avoid specifying the $): $new_string = preg_replace(/(\d\.\d{1,2})\D(\w.*$)/, \1%\2, $test_string); echo new_string is $new_string; prints new_string is 1.2 Has anyone solved this problem? Thanx, Bev -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Oracle 8 Functions Efficiency Problem
On Thu, Jun 27, 2002 at 11:09:23AM -0600, notoriousvic_ca wrote: I have an HTML form which allows users to query data in an Oracle 8 Database. Usualy a search may return over 100 records so I diplay 10 records per page. I would like to make the search more efficient by using the OCISetPrefetch to prefetch the first 10 records. This works great for the first page but for a page that displays records 90 to 100, I have to prefetch 100 records. I have two questions 1) Is there any way of fetching or Prefetching only say rows 80 to 90 of a result set? no - at some point the oci interface _will_ support scrollable cursors (= 9i only i think). that would allow you to skip records. 2) Has anyone tried to save a cursor or connection into a session? will not work. tc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Keeping Secrets in PHP Files
-Original Message- From: Peter J. Schoenster [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 1:27 AM To: [EMAIL PROTECTED] Subject: RE: [PHP] Keeping Secrets in PHP Files Yeah, you are assuming an environment that does not necessarily have to be. Why must one Apache server serve all users? Simply because that's the easiest way to do right out of the box? You have 2 scenarios as I see it: 1. Your own box -- no troubles other than the obvious 2. Virtual Server - One Apache for all users ... seems insecure 3. Virtual Server - One Apache for EACH user ... seems quite secure and experience confirms. Not to be picky but you said there werwe 2 scenarios :-) In any case, your #3 above works as long as each server runs in its own unique group, which is shares with the customer. Peter -- JR -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ASP style application-level variables
Hi, Apologies if this question has already been asked in the past, but I have only just registered for this list. Does PHP in anyway support ASP style application-level variables in a similair way to how standard sessions are used. Though of implementing this as either files or database records but the additional coding could be more error-prone or eat more system resources than using a feature built into PHP itself. I would be interested to hear other peoples views on this feature. Lee -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] ASP style application-level variables
This seems to be the question of the question of the week. No, there are no application level variables in PHP. You can set constants, either through your web server, or maybe PHP.ini, but that's about it. I think the easiest way to implement something like this would be to use the auto_append_file and auto_prepend_file settings of PHP.ini. Make that file load the application variables from the database, and the prepend file saves any changes... ---John Holmes... -Original Message- From: Lee [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 11:11 AM To: [EMAIL PROTECTED] Subject: [PHP] ASP style application-level variables Hi, Apologies if this question has already been asked in the past, but I have only just registered for this list. Does PHP in anyway support ASP style application-level variables in a similair way to how standard sessions are used. Though of implementing this as either files or database records but the additional coding could be more error-prone or eat more system resources than using a feature built into PHP itself. I would be interested to hear other peoples views on this feature. Lee -- 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 Digest 29 Jun 2002 13:33:03 -0000 Issue 1434
php-general Digest 29 Jun 2002 13:33:03 - Issue 1434 Topics (messages 104450 through 104483): Re: Constants 104450 by: John Holmes Re: Writing a GIF/JPG Image 104451 by: Anzak Wolf 104453 by: Brandon 104454 by: Rasmus Lerdorf 104455 by: Brandon 104458 by: Evan Nemerson Re: Keeping Secrets in PHP Files 104452 by: Jonathan Rosenberg 104459 by: Garth Dahlstrom 104461 by: Peter J. Schoenster Re: [mail] quetion 104456 by: Evan Nemerson 104480 by: Evan Re: encryption code in php 104457 by: Evan Nemerson Yet another session problem, with a twist. 104460 by: Cysec Re: Drop connection, keep running? 104462 by: Joshua Alexander Re: preg_replace pains 104463 by: Analysis Solutions Re: PHP with online cedit card processing 104464 by: Analysis Solutions 104468 by: Purushotham Komaravolu Re: Help adding variables from MySQL query 104465 by: Analysis Solutions SESSION's from common computers 104466 by: César Aracena 104467 by: John Holmes 104469 by: César Aracena 104470 by: John Holmes 104471 by: César Aracena 104472 by: John Holmes 104473 by: César Aracena Help please *** PHP4 not installed correctly 104474 by: Paul Godard 104477 by: Nookie Re: pop-up windows 104475 by: Mark Gallagher Re: Why isn't this working? 104476 by: JJ Harrison [GURU] PHP w/ Informix DB ISQL 7.20 and Dynamic server 7.30 104478 by: Emile Bosch session.use_trans_sid 104479 by: Dan Tappin 104481 by: Jason Wong saving temporary image to database 104482 by: andy Re: PHP Oracle 8 Functions Efficiency Problem 104483 by: Thies C. Arntzen Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- ---BeginMessage--- Maybe it's already discussed here, but PHP is generating errors of undefined constants. These constants are defined in my scripts. Als the superglobal $_ENV is empty. Use quotes when using associative arrays. $_ENV['something'] rather than $_ENV[something] The warnings have always been there, PHP 4.2 just defaults to a higher error reporting level, so now you notice them. The problem comes from PHP looking for a constant called something and when it's not found, it issues a warning. Then it assumes you meant to use a string and tries it that way. You can adjust the error reporting in PHP.ini or with the error_reporting() function. ---John Holmes... ---End Message--- ---BeginMessage--- You need to had a content header header('Content-Type: image/gif'); start--- ?php $theFile = ; $fcontents = file ('Logo.gif'); while (list ($line_num, $line) = each ($fcontents)) { $theFile .= $line.\n; } echo $theFile; ? -end- and I have an html file that does img src=image.php but it just prints out a red box with an X, as if image is broken. I know the image is getting read in because I can echo it and its a bunch of garble, just like the jpg is if I open it up in notepad. Any idead? Thanks, Brandon Rasmus Lerdorf [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... You wouldn't. You would write a script like fetch_image.php in which you would do the mysql_query() and simply echo out the image data. Then in your main HTML file you would use: img src=fetch_image.php You can pass information to this script either via GET-method args. eg. img src=fetch_image.php?id=123 Or cooler would be to do an Apache ForceType to the PHP mime type on a file named images in your doc_root and put the fetch image code into thise images file. Then use: img src=/images/123.jpg And in your images script you would pick the image name out of $PATH_INFO and do the appropriate mysql query. -Rasmus On Fri, 28 Jun 2002, Brandon wrote: I would like to store a jpg/gif image in a MySQL database (as a BLOB type I guess ;p), how would I output that into an img src= in php? Thanks in advance, brandon -- 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 _ Join the worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com ---End Message--- ---BeginMessage--- Forgive me, perhaps I'm missing something, this is what I have: ?php header('Content-Type: image/gif'); $theFile = ; $fcontents = file ('Logo.gif'); while (list ($line_num, $line) = each ($fcontents)) {
RE: [PHP] ASP style application-level variables
Make that file load the application variables from the database, and the prepend file saves any changes... errr...prepend loads...append save. Damn English language... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] saving temporary image to database
... sorry I thought it would be to much code. Here is the complete code : $inputImg = ImageCreateFromJPEG($picture_location); # old size $srcX = imagesx($inputImg); $srcY = imagesy($inputImg); # new size $ratio = ($srcY / $dstY); $dstX = ($srcX / $ratio); $outputImg = ImageCreateTrueColor($maxX, $dstY); imagefill($outputImg, 0, 0, ImageColorAllocate($outputImg, 0, 0,0)); imagecopyresampled($outputImg, $inputImg, (($maxX - $dstX) / 2),0,0,0, $dstX, $dstY, $srcX, $srcY); # # save image to db into blob // this does not work (outputImg is a the colorcorrected file) $data = addslashes($outputImg); // this one would work # $data = addslashes(fread(fopen($picture_location, r), filesize($picture_location))); $stmt = INSERT INTO test.picture_test (file_name, file_type, picture) VALUES ('$name', '$picture_location_type', '$data') ; execute_stmt($stmt, $link); # Rasmus Lerdorf [EMAIL PROTECTED] schrieb im Newsbeitrag [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... There is no imagejpeg() call in the code snippet you provided. And you don't say how it is failing. You haven't provided us with enough data to answer this question. -Rasmus On Sat, 29 Jun 2002, andy wrote: Hi there, I would like to save a jpg into a blob field of mysql. The function underneath works fine if I read the image from the temporary destination where php did put it after uploading. My problem is, that I would like to do some funky stuff to the image like changing colors or adding watermarks. So I have several functions ahead before I used to store them successfully to the file system. Now I would like to store it to a blob field, but this does not work. Like I said it works to store the temp file, but not the other one. I guess it has to do with something regarding the imagejpeg function. Here is what I tryed: # # save image to db into blob // this does not work (outputImg is a the colorcorrected file) $data = addslashes($outputImg); // this one would work # $data = addslashes(fread(fopen($picture_location, r), filesize($picture_location))); $stmt = INSERT INTO test.picture_test (file_name, file_type, picture) VALUES ('$name', '$picture_location_type', '$data') ; execute_stmt($stmt, $link); # Maybe some of you guy has a good idea on that. Thanx for any help, Andy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- -- http://www.globosapiens.net Global Travellers Network -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Populate Popup Menu from Database
I have some popup menus and want the items in the menu to be populated from a database. In this case I have a table that contains a listing of departments. I have a page that I can go in and add/delete departments, and want the changes to reflect in the menu the next time you go to the page. I searched for examples and found this: http://marc.theaimsgroup.com/?l=php-generalm=97628169623096w=2 What is here is beyond my understanding, and seems like it is a little much for what I need. Here is what my database table looks like: Departments department_id department_name I just want to list the department name in the popup. Thanks, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help: Constants
Thanks alot, I changed the reporting level. I found it myself later on. Just was a bit to quick when posting this question. Sacha Telgenhof John Holmes [EMAIL PROTECTED] wrote in message news:000d01c21f0c$de789bf0$b402a8c0@mango... Maybe it's already discussed here, but PHP is generating errors of undefined constants. These constants are defined in my scripts. Als the superglobal $_ENV is empty. Use quotes when using associative arrays. $_ENV['something'] rather than $_ENV[something] The warnings have always been there, PHP 4.2 just defaults to a higher error reporting level, so now you notice them. The problem comes from PHP looking for a constant called something and when it's not found, it issues a warning. Then it assumes you meant to use a string and tries it that way. You can adjust the error reporting in PHP.ini or with the error_reporting() function. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Populate Popup Menu from Database
On Saturday 29 June 2002 23:41, Mike Tuller wrote: I have some popup menus and want the items in the menu to be populated from a database. In this case I have a table that contains a listing of departments. I have a page that I can go in and add/delete departments, and want the changes to reflect in the menu the next time you go to the page. I searched for examples and found this: http://marc.theaimsgroup.com/?l=php-generalm=97628169623096w=2 What is here is beyond my understanding, and seems like it is a little much for what I need. Here is what my database table looks like: Departments department_id department_name I just want to list the department name in the popup. There are two things you need to know: 1) How to construct a select list in HTML 2) How to retrieve the info from the db What are you having problems with? -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The only rose without thorns is friendship. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Populate Popup Menu from Database
Hi Mike, Check out ADODB. It's a database abstraction layer for PHP that has functions to do this. (php.weblogs.com) Otherwise it's kinda easy to do this, here's some psuedo-code that shoudl get you going. ?PHP // Make your connection to your database // Select * from department ? SELECT name='departmentID' ?PHP //While !EOF ? ?PHP option value=PHP echo $rs-fields['departmentID']; ?PHP echo $rs-fields['departmentName']; ? ? ?PHP // loop ? /SELECT =C= * * Cal Evans * Journeyman Programmer * Techno-Mage * http://www.calevans.com * -Original Message- From: Mike Tuller [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 10:42 AM To: php mailing list Subject: [PHP] Populate Popup Menu from Database I have some popup menus and want the items in the menu to be populated from a database. In this case I have a table that contains a listing of departments. I have a page that I can go in and add/delete departments, and want the changes to reflect in the menu the next time you go to the page. I searched for examples and found this: http://marc.theaimsgroup.com/?l=php-generalm=97628169623096w=2 What is here is beyond my understanding, and seems like it is a little much for what I need. Here is what my database table looks like: Departments department_id department_name I just want to list the department name in the popup. Thanks, Mike -- 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 to change $ char in string
use single quotes: double quotes would confuse php with variable names. it thinks that $General is a variable and replace it by it's empty content. single quotes prevent php from evaluating the string: $test_string = '1.2$General/ms1.zip'; single quotes on regex too (same reason). the backslash in this case (\$) refers to perl regular expression syntax but does not take care of php ! $new_string = preg_replace('/\$/', %, $test_string); ub At 10:58 29.06.02 -0400, Beverly Steiner wrote: I've tried everything I can think of to change a dallar sign in a string to something else or to split the string on the $ but I can't the the information that comes after the $. Typical string contains: 1.2$General/ms1.zip when I try: $new_string = preg_replace(/\$/, %, $test_string); or (trying to avoid specifying the $): $new_string = preg_replace(/(\d\.\d{1,2})\D(\w.*$)/, \1%\2, $test_string); echo new_string is $new_string; prints new_string is 1.2 Has anyone solved this problem? Thanx, Bev -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- --- Ulrich Borchers Brandenberger Straße 18, 41065 Mönchengladbach fon +49-2161-175883 icq 1282868 --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] need to change $ char in string
On Saturday 29 June 2002 22:58, Beverly Steiner wrote: I've tried everything I can think of to change a dallar sign in a string to something else or to split the string on the $ but I can't the the information that comes after the $. Typical string contains: 1.2$General/ms1.zip when I try: $new_string = preg_replace(/\$/, %, $test_string); Try: $new_string = preg_replace(/\\$/, %, $test_string); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Pity the meek, for they shall inherit the earth. -- Don Marquis */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Populate Popup Menu from Database
Thanks. I thought the example I found was a little to complicated for something like this. From: Cal Evans [EMAIL PROTECTED] Date: Sat, 29 Jun 2002 11:03:16 -0500 To: Mike Tuller [EMAIL PROTECTED], php mailing list [EMAIL PROTECTED] Subject: RE: [PHP] Populate Popup Menu from Database Hi Mike, Check out ADODB. It's a database abstraction layer for PHP that has functions to do this. (php.weblogs.com) Otherwise it's kinda easy to do this, here's some psuedo-code that shoudl get you going. ?PHP // Make your connection to your database // Select * from department ? SELECT name='departmentID' ?PHP //While !EOF ? ?PHP option value=PHP echo $rs-fields['departmentID']; ?PHP echo $rs-fields['departmentName']; ? ? ?PHP // loop ? /SELECT =C= * * Cal Evans * Journeyman Programmer * Techno-Mage * http://www.calevans.com * -Original Message- From: Mike Tuller [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 10:42 AM To: php mailing list Subject: [PHP] Populate Popup Menu from Database I have some popup menus and want the items in the menu to be populated from a database. In this case I have a table that contains a listing of departments. I have a page that I can go in and add/delete departments, and want the changes to reflect in the menu the next time you go to the page. I searched for examples and found this: http://marc.theaimsgroup.com/?l=php-generalm=97628169623096w=2 What is here is beyond my understanding, and seems like it is a little much for what I need. Here is what my database table looks like: Departments department_id department_name I just want to list the department name in the popup. Thanks, Mike -- 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] Populate Popup Menu from Database
I only ask questions if I have tried to do something myself already. I am not looking for someone to do something for me. When I do ask a question though, I feel I deserve at least a little respect. If you want to be an ass, do it somewhere else. From: Jason Wong [EMAIL PROTECTED] Organization: Gremlins Associates Reply-To: [EMAIL PROTECTED] Date: Sat, 29 Jun 2002 23:54:22 +0800 To: [EMAIL PROTECTED] Subject: Re: [PHP] Populate Popup Menu from Database On Saturday 29 June 2002 23:41, Mike Tuller wrote: I have some popup menus and want the items in the menu to be populated from a database. In this case I have a table that contains a listing of departments. I have a page that I can go in and add/delete departments, and want the changes to reflect in the menu the next time you go to the page. I searched for examples and found this: http://marc.theaimsgroup.com/?l=php-generalm=97628169623096w=2 What is here is beyond my understanding, and seems like it is a little much for what I need. Here is what my database table looks like: Departments department_id department_name I just want to list the department name in the popup. There are two things you need to know: 1) How to construct a select list in HTML 2) How to retrieve the info from the db What are you having problems with? -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The only rose without thorns is friendship. */ -- 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] ASP style application-level variables
Lee, Please check the archives before posting questions like this. As John stated, this question has been asked and answered this week. (I think it was a thread just yesterday.) It would have been much quicker for you to get your answer by mining the archives than by posting it again here. Thanks for your cooperation, =C= p.s. I accomplish applicaiton level variables by storing them in a table called application in my application's database. This way I can change them on the fly and all my pages can see them. I have objects that read them in on the pages that need them. * * Cal Evans * Journeyman Programmer * Techno-Mage * http://www.calevans.com * -Original Message- From: Lee [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 10:11 AM To: [EMAIL PROTECTED] Subject: [PHP] ASP style application-level variables Hi, Apologies if this question has already been asked in the past, but I have only just registered for this list. Does PHP in anyway support ASP style application-level variables in a similair way to how standard sessions are used. Though of implementing this as either files or database records but the additional coding could be more error-prone or eat more system resources than using a feature built into PHP itself. I would be interested to hear other peoples views on this feature. Lee -- 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] Populate Popup Menu from Database
On Sunday 30 June 2002 00:31, Mike Tuller wrote: I only ask questions if I have tried to do something myself already. I am not looking for someone to do something for me. When I do ask a question though, I feel I deserve at least a little respect. If you want to be an ass, do it somewhere else. Attitude! What part of my post offended you? I was merely stating what you need to know to be able to solve your problem. And then I asked which part you were having trouble with. You have given no indication in your post as to what level of competence you have in PHP and HTML. The only hint was that the example you quoted was beyond your understanding. You have given no indication of what you have done and did or didn't work. So how is one supposed to respond to your post? a) give you a solution, which may or may not be beyond your understanding? b) or prod you along the right direction with a request for more information? -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The world is coming to an end--save your buffers! */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] need to change $ char in string
Jason, Thanx for your suggestion but I tried it and it didn't work. I'm not sure if it matters, but this running on NT. Bev -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 12:05 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] need to change $ char in string On Saturday 29 June 2002 22:58, Beverly Steiner wrote: I've tried everything I can think of to change a dallar sign in a string to something else or to split the string on the $ but I can't the the information that comes after the $. Typical string contains: 1.2$General/ms1.zip when I try: $new_string = preg_replace(/\$/, %, $test_string); Try: $new_string = preg_replace(/\\$/, %, $test_string); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Pity the meek, for they shall inherit the earth. -- Don Marquis */ -- 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 to change $ char in string
On Sunday 30 June 2002 01:24, Beverly Steiner wrote: Thanx for your suggestion but I tried it and it didn't work. I'm not sure if it matters, but this running on NT. Not sure whether NT has anything to do with it but it works for me :-) If you can't get the following code to work then you might want to check whether it is a known bug (http://bugs.php.net). ? $test_string = '1.2$General/ms1.zip'; $new_string = preg_replace(/\\$/, %, $test_string); echo new_string is $new_string; ? But as someone has pointed out, you should be using single-quotes to prevent unwanted/unexpected variable expansion: $new_string = preg_replace('/\$/', '%', $test_string); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* All great discoveries are made by mistake. -- Young */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session.use_trans_sid
On Saturday 29 June 2002 18:02, Dan Tappin wrote: I am setting up a login section of my site using sessions. I have the login working with and without cookies enabled. I do not want to restrict my users be requiring cookies. The problem is that I can't seem to get PHP to auto append the session id to the relative URLs on the page. I have the following PHP settings: php_value session.use_cookies 0 php_value session.use_trans_sid 1 I also had these setings in my php.ini file. Was your php compiled with '--enable-trans-sid' ? Yes. I checked that. Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Populate Popup Menu from Database
Mike Tuller wrote: I only ask questions if I have tried to do something myself already. I am not looking for someone to do something for me. When I do ask a question though, I feel I deserve at least a little respect. If you want to be an ass, do it somewhere else. It seems *you* are the one being an ass and needing to do it somewhere else. If you can't have enough respect for people trying to help you by answering the simplest of questions (that should have been given in your original question anyway), you don't deserve an answer. Here are Mr. Wong's questions again (very appropriate questions at that). Perhaps if you offer him a sincere apology, thank him for his time, and *answer* *his* *questions*, he might be willing to forgive your poor attitude and offer you some help. There are two things you need to know: 1) How to construct a select list in HTML 2) How to retrieve the info from the db What are you having problems with? If you don't know a damn thing, that's fine. An appropriate answer would be, I neither know how to construct a select list in HTML nor how to retrieve information from a database. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sessions [Help]
This is a follow-up to another thread - [PHP] session.use_trans_sid I am setting up a login section of my site using sessions. I have the login working with and without cookies enabled. I do not want to restrict my users be requiring cookies. Here is my /login/login.php file which takes the results of the user login form: ? session_start(); if ($username $password) { // Here is a MySQL query to verify that the username and password are valid $num_rows = mysql_num_rows($login_result); if ($num_rows 0 ) { $row = mysql_fetch_array($login_result); session_register(id); // I register the user id for later use $id = $row[id]; // I set the user id // Once the user is verified I redirect to the main user page $redirect = http://www.fakeserver.com/login/home/index.php?sid=.session_id(); header(Location: $redirect); }; }; ? The problem is that I can't seem to get PHP to auto append the session id to the relative URLs on the following pages. Here is a include that I have added to each subsequent page to verify that this is a valid user: ? // Now this is perhaps part of the issue. I can't get these pages to keep the session id unless I call session_name('sid') first. I changed PHPSESSID to SID in the config files. If I comment out this my session variable $id which I use to check for a valid session gets lost and my logout() function triggers. session_name('sid'); session_start(); if(!$id) { logout(); // My logout function that clears the session variables and destroys the session }; // The rest of the HTML... ? The problem is that the SID is not getting automatically added to the URL's. If I allow cookies all is fine. I can go from page to page in my 'secure' login section and the $id session variable is accessible and the verification works fine. If I disable cookies the auto addition of the SID does not happen at all. The first page is fine because I hard coded the SID into the header() call. If I manual add the SID to local links it works as well and I am not logged out. This is driving me crazy! I have the following PHP settings in my Apache VH: php_value session.use_cookies 0 // This seems to have no effect on the trans_sid issue as I have tried it both ways php_value session.use_trans_sid 1 I also had these setings in my php.ini file. Am I missing something basic about sessions here? I have looked all over the web for a simular problem and I can't find one. Help!! :^) Thanks, Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Populate Popup Menu from Database
To let everyone know, I did apologize to Mr. Wong. I misunderstood what he was trying to ask me. I took it as he was saying It's easy, what is your problem rather than What is your problem . From: Chris Shiflett [EMAIL PROTECTED] Date: Sat, 29 Jun 2002 13:50:14 -0500 To: Mike Tuller [EMAIL PROTECTED] Cc: php mailing list [EMAIL PROTECTED], Jason Wong [EMAIL PROTECTED] Subject: Re: [PHP] Populate Popup Menu from Database Mike Tuller wrote: I only ask questions if I have tried to do something myself already. I am not looking for someone to do something for me. When I do ask a question though, I feel I deserve at least a little respect. If you want to be an ass, do it somewhere else. It seems *you* are the one being an ass and needing to do it somewhere else. If you can't have enough respect for people trying to help you by answering the simplest of questions (that should have been given in your original question anyway), you don't deserve an answer. Here are Mr. Wong's questions again (very appropriate questions at that). Perhaps if you offer him a sincere apology, thank him for his time, and *answer* *his* *questions*, he might be willing to forgive your poor attitude and offer you some help. There are two things you need to know: 1) How to construct a select list in HTML 2) How to retrieve the info from the db What are you having problems with? If you don't know a damn thing, that's fine. An appropriate answer would be, I neither know how to construct a select list in HTML nor how to retrieve information from a database. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Limiting number of decimal places reported
How do I limit the number of decimal places returned in this query? ?php $result2 = mysql_query(SELECT sum(purchase_price) as total FROM assets where order_number='$order_number'); while(list($order_total) = mysql_fetch_row($result2)) { print ($order_total); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] change variable in file
Hi, I want to write function which change variable in ie. config.php file ... Here is code: ? include config.php; $file = fopen(config.php, w+); $content = fread($file, filesize(config.php)); $content = str_replace(\$option['test'] = \ . $option['test'] . \;, \$option['test'] = \po tescie\;, $content); fwrite($file, $content); ? and config.php: ? $option['test'] = test; ? and it's doesn't work :( ... when I run script, it clear config.php and nothing else ... where is my fault? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Limiting number of decimal places reported
round($order_total), floor(), ceil() are some options. How do I limit the number of decimal places returned in this query? ?php $result2 = mysql_query(SELECT sum(purchase_price) as total FROM assets where order_number='$order_number'); while(list($order_total) = mysql_fetch_row($result2)) { print ($order_total); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -Pushkar S. Pradhan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Javascript to PHP?
Hello, Folks, My apologies if this has been asked a thousand times. I've just joined the list. I can't find any information on passing JavaScript variables to PHP on the same page (i.e. not through the POST information of a submitted form). Is this because it's not possible? To take the load off the server, I'm trying to do a bunch of string manipulations and loops in JavaScript and then hand that info off to PHP once it's done. Any insight is appreciated! Thanks, Jed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Limiting number of decimal places reported
How do I limit the number of decimal places returned in this query? ?php $result2 = mysql_query(SELECT sum(purchase_price) as total FROM assets where order_number='$order_number'); while(list($order_total) = mysql_fetch_row($result2)) { print ($order_total); If you were using the correct column type in MySQL, DECIMAL, you shouldn't have to worry about the decimal places. Otherwise, you can use number_format() on $order_total. Also, the while() loop isn't needed, since only one row is returned from a query like that without a GROUP BY clause. Also, you don't need the quotes around $order_total when printing it out. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Javascript to PHP?
Not possible. You must refresh the page to send something back to PHP. Only workaround is using a hidden frame or layer and refreshing that... ---John Holmes... -Original Message- From: Jed Verity [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 3:14 PM To: [EMAIL PROTECTED] Subject: [PHP] Javascript to PHP? Hello, Folks, My apologies if this has been asked a thousand times. I've just joined the list. I can't find any information on passing JavaScript variables to PHP on the same page (i.e. not through the POST information of a submitted form). Is this because it's not possible? To take the load off the server, I'm trying to do a bunch of string manipulations and loops in JavaScript and then hand that info off to PHP once it's done. Any insight is appreciated! Thanks, Jed -- 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] Javascript to PHP?
I've done this stuff recently. I need to pass whole arrays betn. php and Javascript (2-way), here is some code: // PHP var. to JS function arrFromStr (str2convert) { // make an array from string arr = new Array(); var posOfQt1 = str2convert.indexOf('\'); var posOfQt2 = str2convert.indexOf('\', posOfQt1+1); i = 0; while(posOfQt1 != -1) { arr[i] = str2convert.substring(posOfQt1+1, posOfQt2); i++; posOfQt1 = posOfQt2; posOfQt1 = str2convert.indexOf('\', posOfQt1+1); posOfQt2 = str2convert.indexOf('\', posOfQt1+1); } return arr; } Call this function like this: layerDesStr = '?=serialize($layerDes[0])?'; layerDes[0] = arrFromStr(layerDesStr); In case you have a variable don't serialize, just do myJSvar = ?=$myPHPvar?; JS variables can be sent to PHP by including them in html forms, nothing special about it. Hello, Folks, My apologies if this has been asked a thousand times. I've just joined the list. I can't find any information on passing JavaScript variables to PHP on the same page (i.e. not through the POST information of a submitted form). Is this because it's not possible? To take the load off the server, I'm trying to do a bunch of string manipulations and loops in JavaScript and then hand that info off to PHP once it's done. Any insight is appreciated! Thanks, Jed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -Pushkar S. Pradhan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Javascript to PHP?
Jed Verity wrote: I can't find any information on passing JavaScript variables to PHP on the same page (i.e. not through the POST information of a submitted form). Is this because it's not possible? Basically, this is not possible. A common area of confusion to those new to Web programming is the distinction between client-side and server-side code. PHP is an example of a server-side scripting language, while JavaScript is client-side. To PHP, anything that is not PHP is simply output. It doesn't matter if the output is HTML, JavaScript, XML, an image, etc. - it's all not PHP. When a user requests a PHP script, the PHP part of the script is executed prior to the output being sent to the client. Remember, the output may contain JavaScript. Once the output reaches the browser, the browser will attempt to render the HTML, execute the JavaScript, and whatever else is appropriate. So, to get back to your question, you are wanting to know how to have the browser (which is executing the JavaScript) be able to send a JavaScript variable to PHP (which could be thousands of miles away on whatever Web server the page was obtained from) on the same page, which means you want to be able to do this without communicating back to the Web server. So, your question can be summarized into: How can my browser send data back to the Web server without any further communication with the Web server? Hopefully that explains how it is impossible. The terms server-side and client-side are ignored by most people, understandably, because this industry is littered with useless terms that do little to describe what is really happening (in the case of Web services, the term is actually misleading in my opinion). However, these terms are very descriptive, and once you can begin to understand which code is executed on the server-side (by the Web server prior to sending the response to the Web client) and which code is executed on the client-side (by the Web client after receiving the response from the Web server), all of these types of questions will make more sense to you. Hope that gives a good description of the difference and can help you solve whatever problem you're currently working on. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Javascript to PHP?
My apologies if this has been asked a thousand times. I've just joined the list. I has, but you get that... I can't find any information on passing JavaScript variables to PHP on the same page (i.e. not through the POST information of a submitted form). Is this because it's not possible? Short answer is no. PHP is server-side, Javascript is client-side. You can get variables from php to javascript when your php generates the page to be sent to the browser but you can only get variables back from php when you use browser to server communications (that's usually a form - be it get or post method, or a cookie). To take the load off the server, I'm trying to do a bunch of string manipulations and loops in JavaScript and then hand that info off to PHP once it's done. You'll need to create all the javascript from you php page as it generates and then wait for it all to be done client-side and submitted back to the server. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] need to change $ char in string
works for me on win2k - Original Message - From: Jason Wong [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Saturday, June 29, 2002 6:43 PM Subject: Re: [PHP] need to change $ char in string On Sunday 30 June 2002 01:24, Beverly Steiner wrote: Thanx for your suggestion but I tried it and it didn't work. I'm not sure if it matters, but this running on NT. Not sure whether NT has anything to do with it but it works for me :-) If you can't get the following code to work then you might want to check whether it is a known bug (http://bugs.php.net). ? $test_string = '1.2$General/ms1.zip'; $new_string = preg_replace(/\\$/, %, $test_string); echo new_string is $new_string; ? But as someone has pointed out, you should be using single-quotes to prevent unwanted/unexpected variable expansion: $new_string = preg_replace('/\$/', '%', $test_string); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* All great discoveries are made by mistake. -- Young */ -- 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] Javascript to PHP?
Or setting a cookie in JavaScript. It will be transmitted on the next page request. -Original Message- From: John Holmes [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 3:30 PM To: 'Jed Verity'; [EMAIL PROTECTED] Subject: RE: [PHP] Javascript to PHP? Not possible. You must refresh the page to send something back to PHP. Only workaround is using a hidden frame or layer and refreshing that... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Javascript to PHP?
Hello, Chris, Many thanks for the thorough description. It does make sense, of course...I was just hoping that there was some kind of funky loophole that small brains like mine couldn't comprehend. Thanks again! Jed I liked it when Chris Shiflett wrote this to me: Jed Verity wrote: I can't find any information on passing JavaScript variables to PHP on the same page (i.e. not through the POST information of a submitted form). Is this because it's not possible? Basically, this is not possible. A common area of confusion to those new to Web programming is the distinction between client-side and server-side code. PHP is an example of a server-side scripting language, while JavaScript is client-side. To PHP, anything that is not PHP is simply output. It doesn't matter if the output is HTML, JavaScript, XML, an image, etc. - it's all not PHP. When a user requests a PHP script, the PHP part of the script is executed prior to the output being sent to the client. Remember, the output may contain JavaScript. Once the output reaches the browser, the browser will attempt to render the HTML, execute the JavaScript, and whatever else is appropriate. So, to get back to your question, you are wanting to know how to have the browser (which is executing the JavaScript) be able to send a JavaScript variable to PHP (which could be thousands of miles away on whatever Web server the page was obtained from) on the same page, which means you want to be able to do this without communicating back to the Web server. So, your question can be summarized into: How can my browser send data back to the Web server without any further communication with the Web server? Hopefully that explains how it is impossible. The terms server-side and client-side are ignored by most people, understandably, because this industry is littered with useless terms that do little to describe what is really happening (in the case of Web services, the term is actually misleading in my opinion). However, these terms are very descriptive, and once you can begin to understand which code is executed on the server-side (by the Web server prior to sending the response to the Web client) and which code is executed on the client-side (by the Web client after receiving the response from the Web server), all of these types of questions will make more sense to you. Hope that gives a good description of the difference and can help you solve whatever problem you're currently working on. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating RTF on the fly
check this out: http://www.phpbuilder.com/columns/nair20020523.php3 Mirza -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Generating RTF on the fly
Search before you post. I don't know the answer, but this turned up on google when searching for generate rtf with PHP http://paggard.dlight.ru/rtf_gen/ Yeah, it costs, but it looks good. Help a programmer out! I'm sure there are others. Look on hotscripts.com and sourceforge.net ---John Holmes... -Original Message- From: Mario Bittencourt [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 3:37 PM To: [EMAIL PROTECTED] Subject: [PHP] Generating RTF on the fly Hi, I need to generate RTF files from within PHP scripts based on user input. Do you know of any package to do the trick ? Perhaps external one, for ex. generate a XML version and feed it into an external converter. The rtf would have header/footer, ocasional images and tables. Thanks. -- 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] Generating RTF on the fly
On Saturday 29 June 2002 09:37 pm, Mario Bittencourt wrote: I need to generate RTF files from within PHP scripts based on user input. Do you know of any package to do the trick ? Besides the package already named, you can also just read an rtf template file and use str_replace.. It's plain ascii after all. Not as good as generating, but quite usable for a quick hack. Gerhard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Generating RTF on the fly
Hello, On 06/29/2002 04:37 PM, Mario Bittencourt wrote: Hi, I need to generate RTF files from within PHP scripts based on user input. Do you know of any package to do the trick ? If you are running under Windows you may use COM objects to convert HTML into RTF. You may want to try this PHP class for that: http://www.phpclasses.org/browse.html/package/388.html -- Regards, Manuel Lemos -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Newbie Q: Fetching vs. Looping
Hello Again, Folks, I've been testing this for a while and keep coming up with mixed results. In general, is it faster and more efficient to query a MySQL database once with a large SQL select statement and then loop through the huge resulting table? Or does it make better sense to perform a number of smaller queries with smaller resulting tables? This is the kind of stuff they just don't seem to talk about in the manuals. Any insight is appreciated. Sorry for the ignorant question! Jed -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic List Boxes
I am *very* new to PHP, so this may seem like a stupid question... I am trying to generate dynamic drop-down lists for use in an HTML form, but I have done something wrong with my code. Instead of getting one list box with three options, I am getting three list boxes with one option. I have included this piece of my code... Can anyone help??? ? $link = mysql_connect(localhost, user, pass); mysql_select_db(my_db, $link); $result = mysql_query(SELECT SKU, Description, Retail FROM linecard WHERE sku=61 or sku=239 or sku=318, $link); $num_rows = mysql_num_rows($result); if($num_rows) { while($row = mysql_fetch_row($result)) { print(select name=\test\); print(option value=\$row[0]-$row[1]-$row[2]\$row[1] - \$$row[2]/optionbr); print(/select); } } else { print(option value=\\No Parts Created Yet/option); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic List Boxes
On Saturday, June 29, 2002 at 10:03:16 PM, Chase wrote: I am *very* new to PHP, so this may seem like a stupid question... I am trying to generate dynamic drop-down lists for use in an HTML form, but I have done something wrong with my code. Instead of getting one list box with three options, I am getting three list boxes with one option. I have included this piece of my code... Can anyone help??? Yes, you have the select open and close tags inside the loop. Move them either side as follows... ? $link = mysql_connect(localhost, user, pass); mysql_select_db(my_db, $link); $result = mysql_query(SELECT SKU, Description, Retail FROM linecard WHERE sku=61 or sku=239 or sku=318, $link); $num_rows = mysql_num_rows($result); if($num_rows) { print(select name=\test\); while($row = mysql_fetch_row($result)) { print(option value=\$row[0]-$row[1]-$row[2]\$row[1] - \$$row[2]/optionbr); } print(/select); } else { print(option value=\\No Parts Created Yet/option); } ? -- Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dynamic List Boxes
Thank you Stuart!! I feel like an idiot... I had tried moving one or the other outside the loop, but not both... Thank you again!! Chase Stuart Dallas wrote: On Saturday, June 29, 2002 at 10:03:16 PM, Chase wrote: I am *very* new to PHP, so this may seem like a stupid question... I am trying to generate dynamic drop-down lists for use in an HTML form, but I have done something wrong with my code. Instead of getting one list box with three options, I am getting three list boxes with one option. I have included this piece of my code... Can anyone help??? Yes, you have the select open and close tags inside the loop. Move them either side as follows... ? $link = mysql_connect(localhost, user, pass); mysql_select_db(my_db, $link); $result = mysql_query(SELECT SKU, Description, Retail FROM linecard WHERE sku=61 or sku=239 or sku=318, $link); $num_rows = mysql_num_rows($result); if($num_rows) { print(select name=\test\); while($row = mysql_fetch_row($result)) { print(option value=\$row[0]-$row[1]-$row[2]\$row[1] - \$$row[2]/optionbr); } print(/select); } else { print(option value=\\No Parts Created Yet/option); } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Newbie Q: Fetching vs. Looping
Depends what you're after. Your query should always return exactly the data you are after. Your tables should be arranged so that is possible. ---John Holmes... -Original Message- From: Jed Verity [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 5:10 PM To: [EMAIL PROTECTED] Subject: [PHP] Newbie Q: Fetching vs. Looping Hello Again, Folks, I've been testing this for a while and keep coming up with mixed results. In general, is it faster and more efficient to query a MySQL database once with a large SQL select statement and then loop through the huge resulting table? Or does it make better sense to perform a number of smaller queries with smaller resulting tables? This is the kind of stuff they just don't seem to talk about in the manuals. Any insight is appreciated. Sorry for the ignorant question! Jed -- 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 to change $ char in string
try double \\ to escape the special characters used by php for variables and what not. I think I read it here on a previous post. Hope this helps Hugh - Original Message - From: Beverly Steiner [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] Sent: Saturday, June 29, 2002 7:58 AM Subject: [PHP] need to change $ char in string I've tried everything I can think of to change a dallar sign in a string to something else or to split the string on the $ but I can't the the information that comes after the $. Typical string contains: 1.2$General/ms1.zip when I try: $new_string = preg_replace(/\$/, %, $test_string); or (trying to avoid specifying the $): $new_string = preg_replace(/(\d\.\d{1,2})\D(\w.*$)/, \1%\2, $test_string); echo new_string is $new_string; prints new_string is 1.2 Has anyone solved this problem? Thanx, Bev -- 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 Q: Fetching vs. Looping
Jed Verity wrote: In general, is it faster and more efficient to query a MySQL database once with a large SQL select statement and then loop through the huge resulting table? Or does it make better sense to perform a number of smaller queries with smaller resulting tables? This is a hard question to give an answer to. It depends largely on the amount of data you're talking about, the amount of memory on the machine your code is executing from, whether you are using persistent database connections, etc. In general, if you use persistent database connections, each additional query after the first will be quite fast. I'm sure your question stems from seeing someone say that queries are the most common bottleneck for Web applications, and this is true to a point. If the one query you speak of is huge, try some tests and see how much memory PHP has to use to maintain that in memory. Consider that multiple requests during the time that PHP is holding that data in memory will result in a pretty decent chunk of memory being used. If you have endless amounts of memory (some huge unix machine with 20+ GB of RAM), I would say go for the one query method. It is definitely going to be faster, so long as you have enough memory to handle it. In most cases, if your approach ends up running your machine out of memory under heavy load, it would be a poor approach, because it would end up slowing *everything* down. So, maybe that gives you some things to think about. Maybe someone else can come up with a more conclusive answer. In summation: 1) using memory to keep *all* database results can improve performance if you have plenty of memory to handle this approach 2) if not, try very specific queries that retrieve just the data you need, and carefully free all results as you finish - also try to use persistent connections if you forsee your site being under heavy load. I personally take approach #2, because most of my environments have had sane (less than 5 GB) amounts of memory. I *think* this method would be more appropriate for most people, even though it seems like you end up hitting the database a lot. I've generally gotten extraordinary performance (page execution takes less than a tentth of a second searching through a database with 50,000 records) from a multi-homed Web host with PHP/MySQL, even with 30,000+ transactions/day. It's also more difficult to get specific data sets with one query; that approach usually requires that you have to take a greatest common denominator style approach and end up with way more data than you really need. I'd be curious to see some other opinions. There's mine. :) Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Usiing FOREACH to loop through Array
Hi All, I've stumped myself here. In a nutshell, I have a function that returns my array based on a SQL query and here's the code: -begin code--- function getCourses($UID) { global $link; $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); return mysql_fetch_array( $result ); } end code I call this from a PHP page with the following code: begin code-- $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } end code--- Now, when I test the SQL from my function directly on the database, it returns just want I want it to return but it isn't working that way on my PHP page. For results where there is a single entry, I am getting the same entry TWICE and for records with more than a single entry I am getting ONLY the FIRST entry TWICE. Now I know my SQL code is correct (I am testing it against a MySQL database using MySQL-Front) so I suspect I'm doing something stupid in my foreach loop. I'm hoping someone will spot my dumb mistake. Thanks very much for any help at all on this. Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Newbie Q: Fetching vs. Looping
On Sat, 29 Jun 2002, Chris Shiflett wrote: 2) if not, try very specific queries that retrieve just the data you need, and carefully free all results as you finish - also try to use persistent connections if you forsee your site being under heavy load. Something I haven't picked up in my reading of the manual: Is a free required for every query? Or can I go connect, query, query, query, free, close? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] JavaScript to PHP?
You might be able to pass them as a cookie. Bruce Karstedt President Technology Consulting Associates, Ltd. Tel: 847-735-9488 Fax: 847-735-9474 -Original Message- From: Jed Verity [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 2:59 PM To: Chris Shiflett Cc: [EMAIL PROTECTED] Subject: Re: [PHP] Javascript to PHP? Importance: Low Hello, Chris, Many thanks for the thorough description. It does make sense, of course...I was just hoping that there was some kind of funky loophole that small brains like mine couldn't comprehend. Thanks again! Jed I liked it when Chris Shiflett wrote this to me: Jed Verity wrote: I can't find any information on passing JavaScript variables to PHP on the same page (i.e. not through the POST information of a submitted form). Is this because it's not possible? Basically, this is not possible. A common area of confusion to those new to Web programming is the distinction between client-side and server-side code. PHP is an example of a server-side scripting language, while JavaScript is client-side. To PHP, anything that is not PHP is simply output. It doesn't matter if the output is HTML, JavaScript, XML, an image, etc. - it's all not PHP. When a user requests a PHP script, the PHP part of the script is executed prior to the output being sent to the client. Remember, the output may contain JavaScript. Once the output reaches the browser, the browser will attempt to render the HTML, execute the JavaScript, and whatever else is appropriate. So, to get back to your question, you are wanting to know how to have the browser (which is executing the JavaScript) be able to send a JavaScript variable to PHP (which could be thousands of miles away on whatever Web server the page was obtained from) on the same page, which means you want to be able to do this without communicating back to the Web server. So, your question can be summarized into: How can my browser send data back to the Web server without any further communication with the Web server? Hopefully that explains how it is impossible. The terms server-side and client-side are ignored by most people, understandably, because this industry is littered with useless terms that do little to describe what is really happening (in the case of Web services, the term is actually misleading in my opinion). However, these terms are very descriptive, and once you can begin to understand which code is executed on the server-side (by the Web server prior to sending the response to the Web client) and which code is executed on the client-side (by the Web client after receiving the response from the Web server), all of these types of questions will make more sense to you. Hope that gives a good description of the difference and can help you solve whatever problem you're currently working on. Chris -- 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] Usiing FOREACH to loop through Array
At 3:27 PM -0700 6/29/02, Brad Melendy wrote: Hi All, I've stumped myself here. In a nutshell, I have a function that returns my array based on a SQL query and here's the code: -begin code--- function getCourses($UID) { global $link; $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); return mysql_fetch_array( $result ); } end code I call this from a PHP page with the following code: begin code-- $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } end code--- Now, when I test the SQL from my function directly on the database, it returns just want I want it to return but it isn't working that way on my PHP page. For results where there is a single entry, I am getting the same entry TWICE and for records with more than a single entry I am getting ONLY the FIRST entry TWICE. Now I know my SQL code is correct (I am testing it against a MySQL database using MySQL-Front) so I suspect I'm doing something stupid in my foreach loop. I think your problem lies in a misunderstanding of the mysql_fetch_array() function. It doesn't return the entire result set in an array - just one record at a time. You can fix this in one of two ways: (1) Loop though the entire result set in your function: function getCourses($UID) { global $link; $ResultSet = array(); $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); while ($Row = mysql_fetch_array( $result )) { $ResultSet[] = $Row['C.CourseName']; } return $ResultSet; } ... $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID) global $link; static $result = false; if (!$result) { $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); } { return mysql_fetch_array( $result ); } ... while ($Row = getCourses($session[id]) as $value) { print br, $Row['C.CourseName']; } (standard caveats about off-top-of-head, untested code apply) The reason you are getting the first record TWICE is becaouse of the default behaviour of the mysql_fetch_array() function. It returns both an associative array - ie, elements of the form field-name = value - and a numerically indexed array (0, 1, 2, etc.). You can alter this behaviour by the second parameter of the function: see http://www.php.net/manual/en/function.mysql-fetch-array.php -steve I'm hoping someone will spot my dumb mistake. Thanks very much for any help at all on this. Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Usiing FOREACH to loop through Array
Oops! It's hot, it's Saturday, brain not functioning at 100%, made cut'n'paste error: SNIP or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID) global $link; static $result = false; if (!$result) { $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); } { return mysql_fetch_array( $result ); } ... while ($Row = getCourses($session[id]) as $value) { print br, $Row['C.CourseName']; } SNIP This last block of code should be while ($Row = getCourses($session[id])) { print br, $Row['C.CourseName']; } -steve -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Newbie Q: Fetching vs. Looping
Duncan Hill wrote: Is a free required for every query? Or can I go connect, query, query, query, free, close? You never have to free your results if you don't want to. As I understand it, doing so simply frees up the memory that is being taken up by the result set ($result in most examples). Whenever your script finishes executing, all memory associated with it will be freed anyway. Explicitly doing so simply allows this memory to be freed up sooner. It is definitely beneficial to always free your result set when you're finished with it, but you'll be hard-pressed to notice a difference, to be honest. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Javascript to PHP?
On Sat, 29 Jun 2002 16:58:50 -0300, Jed Verity wrote: Hello, Chris, Many thanks for the thorough description. It does make sense, of course...I was just hoping that there was some kind of funky loophole that small brains like mine couldn't comprehend. well if it's one-way only communication, you could load an image in javascript that is really a php page. that way you can send information to a php script without the browser reloading. there's probably other ways that a javascript guru could come up with (maybe loading content into an invisible layer??) this isn't the best place to be asking a javascript question tho. hth. - Mark -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Newbie Q: Fetching vs. Looping
On Sat, 29 Jun 2002, Chris Shiflett wrote: Duncan Hill wrote: Is a free required for every query? Or can I go connect, query, query, query, free, close? You never have to free your results if you don't want to. As I understand it, doing so simply frees up the memory that is being taken *tip* Ta. Good programming practice then. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting IP from behind proxies
I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... You can only get it if the proxy provides you with this data. Most don't, so this is not a reliable approach. -Rasmus On Sat, 29 Jun 2002, JJ Harrison wrote: I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.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
php-general Digest 30 Jun 2002 01:34:00 -0000 Issue 1435
php-general Digest 30 Jun 2002 01:34:00 - Issue 1435 Topics (messages 104484 through 104543): Getting IP from behind proxies 104484 by: JJ Harrison 104486 by: Rasmus Lerdorf 104543 by: JJ Harrison Re: saving temporary image to database 104485 by: Rasmus Lerdorf 104492 by: andy Re: Keeping Secrets in PHP Files 104487 by: Jonathan Rosenberg need to change $ char in string 104488 by: Beverly Steiner 104497 by: Uli B 104498 by: Jason Wong 104504 by: Beverly Steiner 104505 by: Jason Wong 104521 by: Paul Roberts 104533 by: hugh danaher ASP style application-level variables 104489 by: Lee 104490 by: John Holmes 104491 by: John Holmes 104502 by: Cal Evans Populate Popup Menu from Database 104493 by: Mike Tuller 104495 by: Jason Wong 104496 by: Cal Evans 104500 by: Mike Tuller 104501 by: Mike Tuller 104503 by: Jason Wong 104507 by: Chris Shiflett 104509 by: Mike Tuller Re: Constants 104494 by: S.P. Telgenhof Oude Koehorst Re: Gradients in PHP GD 104499 by: Bogdan Stancescu Re: session.use_trans_sid 104506 by: Dan Tappin Sessions [Help] 104508 by: Dan Tappin change variable in file 104510 by: Nookie Limiting number of decimal places reported 104511 by: John Wulff 104512 by: Pushkar Pradhan 104514 by: John Holmes Javascript to PHP? 104513 by: Jed Verity 104515 by: John Holmes 104516 by: Pushkar Pradhan 104517 by: Jed Verity 104519 by: Chris Shiflett 104520 by: David Freeman 104522 by: Mark Charette 104523 by: Jed Verity 104537 by: Bruce Karstedt 104541 by: Mark Generating RTF on the fly 104518 by: Mario Bittencourt 104524 by: Mirza Muharemagic 104525 by: John Holmes 104526 by: Gerhard Hoogterp 104527 by: Manuel Lemos Newbie Q: Fetching vs. Looping 104528 by: Jed Verity 104532 by: John Holmes 104534 by: Chris Shiflett 104536 by: Duncan Hill 104540 by: Chris Shiflett 104542 by: Duncan Hill Dynamic List Boxes 104529 by: Chase 104530 by: Stuart Dallas 104531 by: Chase Usiing FOREACH to loop through Array 104535 by: Brad Melendy 104538 by: Steve Edberg 104539 by: Steve Edberg Administrivia: To subscribe to the digest, e-mail: [EMAIL PROTECTED] To unsubscribe from the digest, e-mail: [EMAIL PROTECTED] To post to the list, e-mail: [EMAIL PROTECTED] -- ---BeginMessage--- I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.com ---End Message--- ---BeginMessage--- You can only get it if the proxy provides you with this data. Most don't, so this is not a reliable approach. -Rasmus On Sat, 29 Jun 2002, JJ Harrison wrote: I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- ---BeginMessage--- I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... You can only get it if the proxy provides you with this data. Most don't, so this is not a reliable approach. -Rasmus On Sat, 29 Jun 2002, JJ Harrison wrote: I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- ---BeginMessage--- There is no imagejpeg() call in the code snippet you provided. And you don't say how it is failing. You haven't provided us with enough data to answer this question. -Rasmus On Sat, 29 Jun 2002, andy wrote: Hi there, I would like to save a jpg into a blob field of mysql. The function underneath works fine if I read the image from the temporary destination where php did put it after uploading. My problem is, that I would like to do some funky stuff to the
Re: [PHP] Usiing FOREACH to loop through Array
Steve, Thanks very much. This make total sense to me. Now, I was pretty sure that I was getting an array back from mysql_fetch_array because when I do a 'print $myCourses' without specifying any value, I just get 'array' which I believe I am supposed to, IF it is truly an array. Anyway, I'm going to revisit the mysql_fetch_array function right now. Thanks for your help, it is greatly appreciated. ...Brad Steve Edberg [EMAIL PROTECTED] wrote in message news:p05100300b943f2a7feef@[168.150.239.37]... At 3:27 PM -0700 6/29/02, Brad Melendy wrote: Hi All, I've stumped myself here. In a nutshell, I have a function that returns my array based on a SQL query and here's the code: -begin code--- function getCourses($UID) { global $link; $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); return mysql_fetch_array( $result ); } end code I call this from a PHP page with the following code: begin code-- $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } end code--- Now, when I test the SQL from my function directly on the database, it returns just want I want it to return but it isn't working that way on my PHP page. For results where there is a single entry, I am getting the same entry TWICE and for records with more than a single entry I am getting ONLY the FIRST entry TWICE. Now I know my SQL code is correct (I am testing it against a MySQL database using MySQL-Front) so I suspect I'm doing something stupid in my foreach loop. I think your problem lies in a misunderstanding of the mysql_fetch_array() function. It doesn't return the entire result set in an array - just one record at a time. You can fix this in one of two ways: (1) Loop though the entire result set in your function: function getCourses($UID) { global $link; $ResultSet = array(); $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); while ($Row = mysql_fetch_array( $result )) { $ResultSet[] = $Row['C.CourseName']; } return $ResultSet; } ... $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID) global $link; static $result = false; if (!$result) { $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); } { return mysql_fetch_array( $result ); } ... while ($Row = getCourses($session[id]) as $value) { print br, $Row['C.CourseName']; } (standard caveats about off-top-of-head, untested code apply) The reason you are getting the first record TWICE is becaouse of the default behaviour of the mysql_fetch_array() function. It returns both an associative array - ie, elements of the form field-name = value - and a numerically indexed array (0, 1, 2, etc.). You can alter this behaviour by the second parameter of the function: see http://www.php.net/manual/en/function.mysql-fetch-array.php -steve I'm hoping someone will spot my dumb mistake. Thanks very much for any help at all on this. Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mcrypt
Has anyone got a working mcrypt.dll for php 4.2.1 and Windows 2000 Server? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting IP from behind proxies
what esle could i use? Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... You can only get it if the proxy provides you with this data. Most don't, so this is not a reliable approach. -Rasmus On Sat, 29 Jun 2002, JJ Harrison wrote: I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.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: [PHP] Getting IP from behind proxies
You need to assign each person a unique identifier of some sort. ie. assign them a login and password and verify that information by sending a message to their email address. Then only people with multiple email addresses can spam your system with votes. Beyond that it comes down to verifying each voter manually. Get a phone number and call each one up. Even that is not quite foolproof. Personal certificates might be an option here, but that is rather cumbersome for everyone involved. Basically there is no good solution for this problem. Until everyone in the world has a unique and non-spoofable, easily verifiable id number, what you are trying to do is impossible. Basically live with the fact that your voting system will be inaccurate and spoofable. -Rasmus On Sun, 30 Jun 2002, JJ Harrison wrote: what esle could i use? Rasmus Lerdorf [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... You can only get it if the proxy provides you with this data. Most don't, so this is not a reliable approach. -Rasmus On Sat, 29 Jun 2002, JJ Harrison wrote: I want to check to see if people have voted yet for a poll. How can I get the ip of a user from both behind a proxy and the proxies ip? is this simple? will i have trouble with firewalls etc? -- JJ Harrison [EMAIL PROTECTED] www.tececo.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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Usiing FOREACH to loop through Array
At 7:35 PM -0700 6/29/02, Brad Melendy wrote: Steve, Thanks very much. You're welcome! This make total sense to me. Now, I was pretty sure that I was getting an array back from mysql_fetch_array because when I do a 'print $myCourses' without specifying any value, I just get 'array' which I believe I am supposed to, IF it is truly an array. Anyway, I'm going to revisit the mysql_fetch_array function right now. Thanks for your help, it is greatly appreciated. ...Brad Just to clarify a bit - mysql_fetch_array() DOES return an array - thus the name - but it is an array containing one record from the result set. For instance, if the result of the statement SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = 1 through the MySQL commandline was +-+ | C.CourseName| +-+ | Basketweaving | | Noodle twirling | | Poodle furling | | Puddle curling | +-+ then the first use of mysql_fetch_array($result) through PHP would retrieve the array 'C.CourseName' = 'Basketweaving', 0 = 'Basketweaving' the second call would retrieve 'C.CourseName' = ' Noodle twirling', 0 = ' Noodle twirling' and so on. If you had two columns in the result set: +-++ | C.CourseName| C.CourseNo | +-++ | Basketweaving | 12 | | Noodle twirling | 23 | | Poodle furling | 24 | | Puddle curling | 25 | +-++ you would get results like 'C.CourseName' = 'Basketweaving', 0 = 'Basketweaving', 'C.CourseNo' = 12, 1 = 12 and so on. The reason you get the doubled keys (associative numeric) is for historical compatibility; to turn off the feature, and retrieve only the associated indexes (the behavior you normally want), you can use mysql_fetch_array($result, MYSQL_ASSOC); Incidentally, I just learned something here myself; there's a relatively new (= version 4.0.3) function mysql_fetch_assoc() which does what you want...return ONLY the associated indexes. See: http://www.php.net/manual/en/function.mysql-fetch-assoc.php -steve Steve Edberg [EMAIL PROTECTED] wrote in message news:p05100300b943f2a7feef@[168.150.239.37]... At 3:27 PM -0700 6/29/02, Brad Melendy wrote: Hi All, I've stumped myself here. In a nutshell, I have a function that returns my array based on a SQL query and here's the code: -begin code--- function getCourses($UID) { global $link; $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); return mysql_fetch_array( $result ); } end code I call this from a PHP page with the following code: begin code-- $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } end code--- Now, when I test the SQL from my function directly on the database, it returns just want I want it to return but it isn't working that way on my PHP page. For results where there is a single entry, I am getting the same entry TWICE and for records with more than a single entry I am getting ONLY the FIRST entry TWICE. Now I know my SQL code is correct (I am testing it against a MySQL database using MySQL-Front) so I suspect I'm doing something stupid in my foreach loop. I think your problem lies in a misunderstanding of the mysql_fetch_array() function. It doesn't return the entire result set in an array - just one record at a time. You can fix this in one of two ways: (1) Loop though the entire result set in your function: function getCourses($UID) { global $link; $ResultSet = array(); $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); while ($Row = mysql_fetch_array( $result )) { $ResultSet[] = $Row['C.CourseName']; } return $ResultSet; } ... $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID) global $link; static $result = false; if (!$result) { $result = mysql_query( SELECT C.CourseName FROM tblcourses C,
RE: [PHP] Limiting number of decimal places reported
John, Try using the number_format function. Bev -Original Message- From: John Wulff [mailto:[EMAIL PROTECTED]] Sent: Saturday, June 29, 2002 3:10 PM To: [EMAIL PROTECTED] Subject: [PHP] Limiting number of decimal places reported How do I limit the number of decimal places returned in this query? ?php $result2 = mysql_query(SELECT sum(purchase_price) as total FROM assets where order_number='$order_number'); while(list($order_total) = mysql_fetch_row($result2)) { print ($order_total); } ? -- 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] Usiing FOREACH to loop through Array
Steve, Thanks a ton! I'm now running slick as a whistle using your option #1 (looping through the results in the function) and using the newer mysql_fetch_assoc() function. I have a much better understanding of this now and I really appreciate your help. Hopefully I'll get a chance to help someone else next time. :-) Steve Edberg [EMAIL PROTECTED] wrote in message news:p05100300b943f2a7feef@[168.150.239.37]... At 3:27 PM -0700 6/29/02, Brad Melendy wrote: Hi All, I've stumped myself here. In a nutshell, I have a function that returns my array based on a SQL query and here's the code: -begin code--- function getCourses($UID) { global $link; $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); return mysql_fetch_array( $result ); } end code I call this from a PHP page with the following code: begin code-- $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } end code--- Now, when I test the SQL from my function directly on the database, it returns just want I want it to return but it isn't working that way on my PHP page. For results where there is a single entry, I am getting the same entry TWICE and for records with more than a single entry I am getting ONLY the FIRST entry TWICE. Now I know my SQL code is correct (I am testing it against a MySQL database using MySQL-Front) so I suspect I'm doing something stupid in my foreach loop. I think your problem lies in a misunderstanding of the mysql_fetch_array() function. It doesn't return the entire result set in an array - just one record at a time. You can fix this in one of two ways: (1) Loop though the entire result set in your function: function getCourses($UID) { global $link; $ResultSet = array(); $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); while ($Row = mysql_fetch_array( $result )) { $ResultSet[] = $Row['C.CourseName']; } return $ResultSet; } ... $myCourses = getCourses($session[id]); foreach ($myCourses as $value) { print br$value; } or (2) set a flag in getCourses() so that the query is only executed once, otherwise returning a result line - something like: function getCourses($UID) global $link; static $result = false; if (!$result) { $result = mysql_query( SELECT C.CourseName FROM tblcourses C, tblusers U, tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID = $UID, $link ); if ( ! $result ) die ( getRow fatal error: .mysql_error() ); } { return mysql_fetch_array( $result ); } ... while ($Row = getCourses($session[id]) as $value) { print br, $Row['C.CourseName']; } (standard caveats about off-top-of-head, untested code apply) The reason you are getting the first record TWICE is becaouse of the default behaviour of the mysql_fetch_array() function. It returns both an associative array - ie, elements of the form field-name = value - and a numerically indexed array (0, 1, 2, etc.). You can alter this behaviour by the second parameter of the function: see http://www.php.net/manual/en/function.mysql-fetch-array.php -steve I'm hoping someone will spot my dumb mistake. Thanks very much for any help at all on this. Brad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php