|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general-digest-help_at_lists.php.net
Date: Fri Jul 19 2002 - 05:48:26 CDT
php-general Digest 19 Jul 2002 10:48:26 -0000 Issue 1473
Topics (messages 108344 through 108475):
Re: Arrays and Regs
108344 by: Analysis & Solutions
108409 by: Richard Lynch
Re: Loading a File into Variable - How??
108345 by: Analysis & Solutions
108346 by: Rasmus Lerdorf
108424 by: Monty
108425 by: Monty
Windows Sockets Problem Socket_Read
108347 by: David Buerer
108411 by: Richard Lynch
postnuke / geekware?
108348 by: jaxon
108351 by: jon roig
108356 by: John Holmes
108367 by: Miles Thompson
108369 by: Vail, Warren
108417 by: John Holmes
Re: ARRAY_PUSH with $key
108349 by: Pekka Saarinen
108354 by: Analysis & Solutions
Re: Refreshing session variables
108350 by: Kevin Stone
108357 by: John Holmes
108410 by: Richard Lynch
Re: Includes vs. Functions
108352 by: Michael Sims
utf8_decode missing?
108353 by: Les Barstow
Function Upload? Função Upload ?
108355 by: Skyhawk
Please Help with LOOP!!
108358 by: Wee Keat
108359 by: Asmodean
108360 by: Martin Towell
108361 by: Jerome Houston
Re: Please Help with LOOP!! - Questions Answered!!!
108362 by: Wee Keat
Searching...
108363 by: Georgie Casey
108364 by: John Holmes
108418 by: Jason Wong
108443 by: David Robley
108461 by: Jason Wong
Re: Cookies - good or bad???
108365 by: Justin French
108366 by: Justin French
108422 by: Evgeny Chuykov
108447 by: Philippe Saladin
Re: [PHP-DB] Fatal error: Call to undefined function: pg_connect() in .....
108368 by: Miles Thompson
108419 by: Rick Widmer
Re: PostgreSQL
108370 by: Richard Lynch
Re: Purpose of $$var ?????
108371 by: Richard Lynch
Re: file() and array values contain extra \n
108372 by: Richard Lynch
Re: php/mysql simple math
108373 by: Richard Lynch
Re: Classes vs. Functions
108374 by: Richard Lynch
Re: Problem with implode() function
108375 by: Richard Lynch
Re: Search Page question
108376 by: Richard Lynch
Re: exec() function question on Solaris
108377 by: Richard Lynch
Re: Fopen errors out when opening a URL
108378 by: Richard Lynch
Re: PHP Functions Essential Reference??
108379 by: Richard Lynch
Re: Good instruction for installing webserver using RPM and tar.gz files???
108380 by: Richard Lynch
Re: function for finding one character in a string?
108381 by: Richard Lynch
Re: GIF Manipulation
108382 by: Richard Lynch
Re: calling a cgi script from php
108383 by: Richard Lynch
Re: transparent clusters + sessions
108384 by: Richard Lynch
Re: problem with IMAP support
108385 by: Richard Lynch
Re: Bug in PHP?
108386 by: Richard Lynch
Re: PHP and Jigsaw
108387 by: Richard Lynch
Re: Problem on file_exists() function
108388 by: Richard Lynch
Re: remove header tags - include file
108389 by: Richard Lynch
Re: Forms problem?
108390 by: Richard Lynch
Re: php Similar to C in Pointer Memory Accessing or not?
108391 by: Richard Lynch
Re: Sessions Vars under 4.0.4pl1
108392 by: Richard Lynch
Re: Debugging LDAP_connect problems
108393 by: Richard Lynch
Re: imap connection problem
108394 by: Richard Lynch
Re: File reading help with Syntax
108395 by: Richard Lynch
Re: Queries - Sometimes I need to use apostrophe, other times i don't
108396 by: Richard Lynch
Re: Confused about the list() function
108397 by: Richard Lynch
Re: how many requests can php serve?
108398 by: Richard Lynch
Re: Segmentation fault with Sablotron xslt_process()
108399 by: Richard Lynch
Re: ldap_add() - null values in fields produce an "value #0 invalid per syntax" error on ldap server
108400 by: Richard Lynch
Re: Creating Dynamic Variables
108401 by: Richard Lynch
Re: PHP & HASP
108402 by: Richard Lynch
Re: Upload File Problem
108403 by: Richard Lynch
Re: Accessing Ports
108404 by: Richard Lynch
108435 by: Thomas \"omega\" Henning
Re: apache.conf for php
108405 by: Richard Lynch
Re: rebooting linux using php
108406 by: Richard Lynch
108421 by: Jason Wong
108429 by: Richard Lynch
Re: Check for Associative Array
108407 by: Richard Lynch
Re: spawning scripts to different graphical targets
108408 by: Richard Lynch
Password in script
108412 by: Sailom
108413 by: Tyler Longren
108414 by: Anas Mughal
108415 by: Sailom
108416 by: Tyler Longren
108423 by: Jonathan Rosenberg
108431 by: Sailom
108434 by: Monty
108436 by: Richard Baskett
108448 by: Michael Hall
108449 by: Michael Hall
modify an element of a HTML tag within a string
108420 by: Justin French
108427 by: Monty
108428 by: Richard Lynch
Passing variables to page via POST - How?
108426 by: Monty
108430 by: Anup
108438 by: Chris Shiflett
Help with sockets
108432 by: Jeremy
Re: Truncate ::: DAM!!!!!
108433 by: Rudolf Visagie
vertical word match
108437 by: Joe Rice
108444 by: Martin Towell
Sorting array based on key string
108439 by: Peter J. Pieczora
108445 by: Martin Towell
best way to delete char# 4-7 from a string?
108440 by: Justin French
108446 by: Martin Towell
108463 by: joakim.andersson.cybercom.se
session_unregister question
108441 by: Brad Wright
get line from file
108442 by: Yamin Prabudy
108457 by: Peter
108459 by: Michael Hall
108460 by: Jason Wong
Why won't this work?
108450 by: John Wulff
108451 by: Mantas Kriauciunas
108452 by: Rasmus Lerdorf
108453 by: Monty
108454 by: René Moonen
108455 by: Mantas Kriauciunas
108462 by: jusob.free.fr
108464 by: René Moonen
108466 by: René Moonen
108471 by: joakim.andersson.cybercom.se
108473 by: René Moonen
108474 by: René Moonen
Sablotron confusion
108456 by: Michael Hall
Getting name of referenced variable into string
108458 by: Monty
pdflib
108465 by: Joey
How to Detect File in a Specifc Directory on Window Env?
108467 by: Jack
108468 by: Wouter van Vliet
108469 by: Johan Holst Nielsen
108470 by: Johan Holst Nielsen
108472 by: Johan Holst Nielsen
Re: ErrorDocument 404 & Form
108475 by: Fabien Penso
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
Martin:
On Thu, Jul 18, 2002 at 03:55:13PM -0400, Martin Clifford wrote:
>
> Just a performance question, if anyone knows for sure. Within a large
> array, would using numerical indices be quicker than associative? I'm
> talking about a *noticeable* difference in performance, here.
The difference is marginal. The longer the variable name, the more
resources used, but it's not something that you're really going to notice.
More important is code readability.
But, the difference between turning line wrapping on (~77 columns) in your
email client will save significant time for people replying to your posts.
> $text = eregi_replace("([abc]+)", "<span style=\"color:
> red\">\\1</span>", $text);
>
> Would this replace any occurences of the pattern with the same pattern
> match in red text? I'm not sure exactly how the \\1, \\2, etc. works.
It matches sub-patterns, which are the things in parentheses. The number
corresponds to the parenthetical order.
> $text = eregi_replace("(a)(b)(c)", "\\1", $text);
>
> Does this output only the 'a'?
Exactly.
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409
attached mail follows:
>Just a performance question, if anyone knows for sure. Within a large >array, would using numerical indices be quicker than associative? I'm >talking about a *noticeable* difference in performance, here.
Almost for sure, nope.
Run a test for yourself.
>Also, on Regular Expression replacements: > >$text = eregi_replace("([abc]+)", "<span style=\"color: red\">\\1</span>", $text); > >Would this replace any occurences of the pattern with the same pattern >match in red text? I'm not sure exactly how the \\1, \\2, etc. works. So, does:
Yes, for those browsers that understand the span tag. A quick test script in PHP would have been faster than asking... :-)
>$text = eregi_replace("(a)(b)(c)", "\\1", $text); > >Does this output only the 'a'? I find this confusing for some reason, >hehe. Any help would be great!
Yes. If you had \\2 and \\3 somewhere, they'd be 'b' and 'c' respectively. Again a quick test script in PHP would have been faster...
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
On Thu, Jul 18, 2002 at 04:28:57PM -0400, Monty wrote: > > Look 4 implode() in the function list > > Implode isn't really what I need, I just want to load an entire file into a > single string variable.
Yes, it IS what you need. Plus, to work around your other problems mentioned in later posts...
$string = implode('', file('filename') );
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409
attached mail follows:
In 4.3 you would use file_get_contents()
In prior versions I would suggest:
$fp = fopen('filename','r'); $string = fread($fp, filesize('filename')); fclose($fp);
The implode(file()) stuff is very memory-inefficient.
-Rasmus
On Thu, 18 Jul 2002, Analysis & Solutions wrote:
> On Thu, Jul 18, 2002 at 04:28:57PM -0400, Monty wrote: > > > Look 4 implode() in the function list > > > > Implode isn't really what I need, I just want to load an entire file into a > > single string variable. > > Yes, it IS what you need. Plus, to work around your other problems > mentioned in later posts... > > $string = implode('', file('filename') ); > > --Dan > > -- > PHP classes that make web design easier > SQL Solution | Layout Solution | Form Solution > sqlsolution.info | layoutsolution.info | formsolution.info > T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y > 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
attached mail follows:
Andre, here's the function that worked for me...
function file_get_contents($filename) { $fd = fopen($filename, "r", 1); $contents = fread($fd, 12000); fclose($fd); return $contents; }
$page_string = file_get_contents("my_file.php");
The third parameter in fopen() [1] can be removed if you don't want to look for files in your include_path. The second parameter in fread() [12000] is where I hardcoded the filesize. Increase that number if you'll be opening larger files.
Originally I had "12000" replaced with "filesize($filename)" but if the $filename was opened from the include_path, this seems to always return zero, which is why I hardcoded the byte size into fread().
Monty
> From: aajdubuc
webhart.net (Andre Dubuc)
> Reply-To: aajdubuc
webhart.net
> Newsgroups: php.general
> Date: Thu, 18 Jul 2002 17:45:14 -0400
> To: Monty <monty3
hotmail.com>
> Cc: php-general
lists.php.net
> Subject: Re: [PHP] Loading a File into Variable - How??
>
> Hi Monty,
>
> I've been trying to do the same thing with no success. Would you be so kind
> as to show me how you finally did it? I'm not too clear what you meant by:
>
> "So, if I replace the filesize($filename) command with a hard-coded number,
> it works."
>
> Tia,
> Andre
>
> On Thursday 18 July 2002 04:28 pm, you wrote:
>> I just want to load an entire file into a
>> single string variable.
>>
>> However, I figured out the problem shortly after posting that first message
>> (of course). Because the file being opened is in the include_path, it seems
>> filesize() doesn't see those files. So, if I replace the
>> filesize($filename) command with a hard-coded number, it works.
>>
>> Monty
attached mail follows:
Hi Rasmus,
file_gets_contents() doesn't work in my version of PHP (4.2.1). It says "not a valid function" or something like that. Also, I discovered that the filesize() function won't work on files fopened from the include_path. It returns a value of zero, so, I had to hardcode the bytes into the fread().
> From: rasmus
php.net (Rasmus Lerdorf)
> Newsgroups: php.general
> Date: Thu, 18 Jul 2002 15:14:13 -0700 (PDT)
> To: Analysis & Solutions <danielc
analysisandsolutions.com>
> Cc: PHP List <php-general
lists.php.net>
> Subject: Re: [PHP] Loading a File into Variable - How??
>
> In 4.3 you would use file_get_contents()
>
> In prior versions I would suggest:
>
> $fp = fopen('filename','r');
> $string = fread($fp, filesize('filename'));
> fclose($fp);
>
> The implode(file()) stuff is very memory-inefficient.
>
> -Rasmus
>
attached mail follows:
I'm trying to setup a basic TCP server which I will later expand. Right now I get this error on the loop after it receives data the first time:
Warning: socket_read() unable to read from socket [317]: in f:\public\www\josiah\josiah2\consultation\chat\test_server2.php on line 43 socket_read() failed: reason: Incorrect function.
Any ideas? See the server code below.
<?php /* * We don't want any time-limit for how the long can hang * around, waiting for connections: */ set_time_limit(0); error_reporting (E_ALL);
/* Allow the script to hang around waiting for connections. */ set_time_limit (0);
/* Turn on implicit output flushing so we see what we're getting * as it comes in. */ ob_implicit_flush ();
$address = '172.25.190.4'; $port = 10003;
if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) { echo "socket_create() failed: reason: " . socket_strerror ($sock) . "\n"; }
if (($ret = socket_bind ($sock, $address, $port)) < 0) { echo "socket_bind() failed: reason: " . socket_strerror ($ret) . "\n"; }
if (($ret = socket_listen ($sock, 5)) < 0) { echo "socket_listen() failed: reason: " . socket_strerror ($ret) . "\n"; }
do { if (($msgsock = socket_accept($sock)) < 0) { echo "socket_accept() failed: reason: " . socket_strerror ($msgsock) . "\n"; break; } /* Send instructions. */ $msg = "\nWelcome to the PHP Test Server. \n" . "To quit, type 'quit'. To shut down the server type 'shutdown'.\n"; socket_write($msgsock, $msg, strlen($msg));
do { if (FALSE === ($buf = socket_read ($msgsock, 2048))) { echo "socket_read() failed: reason: " . socket_strerror ($ret) . "\n"; break 2; } if (!$buf = trim ($buf)) { continue; } if ($buf == 'quit') { break; } if ($buf == 'shutdown') { socket_close ($msgsock); break 2; } $talkback = "PHP: You said '$buf'.\n"; socket_write ($msgsock, $talkback, strlen ($talkback)); echo "$buf\n"; } while (true); socket_close ($msgsock); } while (true);
socket_close ($sock); ?>
attached mail follows:
>I'm trying to setup a basic TCP server which I will later expand. Right now >I get this error on the loop after it receives data the first time: > >Warning: socket_read() unable to read from socket [317]: in >f:\public\www\josiah\josiah2\consultation\chat\test_server2.php on line 43 >socket_read() failed: reason: Incorrect function.
Your code works perfectly on my Linux box...
The first time I ran it.
After a 'shutdown' (of your server, not the whole box) though, it bitched about socket_bind and an already used address...
Sometimes. It seems to be depending on whether I started it with or without & and then ^C or not, and 'shutdown' seems to only work sometimes...
That doesn't seem right to me... :-)
So maybe you have old processes hanging around, spewing out error messages to MS-DOS prompts that are long-gone?
Maybe just try a re-boot of the whole box... It is Windows, after all.
Does socket_close() have a return value to indicate success/failure? Don't end the loop if it didn't really close, I guess.
> >Any ideas? See the server code below. > ><?php > /* > * We don't want any time-limit for how the long can hang > * around, waiting for connections: > */ > set_time_limit(0); > >error_reporting (E_ALL); > >/* Allow the script to hang around waiting for connections. */ >set_time_limit (0); > >/* Turn on implicit output flushing so we see what we're getting > * as it comes in. */ >ob_implicit_flush ();
Like, I think ob_XXXX only affects stuff you echo out to the BROWSER (aka stdout). I don't think it's gonna do squat for your TCP server... Won't hurt, though... Or is this just for that echo line way down below? I would do: echo $tcp; flush(); personally... But I'm old and don't trust the new functions as much :-)
> >$address = '172.25.190.4'; >$port = 10003; > >if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) { > echo "socket_create() failed: reason: " . socket_strerror ($sock) . >"\n"; >} > >if (($ret = socket_bind ($sock, $address, $port)) < 0) { > echo "socket_bind() failed: reason: " . socket_strerror ($ret) . "\n"; >} > >if (($ret = socket_listen ($sock, 5)) < 0) { > echo "socket_listen() failed: reason: " . socket_strerror ($ret) . "\n"; >} > >do { > if (($msgsock = socket_accept($sock)) < 0) { > echo "socket_accept() failed: reason: " . socket_strerror ($msgsock) >. "\n"; > break; > } > /* Send instructions. */ > $msg = "\nWelcome to the PHP Test Server. \n" . > "To quit, type 'quit'. To shut down the server type 'shutdown'.\n"; > socket_write($msgsock, $msg, strlen($msg)); > > do { > if (FALSE === ($buf = socket_read ($msgsock, 2048))) { > echo "socket_read() failed: reason: " . socket_strerror ($ret) . >"\n"; > break 2; > } > if (!$buf = trim ($buf)) {
This ain't right...
No, maybe it is...
You want an assignment there, but you really ought to be doing the trim() on 'quit ' as well, to be nice to bad typists like me :-)
And some parens around the assignment would be nifty.
> continue; > } > if ($buf == 'quit') { > break; > } > if ($buf == 'shutdown') { > socket_close ($msgsock); > break 2; > } > $talkback = "PHP: You said '$buf'.\n"; > socket_write ($msgsock, $talkback, strlen ($talkback)); > echo "$buf\n"; > } while (true); > socket_close ($msgsock); >} while (true); > >socket_close ($sock); >?>
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
hi,
anyone have an opinion on postnuke versus geekware for a php-based CMS?
cheers, jaxon
attached mail follows:
I've been reasonably happy with postnuke -- easy to go in and modify stuff yourself.
htp://jonroig.com
... but maybe that's just me. I'd actually be curious as to what kind experience people have had with the other systems.
-- jon
-----Original Message-----
From: jaxon [mailto:jaxon
salamander.net]
Sent: Thursday, July 18, 2002 6:52 PM
To: php-general
lists.php.net
Subject: [PHP] postnuke / geekware?
hi,
anyone have an opinion on postnuke versus geekware for a php-based CMS?
cheers, jaxon
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
> hi, > > anyone have an opinion on postnuke versus geekware for a php-based CMS? > > cheers, > jaxon
No...I kind of prefer GeekLog... geeklog.sourceforge.net
---John Holmes...
attached mail follows:
At 08:16 PM 7/18/2002 -0400, John Holmes wrote: > > hi, > > > > anyone have an opinion on postnuke versus geekware for a php-based >CMS? > > > > cheers, > > jaxon > >No...I kind of prefer GeekLog... geeklog.sourceforge.net > >---John Holmes... > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php
John,
Reasons why? I've been looking at a number of them; PostNuke seems to have the most aggressive development effort, including modules, blocks and themes.
Miles Thompson
attached mail follows:
I use MyPhpNuke (MPN) http://www.myphpnuke.com/ which appears to have lots of nice extensions to the phpnuke product including a forums, picture gallery, contact form, user mailing system, and many others. These things are so tightly integrated into the product, that it's tough to tell which options are from the base product or added on. This one seems to have manuals in the latest versions that provide a guide adding your own modules (I have just begun to add interactive, multimedia training courses). The site at http://www.hotscripts.com categorizes this system as a "Portal System" among 52 offerings and under customer "Support" systems (is this what you mean by CMS?) they list 34 offerings (many for sale, many for free).
hope this helps,
Warren Vail Tools, Metrics & Quality Processes
-----Original Message-----
From: Miles Thompson [mailto:milesthompson
ns.sympatico.ca]
Sent: Thursday, July 18, 2002 6:53 PM
To: php-general
lists.php.net
Subject: RE: [PHP] postnuke / geekware?
At 08:16 PM 7/18/2002 -0400, John Holmes wrote: > > hi, > > > > anyone have an opinion on postnuke versus geekware for a php-based >CMS? > > > > cheers, > > jaxon > >No...I kind of prefer GeekLog... geeklog.sourceforge.net > >---John Holmes... > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php
John,
Reasons why? I've been looking at a number of them; PostNuke seems to have the most aggressive development effort, including modules, blocks and themes.
Miles Thompson
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
> > > anyone have an opinion on postnuke versus geekware for a php-based > >CMS?
> >No...I kind of prefer GeekLog... geeklog.sourceforge.net
> Reasons why? I've been looking at a number of them; PostNuke seems to have > the most aggressive development effort, including modules, blocks and > themes.
Yeah, the Nukes do have a lot of development for them and a lot of modules, but it makes them big and bloated. I like geeklog because it's still small and clean. You can still mold it into something that works for you...
---John Holmes...
attached mail follows:
At 7/18/2002, you wrote: >On Thu, Jul 18, 2002 at 03:40:58PM -0400, Joshua E Minnie wrote: > > Hey all, > > Does anybody know of a way to push an element onto an array with a > > specific key? What I am trying to do is create a dynamically created > > associative array. Here is a sample print_r of what an array would look > > like: > >I don't understand the value of array_push(). I just add new elements by >something like: > > $Array[$Key] = $Value;
I think array_push gets you cleaner lookin code (subjective). It also ensures you always add to end of the array - good for novices like me. Array_push is also TWO times faster (academic difference in the speeds of modern computers, but faster :) :
<?php
function getMicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); }
$start = getMicrotime();
for ($n=0;$n>=10000;$n++) { $Array[$n] = $n; }
$stop = getMicrotime(); $diff1 = $stop - $start; print "array key insert time was: " . $diff1 . "s";
$start = getMicrotime();
$array2 = array(); for ($n=0;$n>=10000;$n++) { array_push($array2,$n); }
$stop = getMicrotime(); $diff2 = $stop - $start; print "<br>array_push time was: " . $diff2 . "s";
?>
------------------------- Pekka Saarinen http://photography-on-the.net -------------------------
attached mail follows:
On Fri, Jul 19, 2002 at 01:58:42AM +0300, Pekka Saarinen wrote: > > I think array_push gets you cleaner lookin code (subjective). It also > ensures you always add to end of the array - good for novices like > me. Array_push is also TWO times faster (academic difference in the speeds > of modern computers, but faster :) :
AH! But your test is flawed. Reorder things so the push is first and that'll be slower. In addition, push() is more like setting $Array[] rather than $Array[$n].
So, here's my test, including some arithmetic calculation changes:
<pre> <?php
function getMicrotime() { list($usec, $sec) = explode(' ', microtime() ); return bcadd($usec, $sec, 6); }
# ROUND 1
$Array = array(); $start = getMicrotime(); for ($n=0;$n>=10000;$n++) { $Array[$n] = $n; } $stop = getMicrotime(); echo 'key num: ' . (bcsub($stop, $start, 6)) . "\n";
$Array = array(); $start = getMicrotime(); for ($n=0; $n>=10000; $n++) { array_push($Array, $n); } $stop = getMicrotime(); echo 'push: ' . (bcsub($stop, $start, 6)) . "\n";
$Array = array(); $start = getMicrotime(); for ($n=0; $n>=10000; $n++) { $Array[] = $n; } $stop = getMicrotime(); echo 'key blank: ' . (bcsub($stop, $start, 6)) . "\n";
# ROUND 2
$Array = array(); $start = getMicrotime(); for ($n=0;$n>=10000;$n++) { $Array[$n] = $n; } $stop = getMicrotime(); echo 'key num: ' . (bcsub($stop, $start, 6)) . "\n";
$Array = array(); $start = getMicrotime(); for ($n=0; $n>=10000; $n++) { array_push($Array, $n); } $stop = getMicrotime(); echo 'push: ' . (bcsub($stop, $start, 6)) . "\n";
$Array = array(); $start = getMicrotime(); for ($n=0; $n>=10000; $n++) { $Array[] = $n; } $stop = getMicrotime(); echo 'key blank: ' . (bcsub($stop, $start, 6)) . "\n";
?> </pre>
Results...
key num: 0.000301 push: 0.000145 key blank: 0.000135 key num: 0.000136 push: 0.000135 key blank: 0.000135
The times compared to each other varied each time I reran the test.
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409
attached mail follows:
I think you're missing some fundamental concepts of sessions here. You must think of the session as a file that you're going to include into the script (becuase.. that's litteraly what it is). But instead of using include() you're going to use session_start();
<? session_start(); if (!session_is_registered("myvar")) { $myvar = 'peek a boo'; session_register("myvar"); } else { echo $myvar; session_unregister("myvar"); }
echo "<p><a href=\"$PHP_SELF\">(refresh)</a>"; ?>
When you activate this script for the first time three things happen.. 1) the session file is created on the server 2) a cookie with the Session ID is stored on your computer 3) $myvar = 'peek a boo'; is added to the session file
When you click refresh to reactivate the script, PHP will match the session id stored in the cookie to the file stored on the server, and include the variables into the actively running script. $myvar is now available and the contents are printed to the screen then unregistered (removed) from the session file. The third time around it's going to stop in the if() portion and reregister the variable. Adding and removing lines from a file and including them into your script.. it's no more complicated than that.
Hopefully now you'll be able to fix your problem and learn to use sessions reliably and effectively. :)
-Kevin
----- Original Message -----
From: "N. Pari Purna Chand" <chandu
mihiramail.net>
To: <php-general
lists.php.net>
Sent: Thursday, July 18, 2002 3:36 PM
Subject: [PHP] Refreshing session variables
> Hi guys, > > I got a problem with refreshing session variables. > When the following code is run , for the first time > both $z and $secretstring are showing same values. > > But when page is refreshed, the $secretstring variable > is still having the old value no matter how many times > I click refresh. > > Am I missing some thing ? > > <? > $x = mt_rand (1000,10000); > $y = mt_rand (1000,10000); > > $text = $x.$y; > $secretstring =$x.$y; > > session_start(); > if(session_is_registered("secretstring")){ > session_unregister("secretstring"); > } > session_register("secretstring"); > > echo "<BR>".$text; > echo "<BR>".$secretstring; > > ?> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
attached mail follows:
> <? > $x = mt_rand (1000,10000); > $y = mt_rand (1000,10000); > > $text = $x.$y; > $secretstring =$x.$y; > > session_start(); > if(session_is_registered("secretstring")){ > session_unregister("secretstring"); > } > session_register("secretstring");
What good do you think this does? There is no 'else' here. If 'secretstring' is registered, you unregister it, and then register it again in the next line...
Yeah...it's going to be there with each request because register_globals is probably on and the session value is going to take precedence over your local value you just calculated for $secretstring because you call session_start() after it's been set.
---John Holmes...
attached mail follows:
>I got a problem with refreshing session variables. >When the following code is run , for the first time >both $z and $secretstring are showing same values. > >But when page is refreshed, the $secretstring variable >is still having the old value no matter how many times >I click refresh. > >Am I missing some thing ?
I always put the session_register stuff *before* I start putting stuff into my variables, but maybe that's just me...
What you are missing, though is that whether you 'unregister' it or not, you *always* 'register' it again in the next line.
If you expect it to change, you'd need:
else{ session_regsiter('secretstring'); }
><? >$x = mt_rand (1000,10000); >$y = mt_rand (1000,10000); > >$text = $x.$y; >$secretstring =$x.$y; > >session_start(); >if(session_is_registered("secretstring")){ >session_unregister("secretstring"); >} >session_register("secretstring"); > >echo "<BR>".$text; >echo "<BR>".$secretstring; > >?> >
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
On Thu, 18 Jul 2002 08:40:08 -0600, you wrote:
See below...
>At 09:20 PM 7/17/02 -0500, Michael Sims wrote: > >>$superglobals = array("var1", "var2", "var3", "var4", "var5", "..."); >> >>Now inside the function you can do this: >> >>function somefunction ($somevar) { >> >> global $superglobals; >> foreach($superglobals as $varname) { >> global $$varname; //resolves to $var1, $var2, $var3, etc. >> } >> >> //Other stuff here >> >>} > >You're working too hard! > >function somefunction( $somevar ) { > >global $suberglobals; > >extract( $superglobals ); > >//Other stuff here > >}
Sorry, but your version is not functionally equivalent to mine. The call to extract() is creating locally scoped versions of those variables which do NOT reference the global versions. For proof, go here:
http://mhs-dev.crye-leike.com/test.php
Thanks for the pointer to extract() though, I had never used it before.
attached mail follows:
Not sure if this is something Mandrake could have done by accident, or if it's release related to PHP...
I'm trying to run ldap navigator, and it runs fine on my Mandrake 8.1 box, but moving it to Mandrake 8.2, it complains about missing utf8_decode...
PHP package version is 4.1.2-1mdk. The ldap navigator bug list reports another person with the same issue.
Any help here?
-- Les Barstow | System Administrator | "A society of sheep must in time beget VR1 Entertainment Inc.| a government of wolves." http://www.vr1.com | -- Bertrand de Jouvenel
attached mail follows:
Alguém sabe o que esse erro significa? Which the mistake in this function?
Warning: HTTP request failed! HTTP/1.1 404 Objeto não encontrado in D:\Projetos\Websites\Portal_Origem\adm\incprodutos.php on line 64
Warning: copy("http://doiscliques/origem-novo/web/upload/alias.bmp") - No error in D:\Projetos\Websites\Portal_Origem\adm\incprodutos.php on line 64
Minha Function é esta. My function is this.
function uploadProg($filename1,$filename1_name,$codigo) { require("config.ini"); global $file; global $codigo; global $login; global $destination; file://destino dos arquivos $destination=$path; file://copia dos arquivos $str =""; $extensao = strrchr($filename1_name,'.'); copy($filename1,$destination."/".$filename1_name); $file = filesize($filename1); $filesize = number_format($file,0,',','.'); $str = $str . "|$filename1_name|"; file://avisa que foi alterado o manual $conn = mysql_connect($host,$user,$pass); mysql_select_db($db); $sql = "update produtos set " . "bytes = '$file'" . "where codigo = '$codigo'"; $res2 = mysql_query($sql); } file://fim da function uploadprog
Obrigado Thanks
attached mail follows:
Hi all...
I'm a complete beginner in programming. Just started a few months ago.
So, I'm sorry if this is a stupid question to ask. But I'm at a dead end here and do not know where else to go.
I'm trying to automate a checkbox name to have the name "choice1" to have incremental effect on the number such as the following:
<input type="checkbox" name="choice1" value="x"> <input type="checkbox" name="choice2" value="x"> <input type="checkbox" name="choice3" value="x"> ...
And I used the following script (please don't laugh) :)
Maximise this email to full screen so that you can see the script better.
for($count=1; $count<=$rows; $count++) { while($query_data = mysql_fetch_array($result)) { $price = $query_data["price_lq"]; $RowColor = useColor(); echo "<TR BGCOLOR=\"$RowColor\">\n"; echo "<TD width=\"10%\" valign=\"top\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">",$query_data["prod_brand"],"<BR></FONT</TD>"; echo "<TD width=\"60%\" valign=\"top\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">",$query_data["prod_desc"],"<BR></FONT></TD>"; echo "<TD width=\"15%\" valign=\"top\<font size=\"2\" face=\"Arial, Helvetica, sans-serif\">","$",$price,"<BR></FONT></TD>"; echo "<TD width=\"15%\" valign=\"top\"><input type=\"checkbox\" name=\"choice",$count,"\" value=\"", $query_data["prod_id"],"\"></TD>\n</TR>"; } }
The result was irritating... it came up with the same name, which is "choice1" all the way like:
<input type="checkbox" name="choice1" value="x"> <input type="checkbox" name="choice1" value="x"> <input type="checkbox" name="choice1" value="x"> ...
Am I doing it the wrong way? If so, how should I do it?
Please pleas help... thanks
Yours, Wee Keat
------------------------------------------------------------ "Good timber does not grow with ease; the stronger the wind, the stronger the trees."
attached mail follows:
Hello Wee,
Friday, July 19, 2002, 2:36:40 AM, you wrote:
WK> Hi all...
WK> I'm a complete beginner in programming. Just started a few months ago.
WK> So, I'm sorry if this is a stupid question to ask. But I'm at a dead end here and do not know where else to go.
WK> I'm trying to automate a checkbox name to have the name "choice1" to have incremental effect on the number such as the following:
WK> <input type="checkbox" name="choice1" value="x"> WK> <input type="checkbox" name="choice2" value="x"> WK> <input type="checkbox" name="choice3" value="x"> WK> ...
WK> And I used the following script (please don't laugh) :)
WK> Maximise this email to full screen so that you can see the script better.
WK> for($count=1; $count<=$rows; $count++) { WK> while($query_data = mysql_fetch_array($result)) { WK> $price = $query_data["price_lq"]; WK> $RowColor = useColor(); WK> echo "<TR BGCOLOR=\"$RowColor\">\n"; WK> echo "<TD width=\"10%\" valign=\"top\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">",$query_data["prod_brand"],"<BR></FONT</TD>"; WK> echo "<TD width=\"60%\" valign=\"top\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">",$query_data["prod_desc"],"<BR></FONT></TD>"; WK> echo "<TD width=\"15%\" valign=\"top\<font size=\"2\" face=\"Arial, Helvetica, sans-serif\">","$",$price,"<BR></FONT></TD>"; WK> echo "<TD width=\"15%\" valign=\"top\"><input type=\"checkbox\" name=\"choice",$count,"\" value=\"", $query_data["prod_id"],"\"></TD>\n</TR>"; WK> } WK> }
WK> The result was irritating... it came up with the same name, which is "choice1" all the way like:
WK> <input type="checkbox" name="choice1" value="x"> WK> <input type="checkbox" name="choice1" value="x"> WK> <input type="checkbox" name="choice1" value="x"> WK> ...
WK> Am I doing it the wrong way? If so, how should I do it?
WK> Please pleas help... thanks
WK> Yours, WK> Wee Keat
WK> ------------------------------------------------------------ WK> "Good timber does not grow with ease; the stronger the wind, the stronger the trees."
echo "<TD width=\"15%\" valign=\"top\"><input type=\"checkbox\" name=\"choice",$count,"\" value=\"", $query_data["prod_id"],"\"></TD>\n</TR>";
Your problem is with this line. Look closely at the following part:
name=\"choice",$count,"\"
You should do this:
name=\"choice" . $count . "\"
... and it will generate names like 'choice1', 'choice2', and so on.
-- Best regards, Asmodean mailto:asmodeanlka.nu
attached mail follows:
Asmodean - using comma is another way of using echo...
Wee - try this instead - you're putting two loops together when you don't need to
for($count=1; $count<=$rows; $count++) { $query_data = mysql_fetch_array($result); $price = $query_data["price_lq"]; $RowColor = useColor(); // current echo statements here }
or
$count=1; while($query_data = mysql_fetch_array($result)) { $price = $query_data["price_lq"]; $RowColor = useColor(); // current echo statements here } $count++;
-----Original Message-----
From: Asmodean [mailto:asmodean
lka.nu]
Sent: Friday, July 19, 2002 10:48 AM
To: PHP General
Subject: Re: [PHP] Please Help with LOOP!!
Hello Wee,
Friday, July 19, 2002, 2:36:40 AM, you wrote:
WK> Hi all...
WK> I'm a complete beginner in programming. Just started a few months ago.
WK> So, I'm sorry if this is a stupid question to ask. But I'm at a dead end here and do not know where else to go.
WK> I'm trying to automate a checkbox name to have the name "choice1" to have incremental effect on the number such as the following:
WK> <input type="checkbox" name="choice1" value="x"> WK> <input type="checkbox" name="choice2" value="x"> WK> <input type="checkbox" name="choice3" value="x"> WK> ...
WK> And I used the following script (please don't laugh) :)
WK> Maximise this email to full screen so that you can see the script better.
WK> for($count=1; $count<=$rows; $count++) { WK> while($query_data = mysql_fetch_array($result)) { WK> $price = $query_data["price_lq"]; WK> $RowColor = useColor(); WK> echo "<TR BGCOLOR=\"$RowColor\">\n"; WK> echo "<TD width=\"10%\" valign=\"top\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">",$query_data["prod_brand"],"<BR></FONT</TD>"; WK> echo "<TD width=\"60%\" valign=\"top\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">",$query_data["prod_desc"],"<BR></FONT></TD>"; WK> echo "<TD width=\"15%\" valign=\"top\<font size=\"2\" face=\"Arial, Helvetica, sans-serif\">","$",$price,"<BR></FONT></TD>"; WK> echo "<TD width=\"15%\" valign=\"top\"><input type=\"checkbox\" name=\"choice",$count,"\" value=\"", $query_data["prod_id"],"\"></TD>\n</TR>"; WK> } WK> }
WK> The result was irritating... it came up with the same name, which is "choice1" all the way like:
WK> <input type="checkbox" name="choice1" value="x"> WK> <input type="checkbox" name="choice1" value="x"> WK> <input type="checkbox" name="choice1" value="x"> WK> ...
WK> Am I doing it the wrong way? If so, how should I do it?
WK> Please pleas help... thanks
WK> Yours, WK> Wee Keat
WK> ------------------------------------------------------------ WK> "Good timber does not grow with ease; the stronger the wind, the stronger the trees."
echo "<TD width=\"15%\" valign=\"top\"><input type=\"checkbox\" name=\"choice",$count,"\" value=\"", $query_data["prod_id"],"\"></TD>\n</TR>";
Your problem is with this line. Look closely at the following part:
name=\"choice",$count,"\"
You should do this:
name=\"choice" . $count . "\"
... and it will generate names like 'choice1', 'choice2', and so on.
-- Best regards, Asmodean mailto:asmodeanlka.nu
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
martin- you're totally right except for one thing....
>$count=1; >while($query_data = mysql_fetch_array($result)) >{ > $price = $query_data["price_lq"]; > $RowColor = useColor(); > // current echo statements here >} >$count++;
this code will give him the exact same problem. the
$count++;
line needs to be *inside* the while loop. probably a typing mistake on your part, but i didn't want this guy to get help that ended him up with the same problem =).
-jerome
_________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx
attached mail follows:
THANK YOU SOOOOOOOOOOOO MUCH FOR ALL YOUR HELP!!
God... in just five minutes you guys have helped me solved a problem I've tried to figure out in an hour!!!
I finally decided to take off the loop and used only the while loop.... it WORKED beautifully!!!!!
Thank you soooo much Lejanson, Asmodean, Martin and Dave..... and all who helped.
Really really appreciate it.
KISS TO ALL OF YAS!!!
----- Original Message -----
From: "Martin Towell" <martin.towell
world.net>
To: "PHP General" <php-general
lists.php.net>
Sent: Friday, July 19, 2002 10:46 AM
Subject: RE: [PHP] Please Help with LOOP!!
> Asmodean - using comma is another way of using echo...
>
> Wee - try this instead - you're putting two loops together when you don't
> need to
>
> for($count=1; $count<=$rows; $count++)
> {
> $query_data = mysql_fetch_array($result);
> $price = $query_data["price_lq"];
> $RowColor = useColor();
> // current echo statements here
> }
>
> or
>
> $count=1;
> while($query_data = mysql_fetch_array($result))
> {
> $price = $query_data["price_lq"];
> $RowColor = useColor();
> // current echo statements here
> }
> $count++;
>
> -----Original Message-----
> From: Asmodean [mailto:asmodean
lka.nu]
> Sent: Friday, July 19, 2002 10:48 AM
> To: PHP General
> Subject: Re: [PHP] Please Help with LOOP!!
>
>
> Hello Wee,
>
> Friday, July 19, 2002, 2:36:40 AM, you wrote:
>
> WK> Hi all...
>
> WK> I'm a complete beginner in programming. Just started a few months ago.
>
> WK> So, I'm sorry if this is a stupid question to ask. But I'm at a dead
end
> here and do not know where else to go.
>
> WK> I'm trying to automate a checkbox name to have the name "choice1" to
> have incremental effect on the number such as the following:
>
> WK> <input type="checkbox" name="choice1" value="x">
> WK> <input type="checkbox" name="choice2" value="x">
> WK> <input type="checkbox" name="choice3" value="x">
> WK> ...
>
> WK> And I used the following script (please don't laugh) :)
>
> WK> Maximise this email to full screen so that you can see the script
> better.
>
> WK> for($count=1; $count<=$rows; $count++) {
> WK> while($query_data = mysql_fetch_array($result)) {
> WK> $price = $query_data["price_lq"];
> WK> $RowColor = useColor();
> WK> echo "<TR BGCOLOR=\"$RowColor\">\n";
> WK> echo "<TD width=\"10%\" valign=\"top\"><font size=\"2\"
> face=\"Arial, Helvetica,
> sans-serif\">",$query_data["prod_brand"],"<BR></FONT</TD>";
> WK> echo "<TD width=\"60%\" valign=\"top\"><font size=\"2\"
> face=\"Arial, Helvetica,
> sans-serif\">",$query_data["prod_desc"],"<BR></FONT></TD>";
> WK> echo "<TD width=\"15%\" valign=\"top\<font size=\"2\"
face=\"Arial,
> Helvetica, sans-serif\">","$",$price,"<BR></FONT></TD>";
> WK> echo "<TD width=\"15%\" valign=\"top\"><input type=\"checkbox\"
> name=\"choice",$count,"\" value=\"",
> $query_data["prod_id"],"\"></TD>\n</TR>";
> WK> }
> WK> }
>
> WK> The result was irritating... it came up with the same name, which is
> "choice1" all the way like:
>
> WK> <input type="checkbox" name="choice1" value="x">
> WK> <input type="checkbox" name="choice1" value="x">
> WK> <input type="checkbox" name="choice1" value="x">
> WK> ...
>
> WK> Am I doing it the wrong way? If so, how should I do it?
>
> WK> Please pleas help... thanks
>
> WK> Yours,
> WK> Wee Keat
>
> WK> ------------------------------------------------------------
> WK> "Good timber does not grow with ease; the stronger the wind, the
> stronger the trees."
>
> echo "<TD width=\"15%\" valign=\"top\"><input type=\"checkbox\"
> name=\"choice",$count,"\" value=\"",
> $query_data["prod_id"],"\"></TD>\n</TR>";
>
> Your problem is with this line. Look closely at the following part:
>
> name=\"choice",$count,"\"
>
> You should do this:
>
> name=\"choice" . $count . "\"
>
> ... and it will generate names like 'choice1', 'choice2', and so on.
>
> --
> Best regards,
> Asmodean mailto:asmodean
lka.nu
>
>
> --
> 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
attached mail follows:
in ym search page, i construct a sql query from user input to search my database, and i run this query to get totalresults. Then run another query with a LIMIT 0, 30 ending for each page. So I'm running 2 mySQL queries per page. My question is, is this inefficient? is there any better way i dont know of? or does the 2 queries not mka emuch of a difference
-- Regards, Georgie Casey webmasterfilmfind.tv
*************************** http://www.filmfind.tv Online Film Production Directory ***************************
attached mail follows:
> in ym search page, i construct a sql query from user input to search my > database, and i run this query to get totalresults. Then run another query > with a LIMIT 0, 30 ending for each page. So I'm running 2 mySQL queries > per > page. My question is, is this inefficient? is there any better way i dont > know of? or does the 2 queries not mka emuch of a difference
You have to use two queries, so there's no getting around that. You should be using count(*) in your first query, it'll make it faster.
SELECT COUNT(*) FROM table WHERE ...
---John Holmes...
attached mail follows:
On Friday 19 July 2002 10:21, Georgie Casey wrote: > in ym search page, i construct a sql query from user input to search my > database, and i run this query to get totalresults. Then run another query > with a LIMIT 0, 30 ending for each page. So I'm running 2 mySQL queries per > page. My question is, is this inefficient? is there any better way i dont > know of? or does the 2 queries not mka emuch of a difference
If the results of the first query were small enough to be completely kept in the (RAM) cache then the second query would be performed much quicker.
-- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development */* "Don't hate me because I'm beautiful. Hate me because I'm beautiful, smart and rich." -- Calvin Keegan */
attached mail follows:
In article <20020719012550.26135.qmail
pb1.pair.com>,
webmaster
filmfind.tv says...
> in ym search page, i construct a sql query from user input to search my
> database, and i run this query to get totalresults. Then run another query
> with a LIMIT 0, 30 ending for each page. So I'm running 2 mySQL queries per
> page. My question is, is this inefficient? is there any better way i dont
> know of? or does the 2 queries not mka emuch of a difference
>
You might consider running the first query just to get a COUNT(), rather than extracting all the resulting rows and using mysql_numrows to determine how many were returned
-- David Robley Temporary Kiwi!Quod subigo farinam
attached mail follows:
On Friday 19 July 2002 14:08, David Robley wrote:
> You might consider running the first query just to get a COUNT(), rather > than extracting all the resulting rows and using mysql_numrows to > determine how many were returned
Am I missing something? If you do a COUNT() in the query then, in general, it'll only return 1 row. You then use this row to determine the result of the COUNT(). IE using mysql_numrows() on this result is inappropriate.
-- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development */* Keep up the good work! But please don't ask me to help. */
attached mail follows:
on 19/07/02 3:47 AM, Alberto Serra (albertoserra
gala.net) wrote:
> We use but one cookie, for returning user recognition. That is, the sort > of info your soft can survive without. As for passing values on the GET > channel to iframes, we do it all the time and have never seen a single > problem.
Passing a SID via URL to an IFRAME is not the problem -- I was referring to the fact that I don't *think* --enable-trans-sid can handle IFRAMEs, from my limited look at the PHP source.
Justin French
attached mail follows:
on 19/07/02 4:49 AM, Scott Fletcher (scott
abcoa.com) wrote:
> I never heard of this php function, "link()". Sound like a good function, > I'm going to have to look it up!
Ummm, sorry, it's one that I wrote myself in my library of code -- not an official function.
my function link() takes the standard link, and adds the SID to it. It's not that tricky, all it does is check if there's already a query string, if there is, it appends the SID with &, otherwise with ?.
Justin French
attached mail follows:
Justin French wrote:
JF> As has been said on this list MANY times, just have a look at the big sites JF> like amazon.com -- no cookies, no javascript, no reliance on client-side for JF> anything. Take care of it all server-side, where you have a controlled JF> environment.
And what about yahoo.com? Is it big enough? :)
-- Best regards, Evgeny
attached mail follows:
> If you want 100% accessability, forget cookies were ever invented :) > While you're erasing stuff from your brain, throw out javascript too :D
Some people don't have a fast access to internet. Very simple javascript to validate a form before submitting it can be IMHO still useful. But I agree that other uses of javascript, in most of the cases, can be avoided. Regards, Philippe
attached mail follows:
Is PostgreSQL started with the -i switch? (I think that's the one; it exposes it to tcp/ip connections.) Check your PGSQL docs to be certain.
Have you run a page with phpinfo? Is PostgreSQL support compiled into your installation of PHP? This is a file consisting of <? phpinfo(); ?>, named phpinfo.php. Again, I'm doing this from memory but I'm pretty certain of the function name.
If you have a yes to those questions, then we can start on the rest. Check to see if there is a pg_error function you can call if the connection fails. Keep error reporting at a high level so we can see what they are.
Regards - Miles Thompson
At 06:37 PM 7/18/2002 -0700, Vincent wrote: >Hi, I'm a newbie here. I don't know what went wrong. >I've tried searching for solutions and can't find any. >How come pg_connect() isn't defined? Should I include >any header files or something in php? > >Here's my code: > ><?php $conn = pg_connect("dbname=phpdb"); if (!$conn) { echo "Unable to >connect to database >"; } else print "Connected"; ?> >I've tried installing Apache's rpm and Php's rpm. I'm >running on RedHat Linux 7.3. apache_1.3.23-11.i386.rpm >and php-4.1.2-7.rpm. Then, it still gives me the error >message. So, I tried the gz version using >apache_1.3.26.tar.gz and php-4.2.1.tar.gz. Nothing >works. I've tried looking into the php.ini files, >adding extension to pgsql.so. > >Have any of you encountered this problem before? > >__________________________________________________ >Do You Yahoo!? >Yahoo! Autos - Get free new car price quotes >http://autos.yahoo.com > >-- >PHP Database Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
At 11:02 PM 7/18/02 -0300, you wrote: >Is PostgreSQL started with the -i switch? (I think that's the one; it >exposes it to tcp/ip connections.) Check your PGSQL docs to be certain.
This is not the problem.
>Have you run a page with phpinfo? Is PostgreSQL support compiled into your >installation of PHP? This is a file consisting of ><? phpinfo(); ?>, named phpinfo.php. Again, I'm doing this from memory but >I'm pretty certain of the function name.
phpinfo() is correct, but not needed.
"Call to undefined function" means that PHP was not compiled with this function.
Your best bet is to trash the RPM and compile PHP and possibly Apache from the distribution tarball. You can bang you head against various combinations of RPMs for weeks and never find the right combination, or spend a couple hours collecting the requirements and learning to compile the source. Once I got it down I can compile OpenSSL, Apache, ModSSL PHP and all the goodies that go along with it in about 45 minutes, and I don't even have to be there for most of it. I've got a script that compiles it with all the options I chose. I just collect the latest versions, check for new options I might want to use, plug the new version numbers into the top of the script, run it and go find something else to do while it runs.
Rick
attached mail follows:
>PHP is compiled with PostgreSQL support but I can not connect. I get >this error message What does it mean and what do I need to do to fix >it > >Warning: pg_connect() unable to connect to PostgreSQL server: connectDB() >-- connect() failed: Connection refused Is the postmaster running (with -i) >at 'localhost' and accepting connections on TCP/IP port '5583'? in >/home/sites/home/web/test/test.php on line 2
Show us the pg_connect() line...
You need it to look like this: $connection = pg_connect('host=localhost user=XXXXXXXX password=XXXXXXXX dbname=');
One big long string instead of a bunch of arguments.
Does ps auxwwww | grep postmaster show anything useful?
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>The script was working great before PHP 4.2.x and not after that. So, I >looked through the code and came upon this variable, "$$var". I have no >idea what the purpose of the double "$" is for a variable. Anyone know?
> $var = "v".$counter."_high_indiv"; > $val3 = $$var;
Read the manual about "variable variables"
basically, they are creating a variable name like 'v1_high_indiv' (in $var) and then when they say $$var they really mean $v1_high_indiv
It's probably not the source of your problem.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>$users=file('.users');
>fwrite ($fd, join("\n",$users));
file puts each line in a separate element of the array, but it does *NOT* strip off the \n in doing so.
When you join them back together, *YOU* added an extra \n in the join.
You want join('', $users)
That will join them with no extra characters.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I have created a table which has a column called cost. How do I add up all >the numerical data in the cost column and display that on a webpage?
<?php $query = "select sum(cost) from whatever where blah, blah, blah"; $cost = mysql_query($query) or error_log(mysql_error()); $cost = mysql_result($cost, 0, 0); ?>
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Could someone please explain the difference between classes and functions >and how to use a class. I write alot of PHP, but I never understood this at >all. I use an include statement in many of my pages and include a file with >a bunch of functions. For instance, I might have a function called stock(); >In the page I am using I include the file that has this function and I call >it like this: > >stock($Sym); > >I am wondering if I am doing it the wrong way. So I need to better >understand classes. What is one, and why would you use it?
You can safely ignore classes for the rest of your PHP coding life. :-)
Classes are *MOST* useful when:
Multiple programmers are building a large application, and you want to force some structure into that insanity.
You are creating a "library" to distribute, and you want to minimize the number of functions/variables that might conflict with other people's source code.
You are modeling real-world objects with specific behaviours in your code.
The way you are doing it is *FINE*.
If you wanted to give away your stock() functions to everybody else, you might want to create a class:
create class chris_cranes_stock_functions{ function stock($sym = 'ZEND'){ . . . } }
Then, if the guy who uses your code already *HAS* a 'stock' function, yours won't be in the way, because you've buried it inside your class.
But it's probably not going to magically increase the readability or reliability of your code to just start throwing class objects in there for the fun of it.
Your current usage of include/function is perfectly fine.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Hi, > I have an array of elements which are separated with the operator >comma(,). > >================================================== > $array = implode(",", $checkb); > > echo $array.'\n'; > > $result = mysql_query("DELETE FROM temp WHERE inv_tag IN >($array)") or die('Error in query'.mysql_error()); >==================================================== > > >PTX526_P_1,SIM_1 > >Error in query Unknown column 'PTX526_P_1' in 'where clause'.
Do this:
$query = "DELETE FROM temp WHERE inv_tag IN ($array)"; echo $query."<BR>\n"; $result = mysql_query($query) ...
What's happening is that you are telling MySQL this:
delete from temp where inv_tag in (PTX526_P_1,SIM_1)
Since there are no apostrophes on PTX526_P_1, MySQL figures they must be COLUMN names.
You need it to look like this:
delete from temp where inv_tag in (PTX526_P_1,SIM_1)
which means you need:
$array = implode("','", $checkb);
and then:
$query = "DELETE FROM temp WHERE inv_tag IN ('$array')";
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I was looking at using the LIMIT feature in MySQL, but the MySQL manual said >that if you use ORDER BY with LIMIT in the same SELECT it does the LIMIT >before the ORDER BY. Therefore it does the limit then orders the limit list >only, not order the entire list then returns the limit from that. Is this >true?
In my experience, it does the ORDER BY and then the LIMIT.
Or, at least, that's what comes out of the browser.
They *MIGHT* be doing something so that after they find the first 10 records (or whatever your LIMIT is) they *QUIT* sorting all the others, since there's not much point to sorting records you ain't gonna be getting anyway, is there?
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I have an interesting question. I am working on a system that I need to >run two commands in the shell, but when I use passthru() on the first >command then run the second command to get the results from the first >command, it doesn't work. Is there any way I can run 2 shell commands in >the same execution space so that I can get the results from the first >becaus eI think it is running them separately so when I try to pull the >results, it has no results to pull. Does this make sense? any >suggestions?
First suggestion:
passthru($command1 | $command2);
Second suggestion: Use named pipes.
Third suggestion: Use exec() and get the results from the shell, then pass them back out to the second command.
Fourth suggestion: Write a shell script that does both commands in one, with suitable arguments for your needs.
Fifth suggestion: Re-read http://php.net/passthru
:-)
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I am trying to do a simple fopen("http://www.weather.com/index.html", "r"); >For some reason I cannot Open any URL's after trying several. > >I get the following error > >Warning: stat failed for Resource id #1 (errno=2 - No such file or >directory)
It's possible that weather.com is sending cookies and refusing access if you aren't logged in or something...
To be sure, SSH (telnet) in to your server, or open an MS-DOS shell, and do this from a command prompt:
telnet www.weather.com 80 GET /index.htm HTTP/1.0 host: www.weather.com
Hit 'return' twice after that last line, and be ready for a lot of crap to come out. Or not. Whatever you see there is what PHP is seeing, almost for sure.
I think cURL might be the easiest way around that, though I hate to put cURL and easy in the same sentence.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>does anyone have a copy of the electronic version (free, i believe?) of >the book "PHP Functions Essential Reference" ? >the website http://www.php-er.com has been down and i am trying to >locate it...
http://php.net ? :-)
Given the price of the book, just buy a paper copy :-)
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Re: Good instruction for installing webserver using RPM and tar.gz files???
Don't. :-)
>I'm pretty used to installing OpenSSL, Mod_SSL, Mcrypt, cURL, PHP and Apache >with all of them in tar.gz files. Now I'm experiementing it on the Linux >and mySQL. Never tried it on both Linux and mySQL before.
Jeez, if you can get the SSL crap to install properly from tar.gz, why mess with RPM for PHP and MySQL?! :-)
The problem with most PHP RPM installs is that you are stuck with the versions of the 108 third-party software that the RPM-maker may or may not have decided to include, and what they decided to include only has a 1 in 2^108 (about a zillion) odds in being what you actually *WANT* in your PHP.
Of course, you can muck with source RPMs which is even worse that tarball in the first place...
But ain't nothing more painful than trying to figure out which of the 10,000 mysql-devel RPMs you need to match the RPM of mysql that's been on your machine from the RedHat installer. Hours down the tube.
>The tricky part I found is that some come in RPM. I am familar with >installing using RPM. But from my understanding, I would have to uninstall >the existing RPM software. The tricky part is to knit together RPMs and >tar.gz(s) for those software because they all depend on each other. For >example in order of installation .... > > 1) IBM DB2 (or mySQL) > 2) Mcrypt > 3) OpenSSL > 2) cURL --> (depend on OpenSSL) > 3) Mod_SSL --> (it depend on OpenSSL) > 4) PHP --> (depend on Mod_SSL, cURL, OpenSSL, Mcrypt & DB2) > 5) Apache --> 5th (it depend on Mod_SSL, OpenSSL, PHP) > >So, anyone know of good instruction on the website somewhere? It does not >have to be a complete instruction or a perfect instruction. Just something >that can give me some understanding before I start working it. Or should I >just use all tar.gz files instead? Like forget about the RPM stuffs. The >reason I'm posting this is becuase I realize that PHP can easily not work >with some softwares if it is not installed correctly. You know!
Here's the thing:
You *NEVER* now where some RPM maker decided to put their files. They might be in /usr/include or they might be in /usr/local/include or they might be in /etc or the might be in /usr/local/lib or...
The list is endless.
Basically, you're *BEST* bet is to try to avoid using the RPMs for stuff you expect to update any time soon (like, for the life of the machine) and use tarballs for that.
If the RPMs are already install, try to uninstall them (after doing a backup, of course) then install from tarball.
Even if it gets all screwed up, it's not *that* hard to figure out, usually.
For example, if GD isn't working, look for *TWO* copies of libgd.so on your box:
locate libgd.so
Or even just *TWO* copies of the header files:
locate gd.h
If there's a copy both in /usr/include and /usr/local/include, one of them ain't supposed to be there. Figure out which one by comparing it to the one you compiled a couple minutes ago. Nuke the wrong one, along with all the files that came with it. Be careful not to nuke other files that *happen* to start with 'gd' (like 'gdbm.h') but be sure to get all the ones that conflict with the .h files in your current GD. (like 'gdfont.h')
Detoxifying an RPM-ed install can be very rewarding and satisfying :-)
YMMV
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I have been looking around in the PHP function listing for a function that >can find or match one character from a string. I thought it would be >something like post_str() or something but never found anything close to >that. I get the idea of post and str from the SQL command. I did check the >ereg() but it is so confusing, no clear instruction on it. > >--clip-- > $str = ""; > $str = "X"; > $str = "XY" > $str = "Y"; > $str = "YX"; >--clip-- > >Those same variables from above, I only need to know if hte "X" exist in the >string, nothing else.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I'm currently developing a site which needs the ability to do server-side >image cropping and resizing. I currently have a current version of GD >installed with PHP, however the lack of support for GIFs is causing endless >headaches. > >Is there any way to support GIFs in PHP without reverting to an older >version of GD (and loosing PNG support in the process)?
In the strictest sense of your question, "No." :-)
However, if you want to save on your aspirin costs, just install ImageMagik and use http://php.net/exec or even a simple cron job directly to ImageMagik's 'convert' command to do all your cropping and scaling.
Actually, I've heard rumors of a third-party site that takes the current gd and modifies it to support GIF again, but they are shrouded in the same mists as those salvage yards that repair space-ships in bad Sci-Fi novels... :-) Solid leads to correct this deficiency in my knowledge are most welcome.
As much as I respect Boutell's decision and rationale, there's just too many damn GIFs out there I have to deal with and exec/ImageMagik is not that attractive sometimes...
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>$returndata=exec($cmd);
Change this to:
exec($cmd, $returndata, $error); echo implode("<BR>\n", $returndata); if ($error){ echo "OS Error $error. Usually path/permissions. Read 'man errno' to look up $error<BR>\n"; }
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>If I have say 20 web servers in a cluster behind something like a Cisco >LocalDirector, will session data remain constant over the 20 web servers if >they use a shared NFS or similar mount to save session data on?
Almost for sure, yeah, but NFS is probably not the best answer, unless you know how to make NFS better than all the geeks I know who roll their eyes at it. Hey, I've never even *seen* NFS, as far as I know, so it's all the same to me...
Assuming you are already opening an SQL connection on most pages that need sessions anyway, just stuff your session data into a single SQL back-end database.
http://php.net/session_set_handler
has sample code for MySQL last time I looked, but porting that to any SQL should be a five-minute + 1-hour testing job.
Oh yeah: The session_write happends *AFTER* the browser connection is long dead. Write yourself a little error_handler and *LOG* all the boo-boos instead.
http://php.net/set_error_handler
Even if you're *NOT* using SQL, it still might beat out NFS for performance/reliability/scalability. You'll have to test on our hardware/OS to be sure.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>We've installed and recompiled PHP but I still get "undefined function" >errors when I try to use imap_open(). > >Does anybody have any ideas?
Does <?php phpinfo();?> show IMAP support as being there?
Probably not.
Even if you *think* you have --with-imap in your configure line, what does phpinfo() show?
Did you spell it right?
Did you watch the output from ./configure carefully as the IMAP stuff went scrolling by?
./configure tends to "break" and not include stuff, but chugs right on by and compiles PHP without it.
I've been using:
./config.mine 2>&1 > configure.output &
lately.
Then I can use tail -f or less to view the output and not lose all the info I need.
config.log doesn't bother to log the answers (Yes/No) to the various searches, since those go to stderr, I guess... I dunno, really. I just know that I can't read config.cache like the experts do, but I can almost handle the configure.output I make most of the time :-)
confige.mine just looks like:
./configure \ --with-apxs=/path/to/my/apxs \ --with-mysql=/usr/local \ . . .
Don't put a \ on the last line.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Hello, > >I'm trying to explode an associative array element in $HTTP_POST_VARS >retrieved from submitting am html form. The URL to the form is: >http://www.funfry.com/form.html > >Now when I try to explode $HTTP_POST_VARS["domains"] it doesn't seem to have >the desired effect. I use the syntax "$site = explode(" >",$HTTP_POST_VARS["domains"]);" and instead of the expected result of: > >$site[0] = "www.php.net"; >$site[1] = "www.jokaroo.com"; >$site[2] = "www.gnu.org"; > >I get: $site[0] = "www.php.net www.jokaroo.com www.gnu.org"; > >The value of $HTTP_POST_VARS["domains"] after submitting the form is >"www.php.net www.jokaroo.com www.gnu.org". Does anyone have an idea of how >I can get each domain in a seperate array index?
var_dump($HTTP_POST_VARS['domains']);
I *suspect* that you actually have:
<INPUT NAME=domains[] VALUE=www.php.net> <INPUT NAME=domains[] VALUE=www.jokaroo.com> <INPUT NAME=domains[] VALUE=www.gnu.org>
If so, then $HTTP_POST_VARS['domains'] is an *ARRAY* already, and doing an explode on it is just silly.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Some careful testing and results...
I know nothing about Jigsaw, whatever that is.
>All tests invoke the URL "http://myserver:jigsawport/phpinfo.php" > >Test 1: >* phpinfo.php contains exactly one line ><?php phpinfo();?> > >* Jigsaw's debug flag in the default extension indexer cgiframe definition >for ".php" files is "true". > >The browser shows a white page with the text: >X-Powered-By: PHP/4.2.1 >Content-type: text/html > >Invoking the "view->source" menu path launches a notepad session showing >exactly the same text as the browser with NO html tags.
PHP *IS* being invoked, and *IS* starting to send its output to the browser.
PHP *might* be mis-configured somehow so that a blank line is getting sent before its header output, or
Jigsaw might be adding a blank line before PHP's output, but
*SOMETHING* is forcing a blank line into the HTTP stream that comes to the browser *before* those headers arrive.
That's just wrong.
Can you completely remove jigsaw from the equation? Not just setting some flag to true/false, but be 100% sure jigsaw isn't even running?
>Test 2. >* phpinfo.php contains exactly one line ><?php phpinfo();?> > >* Jigsaw's debug flag is "false". > >The browser shows an empty white page. > >Invoking the "view->source" menu path launches a notepad session showing the >following: ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ><HTML><HEAD> ><META http-equiv=Content-Type content="text/html; >charset=windows-1252"></HEAD> ><BODY></BODY></HTML>
Okay, then we know for sure that jigsaw "true" is messing up your headers. Possibly with an ERROR message and a blank line. The browser swallows the error message as a header, and then display's PHP's output headers as if it were content.
Can you run jigsaw from the MS-DOS prompt or command line or whatever, feeding it the same PHP URL somehow?
>Test 3. >* phpinfo.php now contains some trivial container html. ><html> ><head><title>phpinfo page</title></head> ><body> >phpinfo follows... ><?php phpinfo();?> ></body> ></html> > >* Jigsaw's debug flag is "false". > >The browser shows an empty white page. > >Invoking the "view->source" menu path launches a notepad session showing the >following: ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ><HTML><HEAD> ><META http-equiv=Content-Type content="text/html; >charset=windows-1252"></HEAD> ><BODY></BODY></HTML>
Well, yes, this isn't PHP's output, almost for sure. I dunno who or what is sending this junk out, but it's probably not PHP.
>The DOS prompt running Jigsaw has the process name "JAVA" until the php page >is invoked. At this time it is renamed to php and stays that way. The >Jigsaw server, however, does still respond to JigAdmin commands and can be >stopped correctly. > >Ummm????????
When php.exe fires up, apparently using the same MS-DOS shell as jigsaw, it renames the window title. That's normal. If you take Jigsaw out of the picture, and manage to watch the MS-DOS window that runs PHP fire up and then quite (minimize your browser and hit 'reload') then you'd see that happen, maybe... Make PHP do a <?php sleep(10);?> and you'll have 10 seconds to read it. :-)
If you can get rid of Jigsaw and make sure PHP works without it, you can pretty safely assume it's Jigsaw that is messing up, somehow.
If you can "feed" Jigsaw the same output PHP sends it, and see what it does without a browser getting in the way, you'll probably see an error message that tells you something useful. Well, "useful" here is relative :-)
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I had made a test.txt file which stored in the following window path : >c:\pdf_reports\dealing\test.txt, >In my page, i ask php to check the test.txt exist in foler >(c:\pdf_reports\dealing) using the following script: > >if (file_exists("c:\\pdf_reports\\dealing\\test.txt")) > { > print ("exist"); > } >else > { > print ("Doesn't Exist!"); > } > >It seems that php can't detect the file in such path!!! >I had made another test on this, i moved the test.txt to one level up which >is (c:\pdf_reports) and i use the following script : > >if (file_exists("c:\\pdf_reports\\test.txt")) > { > print ("exist"); > } >else > { > print ("Doesn't Exist!"); > } >Then it can detect the file is there! why?
What are the exact error messages you get when it's "not there"?
Which version of Windoze? Is it one of the ones where you actually have some kind of control over user priveleges on reading/writing directories and files? What permissions are on 'dealing'?
Is 'dealing' really 'dealing' or is it 'Dealing', or maybe 'DEALING' or even 'DeAlInG'? :-) I don't think PHP can force Windows to be case-sensitive, but...
Also try it with just c:/pdf_reports/dealing/test.txt All those \\ and Windoze crap is ugly anyway. :-)
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>This is my problem: >I want include the file html.html inside of my file index.php, but before >include it I want to remove <html>..</head> tags from my html.html file.
<?php $html = file('html.html'); $found = 0; while (list(,$line) = each($html)){ if ($found){ echo $line; } else{ if ($rest = stristr($line, '</head>')){ $rest = substr($rest, 7); echo $rest; $found = 1; } } } ?>
Although, honestly, this is just WRONG design.
Put your <HTML>...</HEAD> into *another* file, and either include it or don't, depending on which way you want it.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>why the images won't display. Any ideas would be helpful and I can post more >code if required.
You're going to have to post all of it, almost for sure...
I'm not seeing a missing " in there, but you surely have one.
Or get an editor that understands PHP and JavaScript that will color-code it all for you.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>The last statement does not generate an error but lets you >access that location...
That's because C is broken :-)
>Firstly I want to know if PHP has pointers
PHP does not have a 'pointer' type. Read the manual.
>(I know it uses >dereferencing values via &) and if it does use pointers >does it let you do stuff like this (or does its nature not >let you interact with the lower level hardware components?
It doesn't let you do that, and that has nothing to do with lower level hardware components. You're still about 4 or 5 layers away from hardware at that point...
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Hello All, > >I, having problems getting HTTP_SESSION_VARS to work the way I think they >should. >Shouldn't I just be able to do something like: > >in a file called index.php I have the following; > ><?php >session_start(); >?> ><html> ><head></head> ><body> >The session_id is <?php echo "\"".session_id()."\""; ?> > ><a href="index2.php">Next</a> ><?php >$HTTP_SESSION_VARS['count']=123;
Don't stuff things directly into that array. Bad Idea (tm).
Use:
session_register('count'); $count = 123;
>?> ></body> ></html> > >In index2.php I then have ><?php >session_start(); >?> ><html> ><head></head> ><body> >The session_id is <?php echo "\"".session_id()."\""; ?> ><?php >echo "\$HTTP_SESSION_VARS['count']=".$HTTP_SESSION_VARS['count'].".<BR>"; >?> ></body> ></html> > >Now when I go to the first one all is great and the session id is shown. But >when I click on the "Next" link I get the next page with the same session id >shown (all well and good) but no value in $HTTP_SESSION_VARS['count']!!! > >Where am I going wrong?
Newer versions of PHP use $_SESSION not $HTTP_SESSION_VARS.
In *ANY* case, the documented procedure is to use:
session_register('count'); $count = /* whatever you want here */;
Stuffing junk into PHP's internal arrays that PHP *happens* to be using this week to force session variables to spring into existence or altering their values directly in that internal array is just *wrong*, no matter how many 'experts' you see doing it.
Use the documented session_register() function.
http://php.net/session_register
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I'm trying to connect to a server using ldap_connect. The connection is >failing, but I'm not sure why. When I try to use ldap_error() to narrow >down the problem, I get a messaging saying "... 0 is not a LDAP link >index at ...." I'm not sure what other options I have. Any suggestions >would be apprecieated.
ldap_error() tells PHP to use the LDAP connection to talk to the LDAP server to ask it what went wrong.
You never got a connection in the first place, so it's a bit of a chicken and egg problem...
If you turn on track_errors, you *MIGHT* find something useful in $php_errormsg (?)
What message do you get from the connection failure, if any?
Can you use any other tools on the same computer to connect to LDAP?
Can PHP connect to some other publid LDAP server somewhere as a test case?
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>when i try to connect to my local imap server by php i get the message >(standard ie message) that the page can't be shown. with another server >(imap.web.de) everything works fine. with outlook i can access my server >without any problems and also mtest seems to work without any errors. what's >wrong. would be nice if anybody could help me.
Does it take awhile on the other browsers?
IE is very impatient sometimes, and will "time out" while waiting, while the others will sit there longer and eventually give you the answer.
About all you can do is make your application faster, or fool IE into waiting. :-)
If you can connect to IMAP asynchronously, you can keep sending a space to IE while you're waiting, and call http://php.net/flush so that the spaces out out to the browser.
If this all has to happen before some headers go out, you *might* be able to do:
<?php header("Microsoft: sucks"); flush(); ?>
and fool IE that way into keeping the connection open...
But I'm not sure PHP won't cache the headers and ignore your flush() at that point anyway...
If the other browsers are all responding quickly, then you've got some other problem with IE, which is no surprise. It's got lots of problems :-)
What exactly is coming to IE in the way of headers and content?
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I am getting data froma website for stock information. If I type in the >brower the URL I get a text file display list this; > >Date,Open,High,Low,Close,Volume >16-Jul-02,7.92,8.10,7.68,7.82,605500 >15-Jul-02,7.98,8.02,7.59,8.02,577200 >12-Jul-02,7.80,8.00,7.57,7.95,411100 >11-Jul-02,7.82,7.94,7.34,7.80,802400 > >Now I want to break each line and then seperate each line by the commas. The >amount of linesin the file is never known so I assume I have to use >something like a foreach or while statement,but I am not sure the best way >to do it. This is what I have so far. > > $Symbol = "IKN"; $LookupUrl = >"http://demos.inxdesign.com/download?sym=$Symbol&format=.txt"; $Results = >implode('', file("$LookupUrl")); > $Data = array(); split("\n", $Results) = array_push($Data, $line)
file() is already *GIVING* you an array of each line.
You simple need to look at each one and separate by commas.
$data = file($LookupUrl); while(list(,$line) = each($data)){ $values = explode(',', $line); var_dump($values); }
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>When running a mysql_query, sometimes i need to have apostrophes >surrounding variables...other times i don't > >example... > >$query = "SELECT * FROM table WHERE id='$id'"; > >or > >$query = "SELECT * FROM table WHERE id=$id"; > >...it kinda seems random when it wants apostrophes and when it doesn't >want them.
You do not need apostrophes on INTEGER and FLOAT data.
Everything else needs them.
In fact, other SQL engines will complain if you put apostrophes on the numeric data.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Now that I have a string of colors delimited by commas, I would like to >parse the string and print out all my colors. I have read the >documentation on using the list() function but I find it confusing. Can >someone clear the fog from my mind please?
Remember when "deconstructionism" was a hot topic in university circles? They would have loved the list() construct. :-)
list() is basically just an array de-constructor:
<?php $array = array('a', 'b', 'c'); list($a, $b, $c) = $array; echo 'a is $a, b is $b, c is $c<BR>\n"; ?>
In other words, list tears apart an array and gets the values out, stuffs the values into the variables you provide, and throws away the keys (aka indices) from the array.
list() is most commonly used with each() and with mysql_fetch_row (and similar).
Now, each() can be a bit confusing, since it tears through an array, building tiny little arrays of the key/value in it as it goes. Let's watch this in "slow-motion":
<?php $array = array('a', 'b', 'c'); echo "array is "; var_dump($array); echo "<BR>\n<BR>\n"; while ($element = each($array)){ echo "A single key/value pair in array gets converted by 'each()' into: "; var_dump($element); echo "<BR>\n<BR>\n"; echo "Note that it is the each() that builds up this somewhat odd array for list to deconstruct.<BR>\n<BR>\n"; echo "Then list(\$key, \$value) = \$element gives you: "; list($key, $value) = $element; echo "$key, $value<BR>\n"; } ?>
Normally, of course, you just do:
<?php $array = array('a', 'b', 'c'); while (list($key, $value) = each($array)){ echo "$key, $value<BR>\n"; } ?>
Now, when you use mysql_fetch_row(), which returns an array, the list() construct is just tearing that apart into its values: <?php $query = "select * from mytable"; # NEVER use select * in *REAL* code! $data = mysql_query($query) or error_log(mysql_error()); while (list($one, $two, $three) = mysql_fetch_row($data)){ echo "The first three columns are $one, $two, $three<BR>\n"; } ?>
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I am wondering how many requests at one time php can serve before the site >brakes down. Someone told me that my site has been down yesterday for a >while after I did anounce it through a university email list going to 2500 >users.
There are many factors that will cause what you think happened...
Usually, PHP is not the deciding factor...
It's more likely that your web server (Apache, most likely) didn't have enough "children" to service everybody in this burst period of time.
Google for "Apache and ab and burst traffic"
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I am getting random Segmentation faults when I use >the following script. This does not happen when I run >scripts that do not include the xslt_process() >So I am assuming it has something to do with Sablotron and xslt. >Below is also the back trace with the problem. >Can anyone suggest a solution or next step?
Usually with these sorts of things, the first thing to check is that the version of PHP and xslt and Sablotron are all matching up.
Check the output of <?php phpinfo();?> with the actual version of Sablotron you are running and have installed... That is, assuming Sablotron is some kind of outside process or library DSO extension installed into Un*x.
Next, you search http://bugs.php.net and the mailing list archives for your same error.
After that, you post your error to http://bugs.php.net and pray the PHP/Sablotron developer[s] find it interesting, challenging, or important enough to dig into.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>The problem comes when fields in the html pages are left empty, which is >normal for this application. For those familiar with the ldap_add/modify >functions in PHP, the array that is passed in has some values, say for >example title, fax, mobile, ... left empty, and therefore NULL (I have >checked, they really are NULL's stored in the array). When the values make >it to the ldap server however, they appear to be no longer NULL's, but a >"#0", and through debugging output on the ldap server, I have seen it is >generating an "invalid per syntax" error.
FORMs with INPUT TYPE=TEXT should be generating values of '', not NULL.
Or, at least, they always did before...
In the short term, you could probably alter any NULL value to '' before shoving it into LDAP, and LDAP will probably like '' much better than NULL.
#0 is basically just LDAP's way to represent NULL, most likely.
> $info["mail"]=""; // <----- NULL VALUE HERE > // The following lines also produce the same result....... > //$info["mail"]=NULL; // <------- NULL value here > //$info["mail"]="\0"; // <------- NULL value here > //$info["mail"]; // <------- NULL value here
Whoa!
Never mind.
Something is very broken in the LDAP stuff if '' and NULL from PHP are being turned into NULL in LDAP, and then LDAP complains about it...
Start looking at http://bugs.php.net
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Hello, I have captured variables from any HTML that is POSTed to me from a >'foreach' clause. Now, possibly in this foreach clause I want to register >these name/value pairs into a session var. I have tried : >session_start(); >foreach ($HTTP_POST_VARS as $name=>$value) { >$name=$value; >session_register(name); //without the $ >} >and get nothing.
That's because you are registering 'name', which is to say $name, rather that whatever is *inside* of $name...
Okay, the docs *DO* point out that you need to use the name of the variable for session_register, not the varible itself, but $name *HOLDS* the name of your variable.
In other words, consider this:
<?php $name = 'foo'; $foo = 42; session_register('foo'); #RIGHT session_register($foo); #WRONG session_register($name); #RIGHT, same as session_register('foo') since $name == 'foo' session_register('name'); #WRONG, that's registering $name, not $foo ?>
Hope that makes sense.
Oh, and use error_reporting(E_ALL) to crank up your warning messages. You'll end up writing better code because of it.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I am planning to setup a web server of using RedHat Linux. The purpose >of the web server is to provide product information for only registered >customers. >I plan to send the HASP parallel port keylock to the registered >customers. >Can I use PHP to monitor the status HASP parallel port keylock in the >client side? >Is there any idea for ensuring the website piracy?
I have no idea what HASP is, but I'm almost 100% certain PHP can't tell if a client has some stupid doohickey plugged into their parallel port or not.
It would be a major invasion of privacy if PHP *could* do that -- Since I could then determine if you have an old HP DeskJet or a $10,000 printer, and decide to rob you or not. That would be bad.
There are many, many, many things you need to understand about web security, and even just how secure you need your content to be -- Fort Knox secure, bank branch secure, ATM secure, dime-store secure, or petty cash in the secretary's drawer secure?
Only you can answer that one.
You can get Fort Know security, but it will be outrageously expensive, consume inordinate amounts of resources, and will take you a *LOOOOOONNNNNGGGGGG* time to figure out how to do it right, or you'll have to hire an expert for a lot of money.
Similarly, each of the security models you *COULD* implement have corresponding costs/benefits for both up-front and maintenance.
Things you can start reading about include:
SSL, HTTPS, and Certificates HTTP Authentication http://php.net/readfile
If you just want to stop the majority of hackers from reading material without paying first, then you would probably be best off going with a standard shopping cart.
http://l-i-e.com/compare/ lists several with "Votes" on a feature-by-feature comparison. Quite possibly the ugliest interface on Earth, but I was in a hurry. And some people actually like that crammed compact look. Oh well.
But if you've got highly-sensitive CIA information in there or something, you'll want to do a whole lot more research.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>I have a simple script that attempts to upload a file and save it on the >server. When I click send file I get this error message 'Warning: Unable to >open '' for reading: No such file or directory in /var/www/html/upload.php >on line 5 >Couldn't copy the file!'. The file is being uploaded from a Win 2000 machine >and the php script live on an apache web server on a linux box. I have chmod >777 the 'image' directory. Any ideas? >Here's the code - > > -- upload.html -- ><html> ><head> ><title>Upload a File</title> ></head> > ><body> > ><h1>Upload a File</h1> > ><form enctype="multipart/form-data" method="post" action="upload.php"> > ><p><strong>File to Upload:</strong><br> ><input type="file" name="img1" size="30"></p> > ><P><input type="submit" name="submit" value="Upload File"></p> > ></form> ></body> > ></html> > > -- upload.php -- ><?php > >if ('img1' != "") {
This is kinda silly as it stands... 'img1' will *NEVER* be ''. You want $img1
> copy($img1_tmp_name, "images/".$img1_name)
Here, you are trying to copy the wrong filename: $img1 *IS* the file's name on your web-server. $img1_name is what it used to be called on the surfer's desktop computer. $img1_tmp_name ain't nothing.
Which is why you get an error message about '' not being able to be copied.
Also, use http://move_uploaded_file instead of copy() because it's *MUCH* better security. It makes sure that they haven't somehow fooled you into copying some other file from somewhere else that isn't the one they uploaded. It does not, however, make sure that the contents of the file are "safe" in any way.
That's up to you.
For images, http://php.net/getimagesize is quite handy, because a valid image will tell you what it is and what size it is, and an invalid one won't.
> or die("Couldn't copy the file!"); > >} else { > > die("No input file specified"); >} > >?>
The upload can also fail and send 'none' for $img1, rather than just ''.
I forget which way is which, but one of them ('none' versus '') means they tried to upload a file but it didn't make it, and the other means they didn't even choose a file at all.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Can i access my paralel or USB port with PHP server side?
The client's (browser's) parallel or USB port? No. See PHP & HASP thread.
If the web-server has a parallel or USB port and you want to access that, probably, if you have (or can get) sufficient permissions from the OS for PHP to do so.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
And what kind of permissions might that be? (server side)
"Richard Lynch" <rich
phpbootcamp.com> wrote in message
news:php.general-108404
news.php.net...
> >Can i access my paralel or USB port with PHP server side?
>
> The client's (browser's) parallel or USB port? No. See PHP & HASP
thread.
>
> If the web-server has a parallel or USB port and you want to access that,
> probably, if you have (or can get) sufficient permissions from the OS for
> PHP to do so.
>
> --
> Like Music? http://l-i-e.com/artists.htm
>
attached mail follows:
>I recently upgraded Apache to 1.3.26 and am currently configurating hte >httpd.conf. I noticed that > >--snip-- >AddType application/x-httpd-php .php >AddType application/x-httpd-php-source .phps >--snip-- > >does not exist in this version as it does in the older version. > >Is it now automatic with the newer version??
No.
Those lines or something like them have to be in there somewhere, or in a file that Apache sucks in to httpd.conf for PHP to work.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Can we reboot a linux server using a php page?
Under certain conditions, probably.
You could run Apache as root, but that's stupid.
Instead, you'd need a sudo script that does shutdown without requiring a user to actually *BE* root.
That script should almost-for-sure be owned and executable by a single special user named 'shutdown' or something like that. If you make it nobody executable, anybody who can log in can shut down your server, and that's probably not acceptable. But might be, depending on extreme circumstances.
Next, you'd want to add a different mime-type and extension to Apache and run PHP as a CGI process owned by the user 'shutdown' via suExec (or move to Apache 2.0 [not recommended] and its ability to run PHP as a specific user on a directory-by-directory basis). You can find docs on suExec at http://apache.org/
Then, create your PHP script owned by that 'shutdown' user with something not unlike: <?php exec('shutdown -r now', $results, $error); echo implode("<BR>\n", $results; if ($error){ echo "OS Error: $error. Usually path/permissions, but read 'man errno' to be sure.<BR>\n"; } ?>
I would put this in a separate directory (password-protected, of course) and add some code at the top of the PHP above to be sure it was accessed only via SSL (search the archives).
Also save it with a different extension than just plain old .php, such as .phpshutdown
And, of course, you'll need to use that extension and a different mime-type in your AddType line in httpd.conf for the suExec CGI PHP, as well as the Action directive in httpd.conf to use the suExec you set up.
Note that this will not interfere in the least with your existing PHP Module already running -- As far as Apache is concerned, they have nothing to do with each other.
>And is it recommended?
If you have to ask, probably not :-)
If you understand HTTPS and choose a good username/password and are careful about not writing it down, and so on and so on, I suppose it would be okay...
If you don't really understand what I typed above, you are doing something very very risky, and you probably shouldn't do it at all. Hire somebody who knows what they are doing to do it instead.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
On Friday 19 July 2002 04:26, Scott Fletcher wrote: > If you're going to use the cron file (or crontab) then php wouldn't work > because it is a programming languages for the web pages. For cron files or > crontab, you can use the bash shell or ksh or whatever you have. It's > simple. All you had to do is to create a file on hte Unix/Linux machine > and do the following ...
John's reply was meant to show that it is a very bad idea to allow someone reboot the server from a webpage (without the proper safeguards). If he had URL he could setup a cron job which would reboot the OP's computer every minute and that _wouldn't_ be fun.
-- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development */* The Public is merely a multiplied "me." -- Mark Twain */
attached mail follows:
>On Friday 19 July 2002 04:26, Scott Fletcher wrote: >> If you're going to use the cron file (or crontab) then php wouldn't work >> because it is a programming languages for the web pages. For cron files or
[Perhaps there was even more text missing that made this all out of context... Sorry.]
I missed other parts of this thread, but I have to say Bull$#!^ to the idea that you need to use some language other than PHP for your cron jobs and/or shell scripting.
I routinely use PHP for *all* my shell/cron scripts.
It saves me hours of time, what little hair I have left, and the aspirin I'd have to down if I was using Perl or some shell script language.
Sure, if it's a one-line cron job to a shell command, I'll use the command directly. If I have to think about it any more than that -- with a loop or any db access or anything remotely complicated, it's PHP.
If you already know Perl or shell scripting, knock yourself out.
If you don't save yourself a lot of pain and suffering and just ./configure PHP as a CGI (or CLI now) and use #!/usr/bin/php -q
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>What's the best way to check for an Associative Array? There is no >is_assoc() or similiar function listed in the manual (I don't think anyway).
All arrays are associative, really. Just some happen to have integers as their keys in the association.
>I'm using mysql_fetch_array() and I want to foreach only the assoc. part of >the array without using mysql_fetch_assoc():
So use that extra argument to mysql_fetch_array and tell it you only want the MYSQL_ASSOC ones, not MYSQL_BOTH.
http://php.net/mysql_fetch_array
>foreach ($arr as $key=>$value) { > echo "$key:$value"; >} > >But of course it show both the indexed array and the assoc array contents. >Is there an existing function to check this, or should I do one of these >things inside the foreach loop: > >A) set $last=value and just check if $value = $lastval > >B) check if the $key is just a number or just a string > >C) $key += 1
It's wrong, but if you want to do it that way, you could use:
maybe.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
>Is there a way I can decide where to target my output from server side?
No.
The FRAME asks the web-server for some content, and the server delivers it.
You could, I suppose, tag every line of content with which frame it belongs in, and then have JavaScript on FRAME A, shove it over to FRAME B.
That would be sick and twisted, and break on too many browsers.
>suppose my page has two iframes > >+---++---+ >! A !! b ! >+---++---+ > >while executing a script that is called by A can I spawn another script >that will output to "b"? And no, I cant' use any Jscript, but I do know >from server side what my target names are (A and b, that is).
Oh, well if you can't use JavaScript, you can't do it...
But you can maybe achieve the same *EFFECT* like this:
<HTML> <HEAD><TITLE>Main Page</TITLE></HEAD> <BODY> <FRAMESET ...> <FRAME NAME=A SRC=a.php?<?=$QUERY_STRING?> ...> <FRAME NAME=B SRC=b.php?<?=$QUERY_STRING?> ...> </FRAMESET> </BODY> </HTML>
----------- a.php ----------------- <A HREF=whatever.php TARGET="_parent"> -----------------------------------
Similarly in b.php
The point being that by forcing every link and FORM to go *back* through the "main" page, and then down into the two sub-frames, you can keep them in sync with each other.
Disclaimer: If an iframe is somehow magically different from a plain old FRAME (they all suck, so I don't pay attention to them) then I might be wrong.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
I am new to PHP and MySQL and never have experience in this area. I am writing a PHP script that connects to MySQL server. I have to put a password of MySQL into the PHP script. I think it may not be secured. What do you think? How can I make it more secure? Thanks.
attached mail follows:
It's fine. There's no other way to do it really. Somebody would have to be able to see the source to the php file before they could see the password for mysql. They won't get it just by viewing the webpage that's already been parsed by php.
-- Tyler Longren Captain Jack Communications tylercaptainjack.com www.captainjack.com
On Fri, 19 Jul 2002 10:03:02 +0700 "Sailom" <amorndet
colorado.edu> wrote:
> I am new to PHP and MySQL and never have experience in this area. I > am writing a PHP script that connects to MySQL server. I have to put > a password of MySQL into the PHP script. I think it may not be > secured. What do you think? How can I make it more secure? Thanks. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
Also, allow MySQL connections only from your server.
Tyler Longren <tyler
captainjack.com> wrote: It's fine. There's no other way to do it really. Somebody would have
to be able to see the source to the php file before they could see the
password for mysql. They won't get it just by viewing the webpage
that's already been parsed by php.
-- Tyler Longren Captain Jack Communications tylercaptainjack.com www.captainjack.com
On Fri, 19 Jul 2002 10:03:02 +0700 "Sailom" wrote:
> I am new to PHP and MySQL and never have experience in this area. I > am writing a PHP script that connects to MySQL server. I have to put > a password of MySQL into the PHP script. I think it may not be > secured. What do you think? How can I make it more secure? 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
--------------------------------- Do You Yahoo!? Yahoo! Autos - Get free new car price quotes
attached mail follows:
THANKS :)
attached mail follows:
Yes, good point Anas. Make sure that you have mysql set up right. Make sure the root mysql user has a password set and that people can't connect from "%".
tyler
On Thu, 18 Jul 2002 20:19:05 -0700 (PDT)
Anas Mughal <anasmughal
yahoo.com> wrote:
>
> Also, allow MySQL connections only from your server.
>
> Tyler Longren <tyler
captainjack.com> wrote: It's fine. There's no
> other way to do it really. Somebody would have
> to be able to see the source to the php file before they could see the
> password for mysql. They won't get it just by viewing the webpage
> that's already been parsed by php.
>
> --
> Tyler Longren
> Captain Jack Communications
> tyler
captainjack.com
> www.captainjack.com
>
>
>
> On Fri, 19 Jul 2002 10:03:02 +0700
> "Sailom" wrote:
>
> > I am new to PHP and MySQL and never have experience in this area. I
> > am writing a PHP script that connects to MySQL server. I have to put
> > a password of MySQL into the PHP script. I think it may not be
> > secured. What do you think? How can I make it more secure? 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
>
>
>
> ---------------------------------
> Do You Yahoo!?
> Yahoo! Autos - Get free new car price quotes
attached mail follows:
Yes, but if you're on a shared server, other users of the user will likely be able to read your PHP files & get the password.
> -----Original Message-----
> From: Tyler Longren [mailto:tyler
captainjack.com]
> Sent: Thursday, July 18, 2002 23:10 PM
> To: Sailom
> Cc: php-general
lists.php.net
> Subject: Re: [PHP] Password in script
>
>
> It's fine. There's no other way to do it really. Somebody would have
> to be able to see the source to the php file before they could see the
> password for mysql. They won't get it just by viewing the webpage
> that's already been parsed by php.
>
> --
> Tyler Longren
> Captain Jack Communications
> tyler
captainjack.com
> www.captainjack.com
>
>
>
> On Fri, 19 Jul 2002 10:03:02 +0700
> "Sailom" <amorndet
colorado.edu> wrote:
>
> > I am new to PHP and MySQL and never have experience in this area. I
> > am writing a PHP script that connects to MySQL server. I have to put
> > a password of MySQL into the PHP script. I think it may not be
> > secured. What do you think? How can I make it more secure? 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
>
>
attached mail follows:
I just checked grant and it said something like...
GRANT USAGE ON *.* TO 'XXXXX'
'%' IDENTIFIED BY .........
Does this means user named 'XXXXX' can log in from any server? This may be
a silly question.
"Jonathan Rosenberg" <jr
tabbysplace.org> wrote in message
news:NDBBLKBKIKFIPIFMDDNHCELHGFAA.jr
tabbysplace.org...
> Yes, but if you're on a shared server, other users of the user will likely
> be able to read your PHP files & get the password.
>
> > -----Original Message-----
> > From: Tyler Longren [mailto:tyler
captainjack.com]
> > Sent: Thursday, July 18, 2002 23:10 PM
> > To: Sailom
> > Cc: php-general
lists.php.net
> > Subject: Re: [PHP] Password in script
> >
> >
> > It's fine. There's no other way to do it really. Somebody would have
> > to be able to see the source to the php file before they could see the
> > password for mysql. They won't get it just by viewing the webpage
> > that's already been parsed by php.
> >
> > --
> > Tyler Longren
> > Captain Jack Communications
> > tyler
captainjack.com
> > www.captainjack.com
> >
> >
> >
> > On Fri, 19 Jul 2002 10:03:02 +0700
> > "Sailom" <amorndet
colorado.edu> wrote:
> >
> > > I am new to PHP and MySQL and never have experience in this area. I
> > > am writing a PHP script that connects to MySQL server. I have to put
> > > a password of MySQL into the PHP script. I think it may not be
> > > secured. What do you think? How can I make it more secure? 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
> >
> >
>
attached mail follows:
The password code will be parsed out by PHP, so, it won't be viewable in the HTML source delivered to the browser.
Some advice: set up a user for your database that has the minimal amount of access necessary to perform queries or writing to the database and use that in your scripts. Don't ever use your master MySQL username and password.
Monty
> From: amorndet
colorado.edu (Sailom)
> Newsgroups: php.general
> Date: Fri, 19 Jul 2002 10:03:02 +0700
> To: php-general
lists.php.net
> Subject: Password in script
>
> I am new to PHP and MySQL and never have experience in this area. I am
> writing a PHP script that connects to MySQL server. I have to put a
> password of MySQL into the PHP script. I think it may not be secured. What
> do you think? How can I make it more secure? Thanks.
>
>
attached mail follows:
Ok I am going to give out my little secret that was passed to me. Your worry is warranted in my opinion especially since let's say your isp is in the middle of an upgrade or something happens to php that breaks it.. Now your php code is being shown as regular text.. Anybody can see your code. There are a lot of things that could possibly go wrong.. Maybe an error happens and it shows where you have the error and it shows your username and password.. So many things.. So use an external file that is below your htdocs/www/public_html directory. I usually use a directory called phpinc/php_inc/php. Call it whatever you want :) and then put a file in it called say.. query.inc
query.inc <? function queryDB ($query) { $connect = mysql_pconnect('host', 'username', 'password'); $result = mysql_db_query('database',$query,$connect); if ($result) { return $result; } else { echo "<h1>Error in Query</h1>"; echo "Query: \"$query\"<br />"; echo mysql_errno($connect).": <font color=\"red\">".mysql_error($connect)."</font><br />"; exit; } } ?>
Include this file within any file that will be doing database queries. Then whenever you want to make a call to the database use this syntax:
$result = queryDB("YOUR SQL QUERY HERE");
Plus it will show you where you are getting your mysql errors when you have them. It's a great little function.. Thank you John Ash! :) Gotta give credit where it's due :)
I hope it helps!
Cheers!
Rick
He who is devoid of the power to forgive is devoid of the power to love. - Dr. Martin Luther King, Jr.
> From: "Sailom" <amorndet
colorado.edu>
> Date: Fri, 19 Jul 2002 11:33:59 +0700
> To: php-general
lists.php.net
> Subject: Re: [PHP] Password in script
>
> I just checked grant and it said something like...
> GRANT USAGE ON *.* TO 'XXXXX'
'%' IDENTIFIED BY .........
> Does this means user named 'XXXXX' can log in from any server? This may be
> a silly question.
>
>
> "Jonathan Rosenberg" <jr
tabbysplace.org> wrote in message
> news:NDBBLKBKIKFIPIFMDDNHCELHGFAA.jr
tabbysplace.org...
>> Yes, but if you're on a shared server, other users of the user will likely
>> be able to read your PHP files & get the password.
>>
>>> -----Original Message-----
>>> From: Tyler Longren [mailto:tyler
captainjack.com]
>>> Sent: Thursday, July 18, 2002 23:10 PM
>>> To: Sailom
>>> Cc: php-general
lists.php.net
>>> Subject: Re: [PHP] Password in script
>>>
>>>
>>> It's fine. There's no other way to do it really. Somebody would have
>>> to be able to see the source to the php file before they could see the
>>> password for mysql. They won't get it just by viewing the webpage
>>> that's already been parsed by php.
>>>
>>> --
>>> Tyler Longren
>>> Captain Jack Communications
>>> tyler
captainjack.com
>>> www.captainjack.com
>>>
>>>
>>>
>>> On Fri, 19 Jul 2002 10:03:02 +0700
>>> "Sailom" <amorndet
colorado.edu> wrote:
>>>
>>>> I am new to PHP and MySQL and never have experience in this area. I
>>>> am writing a PHP script that connects to MySQL server. I have to put
>>>> a password of MySQL into the PHP script. I think it may not be
>>>> secured. What do you think? How can I make it more secure? 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
>>>
>>>
>>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
attached mail follows:
Actually, there is Banother way and you should consider it.
Sensitive information like passwords should be kept in a file stored outside the live web content directory (ie, outside DocumentRoot on Apache). This file can then be included in your main file.
This way, you can be sure that a misconfigured Apache (accidentally or otherwise) will never send your php scripts out as plain text.
This doesn't solve the problem of other users on the same system snooping around your filesystem, though.
All the MySQL advice is good advice.
Michael
On Thu, 18 Jul 2002, Tyler Longren wrote:
> It's fine. There's no other way to do it really. Somebody would have > to be able to see the source to the php file before they could see the > password for mysql. They won't get it just by viewing the webpage > that's already been parsed by php. > >
attached mail follows:
The GRANT USAGE statement creates a user with no priveleges ... the user exists but can't do anything.
See MySQL Manual section 6.13
Michael
On Fri, 19 Jul 2002, Sailom wrote:
> I just checked grant and it said something like...
> GRANT USAGE ON *.* TO 'XXXXX'
'%' IDENTIFIED BY .........
> Does this means user named 'XXXXX' can log in from any server? This may be
> a silly question.
>
>
> "Jonathan Rosenberg" <jr
tabbysplace.org> wrote in message
> news:NDBBLKBKIKFIPIFMDDNHCELHGFAA.jr
tabbysplace.org...
> > Yes, but if you're on a shared server, other users of the user will likely
> > be able to read your PHP files & get the password.
> >
> > > -----Original Message-----
> > > From: Tyler Longren [mailto:tyler
captainjack.com]
> > > Sent: Thursday, July 18, 2002 23:10 PM
> > > To: Sailom
> > > Cc: php-general
lists.php.net
> > > Subject: Re: [PHP] Password in script
> > >
> > >
> > > It's fine. There's no other way to do it really. Somebody would have
> > > to be able to see the source to the php file before they could see the
> > > password for mysql. They won't get it just by viewing the webpage
> > > that's already been parsed by php.
> > >
> > > --
> > > Tyler Longren
> > > Captain Jack Communications
> > > tyler
captainjack.com
> > > www.captainjack.com
> > >
> > >
> > >
> > > On Fri, 19 Jul 2002 10:03:02 +0700
> > > "Sailom" <amorndet
colorado.edu> wrote:
> > >
> > > > I am new to PHP and MySQL and never have experience in this area. I
> > > > am writing a PHP script that connects to MySQL server. I have to put
> > > > a password of MySQL into the PHP script. I think it may not be
> > > > secured. What do you think? How can I make it more secure? 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
> > >
> > >
> >
>
>
>
>
-- -------------------------------- n i n t i . c o m php-python-perl-mysql-postgresql -------------------------------- Michael Hall nintininti.com --------------------------------
attached mail follows:
Hi all,
I've asked simular questions before, but I think I'm finally asking the *right* question to get the right answer.
I'm look for some suggestions on the best method of parsing a HTML document (or part thereof), with the view of CAPTURING and MODIFYING a specific element of a specific tag.
something like:
1. look for a given tag eg DIV 2. capture the tag (everything from '<DIV' up to the '>') 3. look for a given attribute (eg ID="foo", ID=foo, ID='foo' -- all valid ways) 4. capture it 5. be given the opportunity to manipulate the attribute's value, delete it, etc 6. place captured tag (complete with modifed elements) back into the string in it's original position 7. return to step 1, looking for the next occurence of a DIV tag
I really don't know where to start. I REALLY don't expect someone to write this for me, just some guidance would be great -- or maybe some inspiration :)
I guess what I'd like to be able to do, in pseudo code is:
while (getTag('DIV',$myHTML)) { while(getAttribute('ID')) { // manipulate if($attribute == "foo") { $attribute == "foo2"; } } }
while (getTag('DIV',$myHTML)) { while(getAttribute('ID')) { deleteAttribute(); } }
The solution might be a helluva lot more complex, or may be OOP based.
Any inspiration/links/words of wisdom?
Justin French
attached mail follows:
Okay, this is just very general info to help point you in the right direction, but, here are some functions you'll probably need to accomplish this:
* Regular Expressions * pregi() and/or eregi() * explode() and implode() * str_replace()
Regular expressions will probably be the most important part of doing what you need to do. If you don't already know how they work, they are hard to grasp at first, but, very useful once you understand their purpose.
Monty
> From: justin
indent.com.au (Justin French)
> Newsgroups: php.general
> Date: Fri, 19 Jul 2002 13:50:08 +1000
> To: php <php-general
lists.php.net>
> Subject: modify an element of a HTML tag within a string
>
> Hi all,
>
> I've asked simular questions before, but I think I'm finally asking the
> *right* question to get the right answer.
>
> I'm look for some suggestions on the best method of parsing a HTML document
> (or part thereof), with the view of CAPTURING and MODIFYING a specific
> element of a specific tag.
>
> something like:
>
> 1. look for a given tag eg DIV
> 2. capture the tag (everything from '<DIV' up to the '>')
> 3. look for a given attribute (eg ID="foo", ID=foo, ID='foo' -- all valid
> ways)
> 4. capture it
> 5. be given the opportunity to manipulate the attribute's value, delete it,
> etc
> 6. place captured tag (complete with modifed elements) back into the string
> in it's original position
> 7. return to step 1, looking for the next occurence of a DIV tag
>
>
> I really don't know where to start. I REALLY don't expect someone to write
> this for me, just some guidance would be great -- or maybe some inspiration
> :)
>
attached mail follows:
>I've asked simular questions before, but I think I'm finally asking the >*right* question to get the right answer.
That's often the tricky part :-)
>I'm look for some suggestions on the best method of parsing a HTML document >(or part thereof), with the view of CAPTURING and MODIFYING a specific >element of a specific tag. > >something like: > >1. look for a given tag eg DIV >2. capture the tag (everything from '<DIV' up to the '>') >3. look for a given attribute (eg ID="foo", ID=foo, ID='foo' -- all valid >ways) >4. capture it >5. be given the opportunity to manipulate the attribute's value, delete it, >etc >6. place captured tag (complete with modifed elements) back into the string >in it's original position >7. return to step 1, looking for the next occurence of a DIV tag
If you are only looking for a SPECIFIC tag, you just simplified life immensely!
<?php # Get some beautiful sample HTML: $html = file('http://php.net/') or die("Could not open php.net"); $html = implode('', $html); # Find the DIV tag: $div = stristr($html, '<div'); $divpos = strlen($html) - strlen($div); # Break the HTML up into "before" and "after" DIV tag: $before_div = substr($html, 0, $divpos); $after_div = substr($html, $divpos); # Find the *END* of the DIV tag: # KNOWN BUG: # They *could* bury a > in their attributes if they work at it... $end_tag = strstr($after_div, '>'); $endpos = strlen($after_div) - strlen($end_tag); $div = substr($after_div, 0, $endpos); # Now get the "after" part to *really* be after the *WHOLE* DIV tag: $afterdiv = substr($after_div, $endpos); echo "Before DIV tag: <BR>", htmlentities($before_div), "<HR>\n"; echo "DIV tag itself: <BR>", htmlentities($div), "<HR>\n"; echo "After DIV tag: <BR>", htmlentities($after_div), "<HR>\n"; ?>
I can pretty much guarantee that I didn't put a +1 or -1 somewhere where it belongs in the substr() function calls. I never get that right in my first pass of coding. You'll have to fine-tune that part yourself.
But you can now do the same technique to search inside of $div for the ID attribute, pretty much.
>The solution might be a helluva lot more complex, or may be OOP based. > > >Any inspiration/links/words of wisdom?
If you need to do this for any arbitrary tag all at once, there *HAVE* to be PHP-based HTML parsers "out there" in the various PHP script archives...
If all else fails, the PHP source for http://php.net/strip_tags must have some kind of HTML parsing routine in it.
-- Like Music? http://l-i-e.com/artists.htm
attached mail follows:
This is probably more of an HTML question... Is there a way to pass variables to another page via POST instead of via the URL? I need to pass several variables, one that is an array and another that is a fairly long string, so, I can't really do this via the URL.
My initial idea was to just create a very simple form that only has hidden fields with the data I want to pass, along with an image Submit button that would call the page and pass the hidden field variables.
Is that the only/best way to accomplish this?
Thanks.
Monty
attached mail follows:
Hey, I'm new, but I have some advice.
Do you have to POST? becuase you can use sessions, and PHP has a bunch os
session functions.
Secondly, POST will not attach any variables to the URL, this is done by
GET.
To access the POST variables traverse through the $HTTP_POST_VARS (or $_POST
array, i think) to retrieve your values.
But if you can try using sessions, more secure, and as easy to use as POST,
just traverse $HTTP_SESSION_VARS.
"Monty" <monty3
hotmail.com> wrote in message
news:B95D0D40.11938%monty3
hotmail.com...
> This is probably more of an HTML question... Is there a way to pass
> variables to another page via POST instead of via the URL? I need to pass
> several variables, one that is an array and another that is a fairly long
> string, so, I can't really do this via the URL.
>
> My initial idea was to just create a very simple form that only has hidden
> fields with the data I want to pass, along with an image Submit button
that
> would call the page and pass the hidden field variables.
>
> Is that the only/best way to accomplish this?
>
> Thanks.
>
> Monty
>
>
attached mail follows:
Monty wrote:
>This is probably more of an HTML question... Is there a way to pass >variables to another page via POST instead of via the URL? >
Yes.
<form action="another_page.php" method="post"> ... (form fields here) ... <input name="button_name" type="submit" value="Button Text"> </form>
attached mail follows:
How can I do the following with PHP?
1) Accept more than 1 connections without forking 2) socket_read and fgets from 2 connections at the same time
please help! thanks in advance
attached mail follows:
str_replace() is faster and better for simple string replacement.
-----Original Message-----
From: vins [mailto:vins
webonline.co.za]
Sent: Thursday, July 18, 2002 9:43 PM
To: php-general
lists.php.net
Subject: [PHP] Truncate ::: DAM!!!!!
LOL...... So after my last post about updating files i sat and thought about all the replies i got... and then a slap on the head solved the "DUH" problem ereg_replace("\r\n", "\n", $DBfile); I mean..... i am a dork as the best of times..
but now.... there is another problem....
the file length is 10 charactes but the new file length is 15.... I need to overright everything in the old file and somehow push the file length to 15 it truncates..... what now ???
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
hello, any regex gurus? i'm trying to match words put into a <textarea> that are in the form of a\np\np\l\e or any combination of new lines in between, before or after.
$answer = "hello\na\np\np\nl\ne\n"; /*from textarea in form*/ $word = "apple"; $word = preg_replace("/(.)/","(.?|\s+|\n+|)$1(.?|\s+|\n+|)",$word); preg_match("/".$word."/im",$answer,$match)
works. but if
$word = "red apple"; $answer = "r\ne\nd\n\na\np\np\nl\e";
it doesn't match.
thanks in advance, joe
attached mail follows:
try changing the "+"'s with "*"'s + = 1 or more * = 0 or more
-----Original Message-----
From: Joe Rice [mailto:riceja
water-melon.net]
Sent: Friday, July 19, 2002 3:30 PM
To: php-general
lists.php.net
Subject: [PHP] vertical word match
hello, any regex gurus? i'm trying to match words put into a <textarea> that are in the form of a\np\np\l\e or any combination of new lines in between, before or after.
$answer = "hello\na\np\np\nl\ne\n"; /*from textarea in form*/ $word = "apple"; $word = preg_replace("/(.)/","(.?|\s+|\n+|)$1(.?|\s+|\n+|)",$word); preg_match("/".$word."/im",$answer,$match)
works. but if
$word = "red apple"; $answer = "r\ne\nd\n\na\np\np\nl\e";
it doesn't match.
thanks in advance, joe
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
Pardon my sloppy explanation but here it is:
how can i sort an array based on key element ie.
key values are: a1, a2 ,a3 ..., b1, b2 ,b3, ...c1, c1, c3... so doing this: while (list($k, $v) = each($data)) { for ($i=0; $i<count($k); $i++) { echo "$k[0] = $v\n<br>"; } will list all the $k $v . a = foo a = bar b = another foo ....... and so on
Now, how can i sort it according to $k[0] where $k[0] = a, than the same for all b's and so on.
attached mail follows:
dunno if this'll work... but here goes...
sort($data); ksort($data);
but ksort() might mangle the order from sort(). In that case, you'll need to write your sort routine that retains the old order
-----Original Message-----
From: Peter J. Pieczora [mailto:pjpieczora
sympatico.ca]
Sent: Friday, July 19, 2002 5:35 AM
To: php-general
lists.php.net
Subject: [PHP] Sorting array based on key string
Pardon my sloppy explanation but here it is:
how can i sort an array based on key element ie.
key values are: a1, a2 ,a3 ..., b1, b2 ,b3, ...c1, c1, c3... so doing this: while (list($k, $v) = each($data)) { for ($i=0; $i<count($k); $i++) { echo "$k[0] = $v\n<br>"; } will list all the $k $v . a = foo a = bar b = another foo ....... and so on
Now, how can i sort it according to $k[0] where $k[0] = a, than the same for all b's and so on.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
Hi,
Let's say I have the following string:
$str = 'abcdefghijklmnop';
...and I want to strip out char #'s 4 through to 7 (d,e,f,g)
$strip_start = 4; $strip_end = 7;
($str would now be 'abchijklmnop';)
THEN I want to plug a new string $filler at position 4
$filler = '4567';
($str would now be 'abc4567hijklmnop')
This is what I think would work (untested), looking for pointers, optimisation, or a better approach:
<? $str = 'abcdefghijklmnop'; $strip_start = 4; $strip_end = 7; $filler = '4567';
$pre = substr($str,0,$strip_start-1); // abc $post = substr($str,$strip_end+1,strlen($str)); // hijklmnop
$str = $pre.$filler.$post; //abc4567hijklmnop ?>
Thanks,
Justin French
attached mail follows:
dunno how much slower it'd be, but it might look better. You could convert the strings to an array, use array_splice(), and then convert back to a string.
-----Original Message-----
From: Justin French [mailto:justin
indent.com.au]
Sent: Friday, July 19, 2002 3:39 PM
To: php
Subject: [PHP] best way to delete char# 4-7 from a string?
Hi,
Let's say I have the following string:
$str = 'abcdefghijklmnop';
...and I want to strip out char #'s 4 through to 7 (d,e,f,g)
$strip_start = 4; $strip_end = 7;
($str would now be 'abchijklmnop';)
THEN I want to plug a new string $filler at position 4
$filler = '4567';
($str would now be 'abc4567hijklmnop')
This is what I think would work (untested), looking for pointers, optimisation, or a better approach:
<? $str = 'abcdefghijklmnop'; $strip_start = 4; $strip_end = 7; $filler = '4567';
$pre = substr($str,0,$strip_start-1); // abc $post = substr($str,$strip_end+1,strlen($str)); // hijklmnop
$str = $pre.$filler.$post; //abc4567hijklmnop ?>
Thanks,
Justin French
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
> From: Justin French [mailto:justin
indent.com.au]
> Sent: Friday, July 19, 2002 7:39 AM
> To: php
> Subject: [PHP] best way to delete char# 4-7 from a string?
>
>
> Hi,
>
> Let's say I have the following string:
>
> $str = 'abcdefghijklmnop';
>
> ...and I want to strip out char #'s 4 through to 7 (d,e,f,g)
>
> $strip_start = 4;
> $strip_end = 7;
>
> ($str would now be 'abchijklmnop';)
>
> THEN I want to plug a new string $filler at position 4
>
> $filler = '4567';
>
> ($str would now be 'abc4567hijklmnop')
Hi,
substr_replace() does exactly what you want.
$newstring = substr_replace($str, "4567", 4, 4);
Regards Joakim Andersson
attached mail follows:
Is it possible to somehow do a session unregister of all session variables except for (say) 2 variables. varA and varB
So if my session had : varA, varB,varC, varD,varE (etc)
I want to unregister all but varA and varB.
Is there an 'elegant' way to do this without testing for all the variables in the session?
Cheers,
Brad
Nel vino la verità, nella birra la forza, nell'acqua i bacilli -------------------------------------------------------------------------- In wine there is truth, in beer there is strenght, in water there are bacteria
attached mail follows:
I got a file line like this
<!-- START --> This is a line1 this is a line2 this is a line3 this is a line4 <!-- END -->
how can i grep out the line1,line2,line3 ?? do anyone out there have any idea ?
attached mail follows:
You can try this.
<?PHP
$datafile = file("..."); // Here comes your filename
for ($k=0; $k<=count($datafile)-1; $k++) {
echo "$datafile[$k]<br>"; // Display each line read from datafile
}
?>
"Yamin Prabudy" <phplist
pro.net.id> schreef in bericht
news:200207191258.05136.phplist
pro.net.id...
> I got a file line like this
>
> <!-- START -->
> This is a line1
> this is a line2
> this is a line3
> this is a line4
> <!-- END -->
>
>
>
> how can i grep out the line1,line2,line3 ??
> do anyone out there have any idea ?
>
attached mail follows:
I think more info is probably needed here. Is it always the literal string "line3" that you want to catch, or always the second last line?
Some kind of regular expression solution is probably what you need.
Michael
On Fri, 19 Jul 2002, Peter wrote:
> You can try this.
>
> <?PHP
>
> $datafile = file("..."); // Here comes your filename
>
> for ($k=0; $k<=count($datafile)-1; $k++) {
>
> echo "$datafile[$k]<br>"; // Display each line read from datafile
>
> }
>
> ?>
>
>
> "Yamin Prabudy" <phplist
pro.net.id> schreef in bericht
> news:200207191258.05136.phplist
pro.net.id...
> > I got a file line like this
> >
> > <!-- START -->
> > This is a line1
> > this is a line2
> > this is a line3
> > this is a line4
> > <!-- END -->
> >
> >
> >
> > how can i grep out the line1,line2,line3 ??
> > do anyone out there have any idea ?
> >
>
>
>
>
-- -------------------------------- n i n t i . c o m php-python-perl-mysql-postgresql -------------------------------- Michael Hall nintininti.com --------------------------------
attached mail follows:
On Friday 19 July 2002 15:43, Peter wrote: > You can try this. > > <?PHP > > $datafile = file("..."); // Here comes your filename > > for ($k=0; $k<=count($datafile)-1; $k++) { > > echo "$datafile[$k]<br>"; // Display each line read from datafile > > } > > ?>
foreach ($datafile as $line) { echo "$line<br>"; }
is a lot simpler and easier to understand.
-- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development */* I stick my neck out for nobody. -- Humphrey Bogart, "Casablanca" */
attached mail follows:
Any ideas on why this won't work? It will only include("inc/entrance.php") It never, no matter what the value of $mode, displays collection.php.
<?php $mode = "entrance"; if ($mode = "entrance") { include("inc/entrance.php"); } else if ($mode = "collection") { include("inc/collection.php"); }
?>
attached mail follows:
Hello John,
Friday, July 19, 2002, 12:25:12 AM, you wrote:
JW> Any ideas on why this won't work? It will only include("inc/entrance.php") JW> It never, no matter what the value of $mode, displays collection.php.
thinking logicaly:
JW> <?php JW> $mode = "entrance"; $mode is "entrance" JW> if ($mode = "entrance") { looks if mode is "entrance" which is JW> include("inc/entrance.php"); if was true so it includes entrance JW> } JW> else if ($mode = "collection") { looking again if for same $mode if it is "collection" but it was in first line "entrance" JW> include("inc/collection.php"); if was false it never executes this part! JW> }
JW> ?>
so what are you trying to get? both included? if yes this will include both:
<?php $mode = "entrance"; if ($mode = "entrance") { include("inc/entrance.php"); } $mode = "collection"; if ($mode = "collection") { include("inc/collection.php"); }
?>
sorry if i didn't understood the question!
-- Best regards, Mantas mailto:Mantuksattbi.com
attached mail follows:
You need == instead of = there
On Fri, 19 Jul 2002, John Wulff wrote:
> Any ideas on why this won't work? It will only include("inc/entrance.php") > It never, no matter what the value of $mode, displays collection.php. > > <?php > $mode = "entrance"; > if ($mode = "entrance") { > include("inc/entrance.php"); > } > else if ($mode = "collection") { > include("inc/collection.php"); > } > > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
attached mail follows:
Well, first thing I see is that you need to change this:
if ($mode == "entrance")
You need the double equal signs for string comparison.
> From: johnw
orcasnet.com (John Wulff)
> Newsgroups: php.general
> Date: Fri, 19 Jul 2002 00:25:12 -0700
> To: php-general
lists.php.net
> Subject: Why won't this work?
>
> Any ideas on why this won't work? It will only include("inc/entrance.php")
> It never, no matter what the value of $mode, displays collection.php.
>
> <?php
> $mode = "entrance";
> if ($mode = "entrance") {
> include("inc/entrance.php");
> }
> else if ($mode = "collection") {
> include("inc/collection.php");
> }
>
> ?>
>
>
attached mail follows:
You probably do not have a background of C / C++ programming ;-)
assignments: single equal sign comparison: dual equal sign
The *assignments* in your if statements are always TRUE, so it will always execute the statements after the first *if*
So use if ($mode == "entrance") { and else if ($mode == "collection") {
And all works well...
René
attached mail follows:
Hello Rasmus,
Friday, July 19, 2002, 12:26:45 AM, you wrote:
RL> You need == instead of = there
RL> On Fri, 19 Jul 2002, John Wulff wrote:
>> Any ideas on why this won't work? It will only include("inc/entrance.php") >> It never, no matter what the value of $mode, displays collection.php. >> >> <?php >> $mode = "entrance"; >> if ($mode = "entrance") { >> include("inc/entrance.php"); >> } >> else if ($mode = "collection") { >> include("inc/collection.php"); >> } >> >> ?>
oh yea, didn't look closely and didn't understand question clearly :/ guess im tired:( good night...sorry about my letter:/ thnx
-- Best regards, Mantas mailto:Mantuksattbi.com
attached mail follows:
En réponse à Mantas Kriauciunas <Mantuks
attbi.com>:
Hi
You use = instead of ==
So, the first condition is always true
Regards
Julien
> Hello John,
>
> Friday, July 19, 2002, 12:25:12 AM, you wrote:
>
> JW> Any ideas on why this won't work? It will only
> include("inc/entrance.php")
> JW> It never, no matter what the value of $mode, displays
> collection.php.
>
> thinking logicaly:
>
> JW> <?php
> JW> $mode = "entrance"; $mode is "entrance"
> JW> if ($mode = "entrance") { looks if mode is
> "entrance" which is
> JW> include("inc/entrance.php"); if was true so it
> includes entrance
> JW> }
> JW> else if ($mode = "collection") { looking again if for
> same $mode if it is "collection" but it was in first line "entrance"
> JW> include("inc/collection.php"); if was false it never
> executes this part!
> JW> }
>
> JW> ?>
>
> so what are you trying to get? both included?
> if yes this will include both:
>
> <?php
> $mode = "entrance";
> if ($mode = "entrance") {
> include("inc/entrance.php");
> }
> $mode = "collection";
> if ($mode = "collection") {
> include("inc/collection.php");
> }
>
> ?>
>
>
> sorry if i didn't understood the question!
>
> --
> Best regards,
> Mantas mailto:Mantuks
attbi.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
attached mail follows:
<snip>
> $mode = "entrance"; > if ($mode == "entrance") { > </snip> I suppose you added the first line ($mode = "entrance"; ) for testing purposes during debugging, but in order for the script to work you should now remove it, because now $mode will always have the value "entrance"
good luck
René
attached mail follows:
hmm... seems a MySQL topic. I suppose that your table is filled with correct data at some other point. So what you need is a count query that returns *one* result and not all records in that table. You do not want a *while* loop in your PHP script, because that would show a list of unique ips. So my gues would be:
$result = mysql_query("SELECT COUNT(DISTINCT IP) AS ips FROM ma_counter"); $ips = mysql_fetch_row($result); pintf("Visitors = %d",$ips);
Disclaimer: code not tested. You might want to check the MySQL manual for syntax details of the query.
Good luck
René
John Wulff wrote:
>You're a savior, don't know how i missed that. Thanks a bunch. Now, one >more quick question if you don't mind. I've got this query at the bottom >of my page for the purpose of a counter. But naturally i don't want a >list of all the ips logged, i just want a count of how many unique ips >there are in the table. How do i go about this?<?php >$result = mysql_query("SELECT distinct ip from ma_counter"); >while(list($ip) = mysql_fetch_row($result)) >{ >print ("$ip"); >} >?> > > > > >><snip> >> >> >> >>> $mode = "entrance"; >>> if ($mode == "entrance") { >>> >>> >>> >></snip> >>I suppose you added the first line ($mode = "entrance"; ) for testing >>purposes during debugging, but in order for the script to work you >>should now remove it, because now $mode will always have the value >>"entrance" >> >>good luck >> >> >>René >> >> > > > > >
attached mail follows:
> From: René Moonen [mailto:rene.moonen
oberthur.nl]
> Sent: Friday, July 19, 2002 11:01 AM
> $result = mysql_query("SELECT COUNT(DISTINCT IP) AS ips FROM ma_counter");
You _might_ need to add "GROUP BY ip" (without quotes) to the end of that query.
> Disclaimer: code not tested. You might want to check the MySQL manual
Still not tested :-)
Regards Joakim Andersson
attached mail follows:
Well if you *know* your query only returns one row or you are just interessed in the first row, just forget about the while construction
$result = mysql_query("SELECT id FROM ma_users WHERE user='$PHP_AUTH_USER'"); $id=mysql_fetch_row($result) print $id;
Good luck
René
John Wulff wrote:
>Didn't work, but its a great place for me to start from. >As far as the difference between a looping query and a non looping query, >i understand the difference but not exactly how to go about writing a non >looping query. This bit of code is looping, and i assume it dosen't need >to be, how do i fix this? >$result = mysql_query("SELECT id FROM ma_users where user='$PHP_AUTH_USER'"); >while(list($id) = mysql_fetch_row($result)) >{ >print($id); >} > > > >>hmm... seems a MySQL topic. >>I suppose that your table is filled with correct data at some other >>point. So what you need is a count query that returns >>*one* result and not all records in that table. You do not want a >>*while* loop in your PHP script, because that would show a list of >>unique ips. So my gues would be: >> >>$result = mysql_query("SELECT COUNT(DISTINCT IP) AS ips FROM >>ma_counter"); $ips = mysql_fetch_row($result); >>pintf("Visitors = %d",$ips); >> >>Disclaimer: code not tested. You might want to check the MySQL manual >>for syntax details of the query. >> >>Good luck >> >>René >> >> >>John Wulff wrote: >> >> >> >>>You're a savior, don't know how i missed that. Thanks a bunch. Now, >>>one more quick question if you don't mind. I've got this query at the >>>bottom of my page for the purpose of a counter. But naturally i don't >>>want a list of all the ips logged, i just want a count of how many >>>unique ips there are in the table. How do i go about this?<?php >>>$result = mysql_query("SELECT distinct ip from ma_counter"); >>>while(list($ip) = mysql_fetch_row($result)) >>>{ >>>print ("$ip"); >>>} >>>?> >>> >>> >>> >>> >>> >>> >>>><snip> >>>> >>>> >>>> >>>> >>>> >>>>> $mode = "entrance"; >>>>> if ($mode == "entrance") { >>>>> >>>>> >>>>> >>>>> >>>>> >>>></snip> >>>>I suppose you added the first line ($mode = "entrance"; ) for testing >>>>purposes during debugging, but in order for the script to work you >>>>should now remove it, because now $mode will always have the value >>>>"entrance" >>>> >>>>good luck >>>> >>>> >>>>René >>>> >>>> >>>> >>>> >>> >>> >>> >>> > > > > >
attached mail follows:
Eh.. probably should be:
$result = mysql_query("SELECT id FROM ma_users WHERE user='$PHP_AUTH_USER'"); $row=mysql_fetch_row($result) print $row['id'];
René
René Moonen wrote:
> Well if you *know* your query only returns one row or you are just > interessed in the first row, just forget about the while construction > > $result = mysql_query("SELECT id FROM ma_users WHERE > user='$PHP_AUTH_USER'"); > $id=mysql_fetch_row($result) > print $id; > > Good luck > > René > > > John Wulff wrote: > >> Didn't work, but its a great place for me to start from. >> As far as the difference between a looping query and a non looping >> query, >> i understand the difference but not exactly how to go about writing a >> non >> looping query. This bit of code is looping, and i assume it dosen't >> need >> to be, how do i fix this? >> $result = mysql_query("SELECT id FROM ma_users where >> user='$PHP_AUTH_USER'"); >> while(list($id) = mysql_fetch_row($result)) >> { >> print($id); >> } >> >> >> >>> hmm... seems a MySQL topic. >>> I suppose that your table is filled with correct data at some other >>> point. So what you need is a count query that returns >>> *one* result and not all records in that table. You do not want a >>> *while* loop in your PHP script, because that would show a list of >>> unique ips. So my gues would be: >>> >>> $result = mysql_query("SELECT COUNT(DISTINCT IP) AS ips FROM >>> ma_counter"); $ips = mysql_fetch_row($result); >>> pintf("Visitors = %d",$ips); >>> >>> Disclaimer: code not tested. You might want to check the MySQL manual >>> for syntax details of the query. >>> >>> Good luck >>> >>> René >>> >>> >>> John Wulff wrote: >>> >>> >>> >>>> You're a savior, don't know how i missed that. Thanks a bunch. Now, >>>> one more quick question if you don't mind. I've got this query at the >>>> bottom of my page for the purpose of a counter. But naturally i don't >>>> want a list of all the ips logged, i just want a count of how many >>>> unique ips there are in the table. How do i go about this?<?php >>>> $result = mysql_query("SELECT distinct ip from ma_counter"); >>>> while(list($ip) = mysql_fetch_row($result)) >>>> { >>>> print ("$ip"); >>>> } >>>> ?> >>>> >>>> >>>> >>>> >>>> >>>> >>>>> <snip> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> $mode = "entrance"; >>>>>> if ($mode == "entrance") { >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> </snip> >>>>> I suppose you added the first line ($mode = "entrance"; ) for testing >>>>> purposes during debugging, but in order for the script to work you >>>>> should now remove it, because now $mode will always have the value >>>>> "entrance" >>>>> >>>>> good luck >>>>> >>>>> >>>>> René >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> >>> >> >> >> >> >> > > >
attached mail follows:
I've just downloaded a bunch of stuff from www.gingerall.org, which I hope will set up Sablotron on my RH7.2/Apache1.3.24/PHP4.2.1 box.
Can I just use the rpms?:
sablotron-0.95-1.i386.rpm sablotron-devel-0.95-1.i386.rpm
There is also a "Sablot-0.95-PHP.patch" in there, plus a Sablot-0.95.tar.gz package that won't untar which I guess is the source.
I found the directions about what packages I needed pretty confusing. Any advice anyone?
I know I need to recompile PHP when Sablotron is installed.
TIA
--------------------------------
Michael Hall ninti
ninti.com
--------------------------------
attached mail follows:
Is there a way to get and store the name of a referenced variable into another variable? Example...
$varname = "blah"; checkit($varname);
function checkit(&$name) { ...code... }
In the function above, I'd like to find out the name of the referenced variable (pointed to by $name) which should equal "varname" so I can store this string in another variable (i.e., $thename = "varname").
Is there a way to do this in PHP??
Thanks.
attached mail follows:
Hello,
can you tell me what i have to do to generate more than one pdf document with pdflib. At the moment i am not able to do this. the only thing i can do is actually to make one pdf.
It is really important for me to bring more sites in one document. the problem is not solved if i just make more than one doc.
thx Joey
attached mail follows:
Dear all I had a folder which contains a lot of pdf file, the name format of the pdf files are : xxxxx.dateformat.pdf (eg : abcdefg.20020718.pdf). Now i want to use the php script to detect what files it got in a specific folder. i want to make a user input form which will let user to input the date and then i will look for the pdf report from this specific folder base on the Date given!
I think one of the quickest way is to ask php to check the filename from "Right to Left" which is the Date format!
But i don't know which php function will perform this task (Check filename from Right to Left).
If you have any other suggestion, pls help me!
-- Thx a lot! Jack nedcor4nedcor.com.hk
attached mail follows:
I'd use something like:
<?php $handle=opendir('.'); while (false!==($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "$file\n"; } } closedir($handle); ?>
to retrieve dir listing. If you make a function from it, which you'll give a path for argument you can make the script index an entire dir struct. With is_file() you can check to see if the dirlist entry is a file.
Then, you can split every filename in different parts with something like
$parts = split(".", $filename);
$parts[0] will then have the "abcdefg" part of the filename $parts[1] will have the timestamp $parts[2] will have the extension.
I hope that this answers your question. You may want to insert the file data in a database for easy searching, and run a script to index the dir every now and then.
Greetz, Wouter ---------- Alle door mij verzonden email is careware. Dit houdt in dat het alleen herlezen en bewaard mag worden als je goed omgaat met al het leven op aarde en daar buiten. Als je het hier niet mee eens bent dien je mijn mailtje binnen 24 uur terug te sturen, met opgaaf van reden van onenigheid.
All email sent by me is careware. This means that it can only be reread and kept if you are good for all the life here on earth and beyond. If you don't agree to these terms, you should return this email in no more than 24 hours stating the reason of disagreement.
-----Oorspronkelijk bericht-----
Van: Jack [mailto:nedcor4
nedcor.com.hk]
Verzonden: vrijdag 19 juli 2002 11:00
Aan: php-general
lists.php.net; php-windows
lists.php.net
Onderwerp: [PHP] How to Detect File in a Specifc Directory on Window
Env?
Dear all I had a folder which contains a lot of pdf file, the name format of the pdf files are : xxxxx.dateformat.pdf (eg : abcdefg.20020718.pdf). Now i want to use the php script to detect what files it got in a specific folder. i want to make a user input form which will let user to input the date and then i will look for the pdf report from this specific folder base on the Date given!
I think one of the quickest way is to ask php to check the filename from "Right to Left" which is the Date format!
But i don't know which php function will perform this task (Check filename from Right to Left).
If you have any other suggestion, pls help me!
-- Thx a lot! Jack nedcor4nedcor.com.hk
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
attached mail follows:
Jack wrote: > Dear all > I had a folder which contains a lot of pdf file, the name format of the pdf > files are : xxxxx.dateformat.pdf (eg : abcdefg.20020718.pdf). > Now i want to use the php script to detect what files it got in a specific > folder. > i want to make a user input form which will let user to input the date and > then i will look for the pdf report from this specific folder base on the > Date given! > > I think one of the quickest way is to ask php to check the filename from > "Right to Left" which is the Date format! > > But i don't know which php function will perform this task (Check filename > from Right to Left). > > If you have any other suggestion, pls help me!
I think I would do something like this:
<?php
//DATEFORMAT YYYYMMDD
if($dir=
opendir("/yourdirwithpdf")) {
echo "Found following files:"
while(($file=readdir($dir))!==false) {
if(ereg("^[a-zA-Z0-9]+\.$INPUTDATE\.pdf")) {
echo '<a href="'.$file.'">'.$file.'<\n>';
}
}
}
?>
Regards, Johan
attached mail follows:
> <?php
> //DATEFORMAT YYYYMMDD
> if($dir=
opendir("/yourdirwithpdf")) {
> echo "Found following files:"
> while(($file=readdir($dir))!==false) {
> if(ereg("^[a-zA-Z0-9]+\.$INPUTDATE\.pdf")) {
> echo '<a href="'.$file.'">'.$file.'<\n>';
> }
> }
> }
> ?>
UPS
if(ereg("^[a-zA-Z0-9]+\.$INPUTDATE\.pdf", $file))
The ereg line should look like this :)
Regards, Johan
attached mail follows:
Johan Holst Nielsen wrote:
>> <?php
>> //DATEFORMAT YYYYMMDD
>> if($dir=
opendir("/yourdirwithpdf")) {
>> echo "Found following files:"
>> while(($file=readdir($dir))!==false) {
>> if(ereg("^[a-zA-Z0-9]+\.$INPUTDATE\.pdf")) {
>> echo '<a href="'.$file.'">'.$file.'<\n>';
>> }
>> }
>> }
>> ?>
>
>
> UPS
>
> if(ereg("^[a-zA-Z0-9]+\.$INPUTDATE\.pdf", $file))
>
> The ereg line should look like this :)
>
Wow, I also forgot to close the dir handle! Well I will let you do that :)
Regards, Johan
attached mail follows:
Peter a écrit :
> If you removed the > ErrorDocument 404 /phpinfo.php > from the apache conf (or reset it to original value), what happens? Do you > get a standard 404 not found error page?
Sure. But it's an apache problem, it drops the body as soon as you do have a 404 error. Sux :p
-- Fabien Penso <pensolinuxfr.org> | LinuxFr a toujours besoin de : http://perso.LinuxFr.org/penso/ | http://linuxFr.org/dons/
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]