Re: [PHP] IF statement madness
At 19:21 14.03.2003, James E Hicks III said: [snip] >Help save my sanity! What can I do to the IF statement in the following >code to >make it print the line that says "By God they are equal in value."? I have >tried >the following changes; > > 1. using === instead of == > 2. placing (float) in front of the $i and $target inside and before > the IF >statement. > >$start = 215; >$end = 217; >$target = 216; >for ($i=$start; $i<=$end; $i+=.1){ >if ( $i == $target ){ >echo ("$i - $target, By God, the are equal in value."); >} else { >echo ("$i - $target, Eternal Damnation, they aren't >equal!"); >} >} >?> [snip] Before the if statement in your loop place this line: echo "\$i is now: $i"; You'll notice that most probably your $i variable will miss $target by some hunderths or thousandths, since you're working with it as a float. This is due to the way fp numbers are stored and calculated (using exponents and mantissa). Workaround: don't use floats if you want to hit a certain value at the spot: $i - $target, By God, the are equal in value."); } else { echo ("$i - $target, Eternal Damnation, they aren't equal!"); } } ?> -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OT Inactivity Timeout
At 17:03 14.03.2003, Luis Lebron said: [snip] >This may be more of a javascript question than a php question. But how can I >set up an inactivity timeout that will logout a person after let's say 20 >minutes of inactivity? [snip] That's an interesting question - something that might be handled server-side (which is usually a lot safer than on the client side), supporting (javascript-based) client requests if it is still logged-in. I have tried a quick sample and believe a scenario like this could work quite well in a production environment: (1) handle login status server-side: After authenticating the user, establish a timeout until that the login will be valid WITHOUT user interaction (you may e.g. choose 5 minutes, i.e. time() + (5*60)). Store this timeout value in session data ($_SESSION['login_valid_until']); (2) update the timeout on every user interaction Simply refresh the session based timeout value using the same formula. (3) Have a special entry (either a special script, or a certain parameter) where the client may ask if the login is still valid. Make sure this script (and only this!) DOES NOT increment the timeout value since it will be called by client javascript, not by user interaction. (A) Header pseudocode for "interactive" pages (normal application scripts): login valid and validates against timeout? NO: transfer to "you have been logged out" page YES: increase timeout; continue processing; (B) Pseudocode for timeout-checking script: login valid and validates against timeout? NO: transfer to "you have been logged out" page YES: return "204 no response" status code (C) Javascript to be used on any page: function checkHandler() { window.location.href="yourcheckscripthere.php?<?php echo SID; ?>"; onloadHandler(); } function onloadHandler() { setTimeout('checkHandler();', 6); } The main feature here is the use of the server status code 204 which means "No Response". Cited from RFC2616 (HTTP 1.1 draft standard): 10.2.5 204 No Content The server has fulfilled the request but does not need to return an entity-body, [...] If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, [...] The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields. So: if the server sees the login status (in session data) is still valid, the reload request issued by JavaScript doesn't lead to a new page but lets the browser remain in "idle" mode. However the timeout needs to be set again; it seems that the JS engine clears all timers _before_ the reload request (which would make sense; it can't clean them up on another page). However if the server sees the user has exceeded its timeout (by not activating some "interactive" action that would cause the timeout to be extended), the javascript reload will immediately transfer the user agent to the "you're outta here" page. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] can't get any string replacements to clean this
Correction - "$to" should of course read "$repl" :-& -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] can't get any string replacements to clean this
At 08:43 14.03.2003, Dennis Gearon said: [snip] >I finally got something to do it, at least, in inline code. > >I couldn't figure out how to remove NULLS, anybody know? A search on: [snip] I just found this thread, pardon me if I'm off topic, but something like this should work for you. It makes use of the fact that all of the replace functions can take arrays as input parameters. $from = array("/(\r\n)+/", "/(\n\r)+/", "/(\r)+/", "/[\x0..\x19]/"); $repl = array("\n", "\n", "\n", null); $str_cleaned = preg_replace($from, $to, $str_uncleaned); This construction should convert the occurrence of one or more successive newline combinations with a single newline character, and remove control characters at large (untested). -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http_session_vars
At 22:17 13.03.2003, rotsky said: [snip] >I thought session vars were either POSTed or passed via cookies... [snip] No - you're mixing up the session identifier and session data. The session identifier is just an arbitrary key to a server-side storage where session data is stored. The session identifier (aka SID) is effectively passed either via cookie, or via $_REQUEST parameter. Session data (the $_SESSION array, to be specific) will always be stored server-side, by default in a session file. The default filename is sess_. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with string comparison
At 23:11 13.03.2003, Charles Kline said: [snip] >On Thursday, March 13, 2003, at 05:08 PM, Ernest E Vogelsinger wrote: > >> - if your query is exactly as you sent it here you're missing a comma >> after >> the closing bracket of "concat()", just before "name" > >name is supposed to be an alias for the concatenated values of >fname,lname,mname. then shouldn't that be something like this? (at least with PostgreSQL it would): $sql = "SELECT id, concat(fname, ' ', lname, ' ', degree1) as \"name\"". " FROM tbl_personnel WHERE name LIKE '%" . $attributes['nametofind'] . "%' ORDER BY lname ASC"; I just saw that there's another quote just before WHERE that may throw your code off. >Let me try to say what I am trying to do. I have a table of people and >have the names saved in fields: fname, lname, mname. I want to have a >search field where the user can find a persons record by typing in all >or part of their name. What would this kind of query look like? I'd say you're right on track... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Please Help with the Code
At 22:56 13.03.2003, Dalibor Malek said: [snip] >The function is pretty simple, In this Page is a form where the User can >enter his username and password, when he clicks on submit the script >checks the input with the entries in the database. If its ok the script >sends him to the page info.php if its not ok he comes to the page >index_fault.php. >This is all functioning but my problem is I have to paste at least the >username to the page info.php. >If I set the action to info.php and use $HTTP_GET_VARS its functioning >but I cant use that action I need to verify >the user. >As far as I know I cant use two actions. >Has anybody a idea how to do that, I'm sitting on this page now for 30 >hours without brake but I just dont get it. [snip] Please don't take this personally but I dislike this approach to allow a user to access some information he has to validate for. As soon as a user gets to know that he can access the info page just by entering the "info.php" URL, maybe together with a user ID as parameter, he will do that (at least he can bookmark the location he should login to). This is completely against the general idea of authentication... What I'd do is to validate the user, setup a session where the user id is stored (which is server side anyway), then branch to different sections of my app, not by means of redirect but by including() the necessary code. You may pass the user token to the next page in two different ways: (a) pass them as query parameter (see rant above): header ("Location: $FF_redirectLoginSuccess?" . "mmu=" . urlencode($MM_UserName) . "&" . "mma=" . urlencode($MM_UserAuthorization)); (b) just more secure and elegant is simply handing over the session: header ("Location: $FF_redirectLoginSuccess?" . session_name() . '=' . session_id()); The latter of course will only work if it's the same host, and the same machine so PHP will have access to the session data in question. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with string comparison
At 22:31 13.03.2003, Charles Kline said: [snip] >I am trying to get this sql query to work and am getting the error >"Insufficient data supplied". Can anyone help with this? > >$sql = "SELECT id, concat(fname, ' ', lname, ' ', degree1) name > FROM tbl_personnel "WHERE name LIKE \'%"; >$sql .= $attributes['nametofind']; >$sql .= "%\' ORDER BY lname ASC"; > >What I am trying to do is allow the user to find a personnel record >that contains the name to find. [snip] At the first glance I see 3 items where the first one might be the culprit: - if your query is exactly as you sent it here you're missing a comma after the closing bracket of "concat()", just before "name" - before constructing the query make sure $attributes['nametofind'] is formatted correctly, esp. correctly escaping single quotes - when using double quotes to construct a string you don't need to escape single quotes. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] If 1 IF fails, do the rest anyway...
At 22:13 13.03.2003, Liam Gibbs said: [snip] >I know that in a case like this > >if((test1) && (test2) && (test3)) { >... >} > >if test1 fails, dear PHP won't bother doing test2 and 3. Am I correct? Is >there a syntax that will make it carry on with test2 and 3 anyway, >regardless of how test1 came out? [snip] The rule for AND chains is: - evaluate the expressions from left to right - stop AND DON'T RUN THE IF-BLOCK at the first expression evaluating to false The rule for OR chains is: - evaluate the expressions from left to right - stop AND RUN THE IF-BLOCK at the first expression evaluating to true This feature is inherent to all (well, most at least) languages - so be aware of side effects (or no side effects occurring) with such constructs. To allow _all_ expressions to be evaluated you need to run all 3 by themselves, later comparing the results: $x1 = test1(); $x2 = test2(); $x3 = test3(); if ($x1 && $x2 && $x3) ... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] time() question
At 18:07 13.03.2003, Tom Ray said: [snip] >Is there an easy way to display the epoch time given by time() in a human >readable format? Basically, if I do $time = time(); and the insert that >data into my mysql database and then pull that information out again how >do I make it look like 2003-03-13 or a variant of that? [snip] http://www.php.net/manual/en/function.date.php -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pop-up problem
At 15:52 13.03.2003, -{ Rene Brehmer }- said: [snip] >My IE doesn't care about that ... it kicks both into action ... which is >bothersome as I normally used '#' in the href when onclick was used to >open windows... so everytime you clicked the link, it'd scroll the page to >the top, while opening the new window. > >The same thing happens with target (if target is _new) and # in href. >It'll load a new window, with the current page in, and try to run the >onclick function there... [snip] You might use here - however note that this won't do _anything_ if JS is disabled. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is there any reason...
At 15:36 13.03.2003, Chris Hewitt said: [snip] >If the software on this list has the facility I think the "Reply-To" >field should be set to the list. What do others think? [snip] I join our respected CPT John Holmes - there's enough traffic here already :) If the Reply-To field would be set to the list you'd need to manually copy/paste the sender's address to for a private reply. This could only be circumvented IMHO if Reply-To was set to both the list address and the poster's. My vote: leave it as-is, and use ReplyToAll if you want to. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can't seem to be able to do a get request
At 14:50 13.03.2003, Mathieu Dumoulin said: [snip] >I got this script i wish to run like it was a seperate thread on the server >cause i can't run anything with a crontab but i can't seem to do a valid GET >request thru fsockopen. If anyone can help me please. > > >$fp = fsockopen ("sandbox.lhjmq.xl5.net", 80); >if ($fp) { > >fputs ($fp, "GET /lang_fr/index.php HTTP/1.1"); >while (!feof($fp)) echo fgets ($fp,128); >fclose ($fp); >} > >I run the script from the web but nothing happens. If i run it also with the >real URL i want to get (I cannot show this url for security reasons) my >processor and mysql process should go up to 80% each for like 40 seconds and >my "top" command in shell would show it, but it's not happenning. Now i >tried index.php and still nothing! [snip] If you perform an HTTP request indicating a version of 1.0 or higher, a bit more info is required for the server to process the request. Your simple GET statement would probably work if you indicate HTTP/0.9, but it is questionable if the receiving server would direct the request to the correct domain (would only be if this was the "default domain" for the IP address). For a complete reference on the HTTP protocol look at RFC2616 ftp://ftp.rfc-editor.org/in-notes/rfc2616.txt In short for your request to work you should at least transmit these lines: GET /lang_fr/ index.php HTTP/1.1 [CRLF] Host: www.myhost.com [CRLF] Accept: */* [CRLF][CRLF] where [CR] is a _complete_ CarriageReturn/LineFeed sequence "\r\n". Of course you may add more headers to it. You might also want to check out cURL for threaded requests. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] removing appended chars - please help, quite urgent
At 09:59 13.03.2003, Adriaan Nel said: [snip] >I need to update records in a mysql dbase, from a .csv file, everything >works fine, but the index column, $npr_nr from below sometimes has a space >at the end, this causes the dbase index not to match this one, therefore >this record isn't updated. Do any1 know how I can check for spaces here, >and remove them if present [snip] have a look at trim() -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Follow-up to Hacker problem
At 23:42 12.03.2003, Pag said: [snip] > Your tips were nice, guys, thanks a lot. I tried a few things and i >decided to go for making all the checks server side, cant go safer than that. > Just have a doubt on one of the checks, at least so far. > I have a check for long words, because the shoutbox is in a IFRAME, > so if >someone posted a long word, the infamous horizontal scroll bar would >appear. How can i check for long words on a string and remove them before >they get written on the DB? [snip] Check the archives - within the last 2 days there was a thread about breaking up long words to avoid inappropriate posts to clutter the page layout. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Force refresh of graphic - how?
At 23:33 12.03.2003, Justin French said: [snip] >Put this code in your shared library of functions (adapted from manual, >untested): >function randNumber($min=1000,$max=9) >{ >// build a seed >list($usec, $sec) = explode(' ', microtime()); >$seed = (float) $sec + ((float) $usec * 10); > >// seed random generator >srand($seed); > >// return random number >return rand($min,$max); >} >?> [snip] May I? It's usually not a good idea to re-seed the randum number generator during a single script instance, as this might use the same seed more than once, resulting in the identical random sequence... To avoid reseeding, you could e.g. use a static variable in your randNumber() function: function randNumber($min=1000,$max=9) { static $is_seeded = false; if (!$is_seeded) { $is_seeded = true; // build a seed list($usec, $sec) = explode(' ', microtime()); $seed = (float) $sec + ((float) $usec * 10); // seed random generator srand($seed); } ... I prefer to add a string generated by uniqid(), such as uniqid() uses the entropy generated by the opsys random device (if available) in an attempt to make this truly random. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php errors while displaying database fields
At 23:30 12.03.2003, Boulytchev, Vasiliy said: [snip] >I have searched the archives, and have found nothing on these errors >I am getting. Here is the apache error logs capture: > >PHP Notice: Undefined index: REMOTE_ADDR in >/home/www/customflagcompany/phpshop/modules/admin/lib/ps_session.inc on >line 39 >PHP Notice: Undefined variable: page in >/home/www/customflagcompany/phpshop/bin/index.php3 on line 53 [snip] These are notices only, not errors (notices being the least severe level of issues PHP may warn you about). You may adjust the error reporting level with the error_reporting() function, or the corresponding setting in the php.ini file. "Undefined index": this means that the associative array doesn't have an index field with a particular name defined. PHP will return null in this case. Workaround: if (array_key_exists('REMOTE_ADDR'))... "Undefined variable": the variable you're using has not been defined and never been assigned to. PHP will return null in this case. Workaround: if (isset($page))... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Threading objects
At 23:23 12.03.2003, Kris said: [snip] >Is it possible to some how thread a php script threw apache. There has to be >something you can do, it seems there is always something you can do :) >What I want is the following. >I administer a mailing list that has a few hundred thousand subscribed >recipients. >I've written a script that runs threw the DB and validates the email >address. >First by format then by connecting to the mail server. >This script takes way to long to run as it has to do one at a time. >I want to some how thread this so it can be validating multiple emails at a >time. >Please excuse my ignorance on the subject my web programming experience is >rather limited. [snip] Well, web is (or at least should be) kind of real-time, thus you should try to postpone lengthy actions. What I'd try (and I already did such stuff with success) is to just create some DB entries, in your case this would mean to add a "validation request" entry to a database, or even simply a "todo" file. Another process, most certainly run by a cron job, would then read the DB (or the toto file) and perform actions necessary. When done it would update some kind of status flag. On your website yo could display something like "187322 addresses scheduled for validation - 123499 to go", or something like that, just by reading the status data updated by the cron job. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Creating an Array from a Multi-line string (Help appreciated)
At 21:10 12.03.2003, Bix said: [snip] >I am creating an interface page with a multi line text box which will >recieve a list of phone numbers on individual lines, so: > >12345 >12345 >12345 >and so on... > >I need to carry out an operation on each of these numbers (add them to a >mysql db, but thats not important). > >Is it possible to recieve this text box in my php script and reference each >line? Ideally put it into an array and reference by $number['0'] >$number['1'] and so on, so i can have a 'for' loop going? [snip] If you are certain that the lines are separated by a CR you could simply use $phonearray = explode("\n", $_REQUEST['phones']); -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Random String Generation
At 19:56 12.03.2003, you said: [snip] >On Thursday 13 March 2003 02:49, Mike Walth wrote: > >You have started a new thread by taking an existing posting and replying to >it while you changed the subject. > >...etc... [snip] you _do_ have a stationery for that, do you? *g* -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session id generation
At 19:50 12.03.2003, Mathieu Dumoulin spoke out and said: [snip] >Hi, i'd like to know how PHP determines what session_id to hand out to >users. > >Is it based on some real value like the browser and the ip address? an >incremental number? I want to make sure that it doesnt provide two same >session id for the different users at the same time. [snip] {php_source_directory}/ext/session/session.c this has it all - look for _php_create_id(). Basically it generates an MD5 digest from the current secs and usecs (system time) and a pseudo-random number (see php_combined_lcg() in standard/lcg.c). If an entropy file is available (usually on unix systems) it uses the entropy to further randomize the digest. In a final step the digest is converted to a hex string. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Little Problem :)
At 22:07 11.03.2003, CPT John W. Holmes said: [snip] >Use wordwrap() [snip] Hmm -one never stops learning I believe - I was missing this piece since :) There's a bit of a difference between wordwarp() and my approach (see my last post): wordwrap() counts the width for the while string, while my regex just scans for words that are too long, leaving everything else alone. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Little Problem :)
At 21:32 11.03.2003, David Soler said: [snip] >user writes: "a" > >in the web must appear something like: > > table width > || > aa > aa > aa > aa [snip] You can use a regular expression for this task. This is what I use for my CMS routines: function make_maxlen($string, $maxlen) { $re = '/(.*?)([^\s]{' . $maxlen . ',})(.*)/'; $out = null; while (preg_match($re, $string, $aresult)) { $out .= $aresult[1]; // pre-match $out .= substr($aresult[2], 0, $maxlen) . "\n"; // first n characters of matching long-word $string = substr($aresult[2], $maxlen) . $aresult[3]; // stuff back reminder } $out .= $string; return $out; } $test = 'abc defghijklmno pqrstuvwxyz' . 'abcdefghijklmnopqrstuvwxyz' . 'abc defghijklmno pqrstuvwxyz' . 'abcdefghijklmnopqrstuvwxyz' . 'abc defghijklmno pqrstuvwxyz' . 'abcdefghijklmnopqrstuvwxyz'; echo $test, '', nl2br(make_maxlen($test, 25)); Note that the make_maxlen function returns strings split up merely with a newline character, so use nl2br to create a forced newline. There's no drawback in not using nl2br (not adding ''s) since the inserted newline character will be visible as whitespace and allow the user agent to properly reformat the text within the area. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pop-up problem
At 21:02 11.03.2003, -{ Rene Brehmer }- said: [snip] >On Mon, 20 Jan 2003 21:48:22 +, Sean Burlington wrote about "Re: [PHP] >pop-up problem" what the universal translator turned into this: > >>I would do >> >>Click Here >> >>as this will still work on non-js browsers - albeit without being able >>to size/position the window. > >But you'd also get the same page in two windows ... one with dressing, one >without. Atleast in IE ... it runs both the href code, and the onclick >code ... when the JIT is enabled. > >On browsers where the JIT is disabled, only HREF is executed. [snip] No - if the onClick handler returns false, nothing will happen. That's the original reason for the onClick handler to be there - it can take control if a link is actually performed or not. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] imagejpeg and downloading images
At 17:47 11.03.2003, James Holden said: [snip] >READ the manual. > >The snippet is correct but if you want to take advantage of the saving >features of this function follow the function information at the top of >the page. Jumping straight to the user snippets is a mistake as they >are user contributed and may not document the whole function. > >int imagejpeg ( resource image [, string filename [, int quality]]) > > >imagejpeg($im,'myfile.jpg',80); [snip] This will save the image at the server - he wants the browser to present the "Save As" dialog... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] imagejpeg and downloading images
At 17:40 11.03.2003, Doug Coning said: [snip] >header('Content-Type: image/jpeg'); >$im = imagecreatefromjpeg("001_SM77GR.jpg"); >imagejpeg($im,'',85); >imagedestroy($im); > >I copied this code from PHP.net. However, when I run the above code, it >doesn't download the image, it just shows the image in the browser. I'm >using IE 6 for my browser. > >How I get PHP to download this image? [snip] To have a browser handling data it receives as downloadable file you must set a Content-Type it cannot handle inline, and specify a disposition and filename, such as: Content-Type: application/octet-stream Content-Disposition: attachment;filename="myfile.jpg" Content-Length: 1234 Note that it is always a good idea to tell the browser the size of a file it is about to receive. Since imagejpeg() outputs the stream directly and doesn't giv you any size information, you may use output buffering to obtain the stream, like: ob_start(); imagejpeg($im, '', 85); $image_size = ob_get_length(); $imgstream = ob_get_contents(); ob_end_clean(); // continue as outlined above header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment;filename="myfile.jpg"'); header('Content-Length: ' . $image_size); echo $imgstream; exit; -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] seperate streetname from number
At 17:17 11.03.2003, André Sannerholt said: [snip] >If for example >$variable="Hauptstraße 15"; > >$variable_string[0] should be "Hauptstraße" >$variable_string[1] should be "15" > >So I need a function that recognizes a number and explodes the variable at >that very position. >It's important that the thing also works when $variable="Hauptstraße15"; >without any space. Else it would have been easy to do with the explode >function... [snip] try a preg_match like (untested): if (preg_match('/^\s*([^0-9]*)\s*([0-9].*)\s*$/', $address, $aresult)) { $address = $aresult[1]; $number = $aresult[2]; } else { $address = trim($address); $number = null; } Note that preg_match will return false here if no number is available in $address. Leading and trailing spaces are trimmed from $address and $number, either by the regular expression, or by the trim() function in case of a no-match. Note also that this will fail for US-style addresses like "9th street", moving everything in $number, leaving $address empty. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ok now my sessions are *not* timing out
At 14:38 11.03.2003, freaky deaky said: [snip] >the js looks like: > >
Re: [PHP] Reading files over SSL using fopen or fsockopen
At 14:35 11.03.2003, Dan Mullen said: [snip] >I am trying to read the contents of a file using fopen or fsockopen over a >secure SSL connection. I have a script working fine over a non-SSL >connection, but it just won't work over SSL. I have tried using fsockopen >with the port set to 443, (I have checked this and the file I am trying to >read is on a server where the secure port is set to 443). > >I am using PHP 4.3.0 on a Linux machine with OpenSSL installed. Has anyone >got any ideas how I might be able to get this working? If it's not possible >to read files over SSL using PHP, I will need to come up with another >solution pretty quickly, so any help is much appreciated. [snip] You can't simply do a read on port 443, you need to make an SSL connection - there's a lot more to it that just changing ports. Have a look at cURL - this will get you the task done, without effort. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pop top off a multi dimensional array
At 10:30 11.03.2003, Diana Castillo said: [snip] >If I have a multi dimension array like this: >Array ( [provider] => Array ( [0] => 3 [1] => 2 [2] => 4 [3] => 1 ) >[priority] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) >how do I take off the top elements so I will only have three providers and >three priorities left? >If I do array_shift, it takes off all of the providers. [snip] You need to handle all subarray separately. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] newbie: contents will not output
At 04:22 11.03.2003, Anthony Ritter said: [snip] >I'm trying to test the following script to display the contents of the >following URL but it will not output. > >Any advice will be greatly appreciated. >Thank you. >Tony Ritter >... > >http://www.weather.com";, "r"); $contents = >fread($file_handler, filesize($file)); fclose($file_handler); echo >$contents; ?> [snip] You cannot stat() (i.e. use filesize()) a remote file, filesize() will return false making your script read 0 (zero) bytes. When reading remote files you may consider chunking them: $fh = fopen('http://www.weather.com', 'r'); if ($fh) { while ($chunk = fread($fh, 4096)) echo $chunk; fclose($fh); } This will work perfectly (if url-fopen-wrapper is enabled in your build anyway). -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ob_start -- output buffer problem
At 11:22 09.03.2003, Alex Lance said: [snip] >here's my example: > > >$x = new test(); > >echo "hey"; > >// IF next line is uncommented so it manually flushes >// then the finish method WILL get called. But I need >// get around calling anything at the *end* of a script. > >//ob_end_flush(); > > >class test { > ...etc [snip] This won't work anyway since your class test is declared after using it - it should be the other way 'round: class test {} $x = new test(); -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] array question
At 16:35 10.03.2003, Jason Wong said: [snip] >Not very elegant -- there must be a better way? > >foreach ($doo as $key => $value) { > print "Key:$key Value:$value"; > break; >} [snip] Possibly using array_keys()? $keys = array_keys($doo); echo "First key is \"{$keys[0]}\""; array_keys() comes in handy if you want to have random access to an associtive array without knowing the keys. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Displaying a file
At 03:17 10.03.2003, Todd Cary said: [snip] >I want to display a file under program control in the same manner as one >would with using an >a> tag e.g. > >Click Target="_blank">here to open the Race Schedule > >In other words, if certain conditions are met, then I want to display >the file. What is the best way to do that? [snip] Have a look at http://www.vogelsinger.at/protected.html. If you can't use this little gadget I'm sure there's a lot of information in it how to serve any file under program control. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] true, false
At 23:37 09.03.2003, Liam Gibbs said: [snip] >Why is it the following code produces nothing? > >$responsesubmitted = FALSE; >print($responsesubmitted); > >I have an if statement that says if($responsesubmitted), but it doesn't work. [snip] because $responsesubmitted is false :) A "false" value is "empty", while true is "1" in PHP-speech (contrary to languages like C where false is defined either being "!true" or "0". In case the execution block after your if-statement doesn't get executed this construction works just as it should. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Syntax query
At 13:38 09.03.2003, Nik Makepeace said: [snip] >Can anyone tell me why this doesn't work: > >$db_object = pg_fetch_object($this->getLastResult()); > >In imaginary interactive mode, it works like this: > >ME > echo $this->getLastResult(); >PHP> Resource id #67 >ME > echo $this->mr_lastResult; >PHP> Resource id #67 >ME > echo pg_fetch_object($this->getLastResult()); >PHP> >ME > echo pg_fetch_object($this->mr_lastResult); >PHP> > >Any ideas? [snip] From the docs: pg_fetch_object() returns an object with properties that correspond to the fetched row. It returns FALSE if there are no more rows or error. The behaviour of your code is expected if you looped either past the returned records, or there are no records returned by the previous query. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Undefined, even when global?
At 01:53 09.03.2003, Ron Biggs said: [snip] >You are a god among men, Ernest. THANK YOU! [snip] Bless you :) Nope. You're welcome, -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Array - Newbie question
At 01:47 09.03.2003, John Taylor-Johnston said: [snip] >New at this, somewhat: > >#http://www.php.net/manual/en/ref.array.php >$EricCodesArray = array ( >"CO" => "Description", "Input Name", "Select Name", "Option Name", >"Option Selected", >"AN" => "ERIC Number", "EricAN", "SelAN", "AN", "AN «Annotation»", >"TI" => "Title", "EricTI", "SelTI", "BT", "BT «Book Title»" >); This won't run I believe... Code it like this: $EricCodesArray = array ( "CO" => array("Description", "Input Name", "Select Name", "Option Name", "Option Selected",), "AN" => array("ERIC Number", "EricAN", "SelAN", "AN", "AN «Annotation»",), "TI" => array("Title", "EricTI", "SelTI", "BT", "BT «Book Title»",), ); Then you may reference an element within a subarray: echo $EricCodesArray['TI'][2]; //should display "SelTi" Note that non-numeric array indices (a.k.a. associative arrays) a) should always be quoted, and b) are case sensitive. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] phorm (PHPMail) script setup problem...
At 01:17 09.03.2003, Dan Sabo said: [snip] ># This variable indicates that a local config file is NOT required. > $PHORM_RCONFIG = "N"; [snip] Not that I'd know _anything_ of Phorm, but in my first sight of your post I thought "RCONFIG" would mean "remote config", and if set to "no" this would mean to use a local config? Just an idea of an absolute outsider... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] no phun intended!!!
At 23:11 08.03.2003, Chris Knipe said: [snip] >http://www.fingers.co.za/arb/mod_perl.jpg > >If this starts a flame war, I'm going to be rather disappointed at people >that's not able to take a joke :P > >I think it's hilarious though... [snip] Hmm. Quite nice girls I'd say. But I'm sure they have better things in mind than to fuck just mod_perl... Would like to have them round my office anyway (esp. the dark one in the background). *sigh* -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Undefined, even when global?
At 01:28 09.03.2003, Ron Biggs said: [snip] >function ColorCollection($lkID){ > > $whatX = $lkID + 1; // Adding 1 turns makes the index correspond to the >template number. > >// $aColLen = count($lkColor); //.length > $aColLen = test; //sizeof($lkColor); //.length > > echo "xxx\n"; //first option is blank > >// KeepGoing: //PHP does not have a line-label statement. Set up a trigger > for($i=0;$i<$aColLen;$i++){ > $trigger = false; > $whatglass = $lkColor[$i]->glass; //shouldn't $lkColor[any-number] be >global??? <<<<<<<<<<< [snip] Yes it _is_ global, but within the function you need to declare if global to have access to it, if you miss this you're referencing a local variable, which is not defined... function ColorCollection($lkID){ global $lkColor; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $whatX = $lkID + 1; // Adding 1 turns makes the index correspond to the template number. // $aColLen = count($lkColor); //.length $aColLen = test; //sizeof($lkColor); //.length echo "xxx\n"; //first option is blank // KeepGoing: //PHP does not have a line-label statement. Set up a trigger for($i=0;$i<$aColLen;$i++){ $trigger = false; $whatglass = $lkColor[$i]->glass; //shouldn't $lkColor[any-number] be global??? -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] save to file
At 00:30 09.03.2003, Ryan Holowaychuk said: [snip] >So right now the implode puts everything on one line in the text file!!! > >So I am no sure if anybody can shed some light on this one. > >Thanks again >Ryan > >//create a new file > $fp = fopen("/place/on/server/" . $HTTP_POST_VARS['team'] , "w"); > > $file_data = implode("\t\", $_POST); >//this would return values spit by tabs >//write to the open file handle > fwrite($fp, $file_data . "\r\n"); >//close the file > fclose($fp); [snip] The implode statement will indeed create a single line, that's what you tell it to do... if you want a line per value, you need to specify the newline separator, such as implode("\n", $_POST); Or am I off topic? -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file_exists() question
At 22:40 08.03.2003, Khalid El-Kary said: [snip] >because you can't directly use the $annrow[id] within single quotes, you >should use double quotes to do so. > >file_exists("cherpdocs/$annrow[id].doc") > >or > >file_exists('cherpdocs/'.$annrow[id].'.doc') > >or > >file_exists("cherpdocs/".$annrow[id].".doc") > >Note: i heared it's prefered to always use the "." when including variables >within strings. [snip] Hmm - that's a bit different. 1) You can't use variables in singlequoted strings - these don't get parsed by PHP. 2) You can absolutely use variables in doublequoted strings as these do get parsed. 3) Array indices and object references must be enclosed in curly brackets when used within double quotes to tell PHP what the variable and what the string text is. Example: "cherpdocs/$annrow[id].doc" <== doesn't work correctly "cherpdocs/{$annrow['id']}.doc" <== will work "cherpdocs/$object->docname.doc" <== will not work "cherpdocs/{$object->docname}.doc" <== will work Note that you should quote non-numeric array indices to allow PHP to recognize it's not a defined value. Omitting quotes for index data would trigger a warning (something like 'using unknown identifier id, assuming "id"'). -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Deleting Files
At 19:14 08.03.2003, Vernon said: [snip] >I need to have files that exist within a folder on my server based on the a >MySQL record that contains it's name. What command would I be looking for in >the php functions list? Anyone? [snip] Sorry, just saw you wanted to DELETE the files... It's "unlink($filename);" Note you need to have write access to the directory (not only the file) to delete it. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Deleting Files
At 19:14 08.03.2003, Vernon said: [snip] >I need to have files that exist within a folder on my server based on the a >MySQL record that contains it's name. What command would I be looking for in >the php functions list? Anyone? [snip] file_exists($filename); -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Really simple question - /php directory above /web tree .htaccess contents
At 17:58 08.03.2003, news.php.net said: [snip] >I want to have the /php directory >one directory above the /web root >so it is not accessible from browser command line execution but >will execute from a click on an >html page. CGI-PHP is installed >but I need to know the .htaccess >contents for the /cgi/php directory Of course this is possible. You just cannot directly run any PHP script by URL if it's located outside the web root, but you could easily use stub files running that part of the application you wish to use. I assume you have some libraries that you'd like to include in your stub files: -- stub.php So there's no real need for an .htaccess-based blocker. However here's what you need in .htaccess )line numbers only for explanation below): 1 AuthName "The name of your realm" 2 AuthType Basic 3 AuthUserFile /etc/httpd/.htpasswd 4 AuthGroupFile /etc/httpd/.htgroup 5 Require group authorized_users 6 Order deny,allow 7 Deny from all 8 Allow from 10.10.10.0/24 9 Allow from ##.##.##.## 10 Satisfy any Explanation: 1 - This is the text that will appear on the authentication dialog at the clients side. 2 - There are others (like NTLM) but I don't have any experience using them. Take care that "Basic" doesn't provide any encryption of transmitted UserID/Passwords; it just Base64-encodes it. 3 - Where the password file is located. It may be anywhere, even outside the web root, as long as it is readable by Apache. You create and maintain the .htpasswd file using the htpasswd command line utility. 4 - Optional; contains user groups. Maintained by text editor. Format: group: user user user group: user user user 5 - Names of user groups that may access the ddirectory. You may as well use Require user user-id user-id if you don't support groups. 6 - Order of ACL check (http://httpd.apache.org/docs/mod/mod_access.html#order) 7 - Deny all hosts and users (checked first, see 6) 8 - Allow from the internal network (example, not required) 9 - Allow from any other IP or subnet (example, not required) 10 - http://httpd.apache.org/docs/mod/core.html#satisfy Allow access if _any_ of the above restrictions is met. If you specify Satisfy all the above example would never allow access since no host can be on different addresses... Note that "AllowOverride AuthConfig" must be set in the server or virtual host definition if authentication is to be used via .htaccess. The authentication directives can be used in the server config at the level, or in the .htaccess file. Formore info on Apache directives read http://httpd.apache.org/docs/mod/directives.html. HTH, -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Mining a file for data
Dear Hugh, please don't use background colors. Black text on darkblue background is definetely hard to decipher. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP removing data...
At 17:12 08.03.2003, Doug Coning said: [snip] >Hi all, > >I'm trying to save a text file from my server to a client machine through >PHP and am using the following headers: > >header("Content-type: application/text"); >header("Content-Disposition: attachment; filename=variables.txt"); > >The header does save a text file from the server to my desktop alright, but >it strips everything in the text file. I have a file named variables.txt >with nothing in it. I have uploaded a text file that does have test data in >it. Furthermore, I set all the user rights in Unix to Read / Write/Execute >but everytime PHP opens or saves it, it does so without any of the variables >I've entered. [snip] Try to add the Content-length header and see if this resolves your problem: header("Content-type: application/text"); header('Content-Disposition: attachment; filename="variables.txt"'); header('Content-Length: ' . strlen($contents)); I made a habit to send the "filename" part in double quotes - some user agents seem to require this although it's not required by RFC (RFC822, RFC2183). Since doing this it always works for me :) -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
php-general@lists.php.net
At 08:04 08.03.2003, James Taylor said: [snip] >Where can I read more about this? I'm not sure that I understand why 4 >& 4 == 4. [snip] Bitwise comparison means just that, i.e. comparing two numbers bit by bit. Any number is represented by a bit combination (this has technical reasons - if a single "wire" has some electric potential set it's "1", if not it's "0" (or is it the other way round? Can't remember...). A single "Byte" is comprised of 8 such lines, each line representig a "Bit" with increasing value. To read this correctly you need to have a monospaced font: line number 7 6 5 4 3 2 1 0 | | | | | | | | | | | | | | | | line value 7 6 5 4 3 2 1 0 as power of 2: 2 2 2 2 2 2 2 2 dec. value: 128 64 32 16 8 4 2 1 Taking this, the decimal number "4" would look 0100 written in binary notation. Ok, now let's bitwise AND 4 and 4, walking bits left to right. If both bits are set the resulting bit is also set (for an AND operation), if one or both bits are not set this yields a zero bit: 0 & 0 => 0 0 & 0 => 0 0 & 0 => 0 0 & 0 => 0 0 & 0 => 0 1 & 1 => 1 0 & 0 => 0 0 & 0 => 0 I hope it seems logical that the result of bitwise ANDing a number to itself always will result in the same number... There are a couple of bitwise operators: & (AND): the result contains bits set in both operands | (OR): the result contains bits set in either operand ^ (XOR): the result contains bits set in either one or the other operand, but not in both (0 ^ 1 = 1, 1 ^ 0 = 1, 1 ^ 1 = 0, 0 ^ 0 = 0) Unary operands: ~ (NOT) reverses all bits of the single operand, e.g.; ~4 => 251 (~ 0100 => 1011) Bit-Shift operators move the bits of a number to the left or right: << left shift ($a << $b means shift bits of $a $b-times to the left) e.g. 4 << 1 = 8 (0000 0100 << 1 = 0000 1000) >> right shift ($a >> $b means shift bits of $a $b-times to the right) e.g. 4 >> 1 = 2 ( 0100 >> 1 = 0010) HTH, -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
php-general@lists.php.net
At 05:54 08.03.2003, James Taylor said: [snip] >Ok, this may have already been posted to the list already, but the >archives don't seem to like the & and && characters. > >I'm running into some code that looks like this: > > >Define('INPUT', 2); > >if($search->level & INPUT) $tmp.= $search->input(); > > >Ok, what's the & mean? > >As far as I could tell from the very little documentation I was able to >scrape up on google, & is a bit-by-bit operator. Thus, if either INPUT >or $search->level, we get TRUE... If that's the case, what's the point >of using it instead of || ? [snip] These are two totally different operators: & - bitwise AND && - logical AND So: 5 && 2 yields true 5 & 2 yields 0 In your example we would need to know the value of INPUT - it is most certainly one of 1, 2, 4, 8, etc, denoting a single bit. So the expression $search->level & INPUT would yield nonzero (a.k.a. true) if the bit denoted by INPUT was set in $search->level. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Executing PHP code in a database
At 06:15 08.03.2003, Leo Spalteholz said: [snip] >I have a table that stores all the "boxes" that my website will >display on the sides. So far the content is simply stored in a text >field and then substituted for the box body. However this way I >can't have any php code in the boxes... What I thought I could do is >have another field that will contain any php code that I want for >that box and then execute that after I read it from the database. > >So I have two questions basically. >1. How would I go about executing php code in a string? >Say I have $code = "md5('blah');" how would I execute the code in >the string? To execute any code contained within a string you need to eval() it. Assuming you have this piece of code $uname = 'Leo'; $text = "Hello there, "; eval("?>$text2. If I instead include a file would it have access tio the local >variables? > >Ie. In a class I have this: >$strContent = "blah, this is the content I got from the database"; >include("includefilefromdatabase.php"); > >Is the $strContent variable then available from the include file? Yes. See http://www.vogelsinger.at/test.php for an example (will be available for 1-2 days). -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] $PHPSESSID
At 05:45 08.03.2003, Liam Gibbs said: [snip] >Here's the newest brain teaser: I have cookies disabled (well, I have IE set >to the highest security mode, where it disables cookies). I understand that >with cookies enabled, $PHPSESSID will return nothing when it works. However, >it will return a value when cookies are disabled and the page is refreshed >after a cookie is attempted. I'm still getting nothing either way. Anybody >know why? [snip] You mean the SID constant I assume. This constant is only defined if the client didn't send the right cookie. There's no global variable holding the session identifier - you can use session_id() to retrieve (and set!) the current session identifier, and session_name() to retrieve (and set!) the name of the session (which usually is PHPSESSIONID). For further information check out http://www.php.net/manual/en/ref.session.php. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] require_once adds a "1"
At 20:19 07.03.2003, Gary said: [snip] >Thanks for your response James! >but still I must be doing something wrong the "1" is a persistent little >bugger. Have you any tips on how to rewrite: > >echo @ require_once("topten.php"); > ?> >using the ob_methods? [snip] Rewrite this to just require_once('topten.php'); No need to echo here. Using output buffering the 1 would still appear, some microseconds later... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] require_once adds a "1"
At 17:28 07.03.2003, Gary spoke out and said: [snip] >Hi >I've included the following in a php document: >echo @ require_once("anyfile.php") >> >and it works exactly as I expect except at the end of the included document >theres a single "1" displayed. I've noticed also that if I include a >document in the included document the end result will be the document I want >exactly as I want it with the addition of two ones "11"s can anyone tell me >how to get rid of the ones? >(if I run anyfile.php by itself there are no "1"s) [snip] This happens if the included file returns some value, in your case it seems to return "true". Remove the return statement (you may simply "return;" if necessary) and the 1 will be history. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] attaching php-action to form-button
At 12:59 07.03.2003, Michiel van Heusden said: [snip] >I have some variables defined which i'm sending through get > > >// input's etc > > >now I have $var1 defined in my PHP and I want to send it through that GET as >well >is there a way to do this? > >so it's not a user-defined but php-defined var, which i need to send through >the form [snip] use a hidden field: // input's etc -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Search for keyword in txt file
At 11:36 07.03.2003, Chris Blake said: [snip] >Ok, it`s not that easy..here`s my code...I wanna search all the >files in the "logs" directory and for each file found I want it to >search for the word "started" and print that line into a table row. > >I will probably need to do like a "for each" loopbut where do I >insert it ? [snip] In case you're _not_ in safe mode: $result = `grep -n started logs/*`; -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dollar signs in values
At 06:58 07.03.2003, Liam Gibbs said: [snip] >How is it I can properly get PHP to represent dollar signs when putting it >into HTML? > >I know that dollar signs denote the beginning of a variable, like $reference >or $ftpstream or whatever. However, I have a text file that contains (or can >contain) values with $ in them. When I open the file and grab those values, >then stick them onto my HTML page, they get unpredictable results. Is there >a way I can escape them or such? [snip] Escape them with a backslash: $text = "The amount is \$400.-"; -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Login via PHP: Protecting files and directories
Hi all, since this has been asked a lot the last weeks I've published a nice little script for a generic login system using the HTTP authentication method via the "401 Unauthorized" header. It is available at http://www.vogelsinger.at/protected.html. Its main features are: - Protects directories - Protects single files in directories that are otherwise not protected, even in the server root folder - Supports multiple "realms" on a directory level - Supports multiple document types by matching a document extension to the correct MIME type - Supports inline display and downloadable files configurable by extension - Supports multiple users with different privileges, on a directory level - Privileges are inherited for subdirectories except when overridden - Standard HTTP Authentication Mechanism - It is not necessary to develop an integrated login system - Supports execution of PHP scripts under the "protected root"! The basic idea is to setup a "shadow tree", outside the web servers directory tree. For example: Web server Shadow tree / (root) / (root) /--public_files/--protected_files /--images /--images By placing a document in the root directory of the shadow tree it will be protected by a login, while still accessible via the standard url http://yourserver/thefile. The same is true for the /images folder; the /protected_folder directory would be protected as a whole. The script works as an error document for the "404 Not Found" error and has been tested with Apache 1.3.27/PHP 4.2.3. User authentication may be freely configured; the script must be modified here to meet the demands of each user. Yes, of course, if a document is effectively not found it serves a standard 404 error... Donated to the public domain :) For support just email me ... I'll try to answer questions whenever I have time. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] print "$array[$i][0]" pukes
At 10:44 06.03.2003, David T-G said: [snip] >...and then Leif K-Brooks said... >% >% print "$i :: {$manilist[$i][0]}\n"; >Aha! Perfect. Here I'd been trying such things with the leading $ on >the *outside* of the braces. [snip] Try to see it this way: $manilist[$i][0] is a PHP expression, thus needs to be put in curly braces _as_a_whole_ within a string. It doesn't hurt to use curly quotes even if they're not necessary - it's just the same as with using brackets in expression to clarify operator precedence: with brackets, you don't have to fear any performance impact and gain the clarity of the evaluation sequence; with curly quotes, you gain the correct result :-) -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Compiling PHP5 In Linux
At 04:55 05.03.2003, Clete Rivers Blackwell 2 said: [snip] >I have RedHat 8.0 with the everything box checked in packages... when I >build the CVS of PHP5, it tells me that tempnam is dangerous and to use >makename or something... I think it's a code bug, but just in case, does >anyone know if this is due to an outdated version of some program? [snip] No, I don't think so - this warning is also generated for 4.2.something. It is a warning from gcc about a possibly insecure implementation of the tempnam() function where a race condition could occur. There are some interesting answers to this questions on google - search for "tempnam dangerous". -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] file uploads
At 19:55 04.03.2003, Joseph Bannon spoke out and said: [snip] >Regarding file uploads... > >1) Do the temp files automatically delete, or do I >need to put something in the code to delete them? > >2) If automatically, how long? Where can I set the >length of time until they are deleted? > >3) If not, is there a place I can make it be >automatic? [snip] As far as I know (not 100% sure, though...): 1) yes, they do; no, you don't 2) they're deleted by move_uploaded_file(), or when your script exits 3) n/a -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php forgetting variables very easily
At 19:37 04.03.2003, Ian A. Gray spoke out and said: [snip] >Hi everyone.I am probably doing something obviously >wrong but I can't seem to sort it! It's regarding >variables.In one script, lets call it main.php I make >a variable- say $colour. It inludes a file which >prints the variable: > >main.php >$colour = 'green'; >include('new.php') >?> > >new.php >echo $colour >?> > >Ok, this works fine for me. However it doesn't seem >to work when main.php and new.php have html in them. >The variable seems to be lost and new.php prints >nothing. Has anyone got any words of wisdom on this? >It may help if I actually showed the two pages here, >but they are long and I thought it would be a waste of >space. [snip] in main.php, try to make $colour global: main.php new.php This seems to me like an inconsistency within PHP as to when variables are "automagically" available, and when you have to declare them global. However you should avoid using globals anyway... -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Doing a Multiple Search
At 14:50 04.03.2003, Hunter, Jess spoke out and said: [snip] >Here is the Base Line I am working with: > >$Query="SELECT * from $TableName WHERE lastname='$Array[lastname] AND >firstname='$Array[firstname]' "; > >What I ant to be able to do is a search on both the lastname and the >firstname so if someone just puts in the last name it will display all >people with the queried last name regardless of the first name. So for the >visual representation [snip] $query = "select * from $tablename where " . (!empty($array['lastname']) ? "lastname = '{$array['lastname']}' " . (!empty($array['firstname']) ? 'and ' : null) : null) . (!empty($array['firstname']) ? "firstname = '{$array['firstname']}'" ; null); Note that you need to put curly braces around an array dereference if you have it in a quoted string. This doesn't work: $s = "Some $array[sample]"; But this works: $s = "Some {$array['sample']}"; -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP OOP design question
At 14:24 04.03.2003, Joseph Szobody spoke out and said: [snip] >I have several web projects that are all database driven. I have recently >been diving into OOP, and rewriting a lot of procedural code in OOP. I have >a design question about handling the MySQL connection. > >I have a mysql() class which handles all my queries, automatic >inserts/updates, etc. Just about every other class will use the mysql() >class at some point. > >Should I > >1) Make every class extend mysql(), so that they all have direct access to >the db functions I wouldn't do that. First of all this would counterfeit the OOP goodies of encapsulating the actual implementation, i.e. your MySQL class wouldn't be the "transparent blöackbox" it ought to be. >2) Create a new mysql object inside of each class. That's a better way but you need to manage the database connection to avoid repeated reconnects... only way if to make it "class static". >3) Only create the mysql object at the script level, and pass in the object >to the other classes. This would be my choice and is exactly what I'm doing, not only for database objects but for all other objects I'm using. This is my approach: I have a centralized object storage. No global variables, only a couple of public functions. For example, the function (note: not a method) "pos_getobject" returns a reference (!) to any object. If it doesn't exist it will be created. The syntax is: $hObj =& pos_getobject($id); where "$id" is the object ID. This ID could be either a constant (e.g. OBJID_DATABASE), or an ID referencing a database-persistent object. In my case, object ID's that are negative numbers are predefined objects (e.g. OBJID_DATABASE), positive numbers are DB persistent objects (simply the row-ID where the object header can be retrieved), and non-numeric IDs are temporary objects that may be created at runtime. If you don't need to take such a general approach I'd create a public function to retrieve the database object: $hDB =& pos_getDB($dbid); where $dbid is a database identifier in case you need it. Just my 2c, -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Populate var with function output string?
At 04:56 04.03.2003, CF High said: [snip] >Hey all. > >Is it possible to populate a var with an output string generated by a >function? So: > >*** >function write_string(count) { > >for ($x = 0; $x < $count; $x++) { > > echo " Row $x"; > >} > >} > >$my_string = write_string(5); > >echo $my_string; >*** > >I need $count option elements stored in $my_string. How to make this happen. [snip] You might use output buffering: ob_start; write_string(5); $my_string = ob_get_buffer(); ob_end_clean(); Output buffering is stackable, i.e. the above code will work even if you have ob turned on already. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] eval help
At 14:47 03.03.2003, neko said: [snip] >$someVar = "testing for node - wootah, \$evalTestArr[TAG_PAGENAME]" > > >then in some other function that gets passed this string >... > >$evalTestArr[TAG_PAGENAME] = "hello anna marie gooberfish!"; >$str = $someVar; >eval("\$str=\"$str\";"); > >if I echo it out, the substitution is not done. [snip] try $someVar = "testing for node - wootah, \{\$evalTestArr[TAG_PAGENAME]\}" Array derefs within quoted strings must be enclosed in curly quotes. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php as php3 perhaps with htaccess
At 11:29 03.03.2003, Cranky said: [snip] >Thanks for this reply. >But I can not use the mod-rewrite because my site is on a shared hosting. > >Another idea ? [snip] Ask your sysadmin to install the mod-rewrite for your site to the configuration. They should do this without asking too much ... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem using extension.
At 10:35 03.03.2003, Joe Wong said: [snip] > My last posting was interrupted. The details are here: > >I have created an extension on top of a C++ library >If I put the module name into php.ini extension=XYZ, apache failed to load >If I try to use 'dl' to load the libary in a PHP page, I got 'child exist >segementation fault' in /var/log/httpd/error_log > >I am sure the C++ library is running ok as I have a test program that make >use of it. I just don't know how I can make it work with PHP.. [snip] Sounds as if there was some problem in the extensions initialization code. I'd try to put some debugging in there (write to a file, flush and close it) so you can see how far your extension executes until the segfault. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php as php3 perhaps with htaccess
At 10:21 03.03.2003, Cranky said: [snip] >I have a website and all my files are *.php3 >I would like to change the extensions of all files to *.php > >So I would like to know if there is a way perhaps with a .htaccess file to >say that the file .php3 must be redirect to the same file but in *.php > >So when I try to access this page : >http://www.my-site.com/page.php3?param=value > >I will access this page : >http://www.my-site.com/page.php?param=value [snip] If you have the ability to use mod-rewrite, you can do RewriteEngine On RewriteCond %{REQUEST_URI} ^.*\.php3.*$ [NC] RewriteRule ^(.*)\.php3(.*)$ $1.php$2 [L] This can be done either in the general configuration, within , or within . I am using exactly this stuff to allow legacy links to a site that has been developed in Python (*.py) to access the same URLs as PHP files. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problem using extension.
At 09:49 03.03.2003, Joe Wong said: [snip] >Hello, > > I have some problem using an extension written by myself. Here are the >details: > >OS. RedHat 7.2 >Apache: 1.3.20-16 (out of the box version ) >PHP 4.3.0 compiled with: [snip] Uh yes - we have problems too, sometimes. Care to tell us about _your_ problem? -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fread problem
At 05:46 03.03.2003, Paul Cohen said: [snip] >Here is the code in my file and was taken directly from the manual: > >$filename = "test.php"; >$handle = fopen ($filename, "r"); >$contents = fread ($handle, filesize ($filename)); >fclose ($handle); >echo $contents; [snip] You need to eval your code (not "exec"): eval($contents); Note that $contents need to be valid PHP for eval(). It must not start with "Some HTMLBlah you should eval("?>$contentsO Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] heredoc problem
At 23:02 02.03.2003, [EMAIL PROTECTED] said: [snip] >Can someone tell me what is wrong with the following code: > >This is code straight out of the PHP manual. I get the error: >Parse error: parse error, unexpected T_SL in testhere.php on line 5 > >I looked up T_SL and it is a token representing << so that means it just >doesn't get the <<<. Why not? I've tried all the combinations of spaces and >no space in that line that I can think of. [snip]---- The correct heredoc syntax: $text = <<O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php and html differences
At 21:54 02.03.2003, Sunfire said: [snip] >well i told him it was probably java or something of the sort cuz he uses >java in his pages sometimes expecially when it comes to buttons or something right, you can do some logic with JavaScript (don't confuse that with Java please!). There's a big BUT there - you can never be sure the client browser gets it right, be it because JS is switched off, or some malicious guy tries to trick your application. >oh well he said that frames are good for the sighted people because it makes >things easier to find and makes the page look better...is this true or are >frames just utterly useless? Layout is a matter of taste, there's no final judgement about this, I believe. I don't really like your particular layout of the site for two reasons: - the graphics render horribly (still alpha, going to be better?) - the list scrolls endlessly - there must be a better way to display records found That doesn't mean that frames are the way to go - usually frames make a site more complicated from a technical view. With languages like PHP it's very easy to generate good-looking pages that are easy to navigate - start your thoughts by trying to separate data and logic from presentation. >btw i am also totally blind using jaws for windows and even though i have >great concepts of where to put stuff on pages he is telling me its all wrong >visually and it needs to be redone so he told me where to put stuff and i >had to move everything around on it.. If he's the boss you should do what he wants; if you believe you have a better concept try to make an alternative presentation. >sorry if this starting to fall outside php line but as far as php goes i >think its important things to concider in my php/sql programming life.. >i know im not talking direct code but i do need to know if i have layout >problems or if the guy is taking his sight for granted... Presentation doesn't have anything to do with web programming - that's the HTML stuff. It's just composed by your application. Have a look at some template engines like Smarty to get an idea. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php and html differences
At 21:25 02.03.2003, Sunfire said: [snip] >i guess this is a php related question (well sort of) the person i work >with decided that he was going to edit a few of my php scripts that make a ... oh my god. >he told me a few things that i dont quite understand (or for that matter i >dont belive what he says is really true).. >he said: >1. on the instance about testing certain conditions to determine what page >to show..frames or a frameset can do exactly the same thing...i told him no >it didnt (who is right?) Framesets are HTML constructs to divide a browser window in adjacent areas to display more than one page at the same time. There's nothing what a frameset construct can do to implement any logic - the page that's shown in a frame is available in the "src" tag. >2. he asked me in the scripts that have 3 or more pages built into them how >was the logo at the top of the page being shown.. i just told him that i >used normal html and put the logo at the top of the pages.. he said frames >wont let you do that (who is right??) Not within the frameset, of course... if you have a frameset you don't have a body, that's it. >so im confused about that one.. he also said that plain html had an if else >statement in it.. i never heard of such a thing... Never heard such bullshit. >can somebody get me unconfused? and is it not really a good idea to have 3 >or more pages built inside a php script? should the pages be called from the >script some way else? Boy - some of my applicatinos server a couple of hundred pages out of a single script (from the database, that is)... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] browser uploading
At 12:35 02.03.2003, joe said: [snip] >i am operating on safe mode and i need to figure out, how to upload files >with php through your browser. copy() is disabled for sure, im not >absolutsely sure about other functions. i have heard that it is actually >possible but so far i haven't been able to figure out how.. [snip] check out move_uploaded_file(): http://www.php.net/manual/en/function.move-uploaded-file.php safe_mode is covered in the docs, too. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] authentication question...
At 07:02 02.03.2003, Sunfire said: [snip] >basic question about www-authenticate header...(least i hop its simple) >i have the code: >header("WWW-Authenticate: basic realm='a realm'"); >header("HTTP/1.0 402 Unauthorized");//dont understand >//what this line does >echo "you didnt login yet\n"; //understand it but want >//something else like a header sent out... >dont understand what the second line is for and was wondering if that third >line that someone gets when you hit cancel can be turned into another >header? or is there a way to force a header block even if output has already >been put on the screen? [snip] To understand the header lines you need to have some basic knowledge of the HTTP protocol. Start eating tht HTTP RFC: http://www.w3.org/Protocols/rfc2616/rfc2616 This will also enlighten yo about the fact that a header cannot be senz after content has been pushed out. This said you can use output buffering (http://www.php.net/manual/en/function.ob-start.php) to avoid output being sent before the headers: Example: ob_start(); echo "some stuff"; // we decide to redirect the client ob_end_clean(); // clear the output buffer header('Location: http://somewhere.com'); HTH, -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripslashes()
At 04:03 02.03.2003, Dade Register said: [snip] >Thanx a lot for your help. >It adds to the .dat file. it's not fgets(). >Dade [EMAIL PROTECTED]'s >That's from the dat file. any other ideas? [snip] add this line vefore and after stripslashes() and see what you get: echo '', $poem, ''; If I type "I've set it up" it should read I\'ve set it up I've set it up or your stripslashes is not working. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripslashes()
At 03:37 02.03.2003, Dade Register said: [snip] >I know I am doing the exact thing you are If you >or someone else doesn't mind, could you look @ >http://dragonz-cavern.mine.nu/poems.phps and see what >I'm doing wrong? I am trying to parse it before it >gets stored in my txt file. plz help. I'd really >appreciate it. [snip] You're doing everything right. If you have a look at the datfile you'll notice there are NO backslashes. Right? Ok, so the culprit must be fgets() - and indeed this can be found in the online manual (http://www.php.net/manual/en/function.fgets.php), in the user comments: php at silisoftware dot com 13-Jun-2002 06:44 Beware of magic_quotes_runtime ! php.ini-recommended for PHP v4.2.1 (Windows) had magic_quotes_runtime set ON, and that addslash'd all input read via fgets() So the solution here is to either add stripslashes() after your datfile read, or to use set_magic_quotes_runtime(0) (see http://www.php.net/manual/en/function.set-magic-quotes-runtime.php). -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripslashes()
At 02:05 02.03.2003, Dade Register said: [snip] >Well, only diff is it's a POST from a textarea. With >magicquotes on, you're right, it makes "Thank's" >become "Thank\'s". how can I get rid of that? I'm >posting it to a text file. [snip] Use stripslashes(). Try this example: $REQUEST[\'blah\']: "', $var, "\"\n"; $var = stripslashes($var); echo 'stripslashe\'d: "', $var, '"'; echo '', '', $var, '', ''; ?> You will notice the textarea transmits "Thank\'s" which is displayed in the first line, and stripslashes() removes the backslash and displays "Thank's". Note that you also must use the stripslashe'd data when constructing the textarea. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripslashes()
At 01:48 02.03.2003, Dade Register said: [snip] >I know this is probably an easy question, but I am >using stripslashes() on a textarea var, and I don't >think it's working. It doesn't error, but in the >testarea it doesn't seem to work. Ex: > >$var = "Thank's"; >$var = stripslashes($var); >echo $var; >Output = Thank\'s [snip] This can't work since there are no slashes to strip... stripslashes() strips certain slashes from a string. Assume you have a textarea where the user enters "Thank's", so PHP converts this to "Thank\'s" (assuming magic_quotes is set to on). Using stripslashes() here will get rid of these slashes. BTW - the sample you've sent will output "Thank's" - what are you doing what you didn't show? -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Checking for HTTP:// at the start of a string and more ////
At 01:17 02.03.2003, Kris Jones said: [snip] >>Untested: >> >>if (preg_match('/^http:\/\/[^\.\s]+\.[^\s]+\/$/i', $string)) >>// valid string >>else >>// invalid string >> > >I've also been looking for this information. Can you please point me to a >list of those string codes? My search for them in the documentation has been >fruitless. [snip] It is all in the online manual. Start your studies at http://www.php.net/manual/en/ref.pcre.php Chapter LXXXVIII (read 88), titled "Regular Expression Functions (Perl compatible)", which are my favorites... pay special attention on these chapters: "Pattern Syntax" (http://www.php.net/manual/en/pcre.pattern.syntax.php) "Pattern Modifiers" (http://www.php.net/manual/en/pcre.pattern.modifiers.php) -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A few questions...
At 00:49 02.03.2003, The Head Sage said: [snip] >1. How can i set a script to run at a certain time? *nix: use cron (man crontab) Windows: use the "at" command (help at) >2. How do i open a HTML file, extract all the text and then break up the >text into variables.. > >For example, i've got a HTML files which all have the same structure > >>> >Title: Magocracy >Author: TheHeadSage >E-Mail: [EMAIL PROTECTED] >Category: Comedy, Action >Keywords: Ilja, Magic, Ilkeria >Rating: PG-13 >Spoilers: None, origional story. >Summary: [Sumary here] > >Chapter Body ><< > > >How would i get all the text and break it up into the variables $title, >$author, $email >ect. So they can be insterted into the MySQL table under the approprate >colums. Using the layout you are showing: 1) Read the file 2) Split headers from body (delimited by an empty line) 3) make an array from the headers, splitting each line by ': ' // Disclaimer: untested // step 1 $hf = fopen($file, 'r') or die("Can't read $file"); $buffer=fread($hf, filesize($hf)); fclose($hf); // step 2 - now you have the chapter ready list($headers, $chapter) = preg_split("/(\n|\r|\r\n|\n\r){2,2}/s", $buffer); // step 3 $headers = preg_split("/(\n|\r|\r\n|\n\r)/s", $headers); $arkeywords = array(); // for the "array" method, see below foreach ($headers as $line) { list($var, $value) = preg_split('/:\s*/', $line, 2); // you may rather use an associative array instead of variable names // the "variable" method: $$var = $value; // the "array" method $arkeywords[$var] = $value; } You now have the "body text" in "$chapter", and either an associative array, or the named variables of the header lines. >3. How do i open a Word Document and extract all the text? You might try Word2X (see http://word2x.sourceforge.net/) Disclaimer - never used it, just been told about it by my friend Google (question was "Winword conversion Linux"). >Thats all the questions so far, any tips, comments, ideas, questions even >insults and flames are welcome! Nothing else? Ok, you got something to work on now I believe... *grin* >- Daniel "TheHeadSage" Spain >Founder of Voidsoft. >Server Administrator of The Void ...hopefully not... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checking Access to a directory Via a PHP/MYSQL Databace.
At 21:12 01.03.2003, Philip J. Newman said: [snip] >Is there a way that i can restrict access to an entire directory using >PHP/MYSQL so only valid users in the Database can have access to a resource? [snip] 1) Put that folder outside the document root of your webserver so they cannot be retrieved by accessing their URL directly 2) After authenticating, server the files using readfile() or similar. You could even use the ErrorDocument directive in Apache to run this. Consider this deirectory layout: ~newmanpj/ + -- htdocs<== the web root (home of hidden_files.php) | + -- hidden_files <== an empty directory, only .htaccess available | + -- hidden_files <== the directory holding your files The .htaccess file within the hidden directory contains ErrorDocument 404 /hidden_files.php Now when a user requests http://www.newmanpj.com/hidden_files/somestuff.html, the hidden_files.php will be triggered by apache, having $_SERVER['REDIRECT_URL'] set to the requested URL. hidden_files.php does the following: 1) Check if the request is for a hidden file: No => serve a general 404 Error message Yes => continue 2) Check authentication: Not authenticated => goto login (or return 401 Authenticate) Yes - readfile(requested_file) Hope this helps, -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: FW: [PHP] Constants and "Here Document" Interpolation
At 19:28 01.03.2003, Daniel R. Hansen said: [snip] >Actually I did try it and couldn't think of a way to work around the matter. >Thanks for the suggestion. > >-Original Message----- >From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED] >You simply could have tried it - it's trivial. > > [blah] [snip] My apologies - by rereading my message it sounds straightforward arrogant which it wasn't meant to be. I was referring to your statement "didn't find anything in the online docs" that led me to the perception you didn't even try it - sorry for that (but there are so many posters asking questions that wouldn't even arise if they only had _tried_ it). Hope my suggestion helps though :-) -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Constants and "Here Document" Interpolation
At 16:56 01.03.2003, Daniel R. Hansen said: [snip] >Can anyone tell me if it is possible (and how) to use defined constants >within "here document" content? I've not been successful finding anything >on this in the online docs. [snip] You simply could have tried it - it's trivial. The answer: no, you cannot have a constant within a string, be it heredoc or quoted. A constant must always reside on "native code level". However you can easily concatenate strings and heredocs - both of the examples below work correctly: define('A_CONSTANT', 1); $text1 = <<$text2"; Output: This heredoc text contains the constant A_CONSTANT (1) outside the heredoc construct... This quoted text contains the constant A_CONSTANT (1) outside the string quotes... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IS there a way.
At 05:40 01.03.2003, Philip J. Newman said: [snip] > Is there a way to PING a URL and check if it returns a valid code like 200 >... ?? [snip] Ping doesn't return a "200 OK" code... If you want to check for the existence of a webserver at the given address you should try to read some data from it. To check the return code you need a tool to return the HTTP headers - check out cUrl (also supports SSL), or go on your own using fsockopen(). -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Checking for HTTP:// at the start of a string and more ////
At 05:09 01.03.2003, Philip J. Newman said: [snip] >I would like to check for HTTP:// at the start of a string and for at least >1 . and a / at the end of a string. > >I have tried ereg, but the documentation is not too clear how to format. [snip] Untested: if (preg_match('/^http:\/\/[^\.\s]+\.[^\s]+\/$/i', $string)) // valid string else // invalid string Should match a string beginning with 'http://', followed by one or more characters that are no dots or whitespace, followed by a dot, followed by one or more characters that are not whitespace, and terminated with a slash. The terminating 'i' makes the search case insensitive. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL Query Result Question
At 00:20 01.03.2003, Van Andel, Robbert said: [snip] >I have the following query: >$query = "SELECT d.utilization, d.capacity_date, d.day, i.id, i.interface, >cd.date, cd.id "; > $query .= "FROM (capacity_data as d LEFT JOIN interfaces as i ON >d.interface = i.id) "; > $query .= "LEFT JOIN capacity_date as cd ON d.capacity_date=cd.id "; > $query .= "WHERE i.router = '$cmts[$i]' AND cd.date >= '$useDate' "; > $query .= "ORDER BY i.interface,cd.date DESC"; > >if(!$result = mysql_query($query)) die(mysql_error()); > >while($data=mysql_fetch_array($query) >{ >//SSLT >} [snip] Simply setting $result=null after the loop should do, or am I off topic? if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($result)) { //SSLT } $result = null; // could also use // unset($result); -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing for < 0
At 19:28 28.02.2003, Steve Buehler spoke out and said: [snip] >I have a form that has input for minutes. My problem is that I am trying >to test to see if the field is blank or not and if they enter a "0" (zero), >my test always show it as blank. I have tried !$timemb and >!is_numeric($timemb). [snip] How about some code? -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can I detetct if session cookies are enabled?
At 17:52 28.02.2003, Don spoke out and said: [snip] >I have a site that requires a user to login in for extended function. The >site uses sessions. I note that if a user configures his/her browser block >all cookies, he/she will not be able to navigate the extended part of the >site. Is there a way (PHP code if possible please) to verify if session >cookies are enabled in the user's browser? [snip] First of all, if you have URL rewriting enabled (it is by default) any site should be transparently working regardless of the client's cookie settings, as far as sessions are concerned. That said - you can use the SID constant. SID contains either "PHPSESSIONID=###" if cookies are _DIS_abled, or is empty if cookies are _EN_abled: if (empty(SID)) // ok, go ahead else // issue a warning here Of course this only works after the first response of the client to the site where sessions are enabled. The SID will always contain the session key after starting the session for the very first time, thus the above code will always trigger the warning. -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] strip http headers
At 16:46 28.02.2003, Diana Castillo spoke out and said: [snip] >is there any predefined procedure to strip http headers from a response? [snip] A valid HTTP response is a MIME message comprised of two parts - the header block, and the data block. Both blocks are separated by a single empty newline. You can easily split them using something like this (untested): list(header, body) = preg_split("/(\r\n|\n\r|\r|\n){2,2}/s", $message, 2); This should catch all possible variations of newlines. The correct newline sequence afaik is "\r\n". -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sorting a file
At 16:41 28.02.2003, Beauford.2002 spoke out and said: [snip] >I have the file below which I need to sort by player and then rewrite it, >this file will then be used as part of another part of my input process on >my site. A couple of things. I am able to read the file into an array using >'file', I think, but I am not able to sort it. I have tried different >variatons of 'sort' and it doesn't do it properly. One other question >though, when I display the contents of the array in my browser, I only get >the players name and not the , I am assuming this is because >of the way IE has interpreted it and that the entire line did actually get >read, but who knows. > >Bonk >Alfredsson >Neil >Chara >Lalime >Hossa >Phillips >Redden >Havlat [snip] Try something like this (untested): $array = file($infile); // exchange the and name parts // Name // will become // Name $array = preg_replace('/(<.*?>)(.*)/', '$2$1', $array); // now sort the array $array = sort($array); // exchange the parts back $array = preg_replace('/(.*?)(<.*>)/', '$2$1', $array); // and finally save it to a file >though, when I display the contents of the array in my browser, I only get >the players name and not the , I am assuming this is because >of the way IE has interpreted it and that the entire line did actually get >read, but who knows. Try echoing using htmlentities(), IE (and all other browsers) will need to eat the "" parts - it's a valid html tag (even outside a form) -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fsockopen() with SSL?
At 14:11 28.02.2003, Michael Temeschinko said: [snip] >Hello, >is it possible to fetch a Website via SSL? [snip] Sure - have a look at cUrl... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Can't run PHP cli script from Cron
At 05:30 28.02.2003, Justin Michael Couto said: [snip] >Here is my crontab entry: > >* * * * * /path/to/file/file_name.php > >I also have > >* * * * * /path/to/file/bash_test_script [snip] Did you try to run the php file interactively, from the shell prompt? You need at last this statement on top of your PHP files: #!/usr/local/php -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read
At 05:11 28.02.2003, Karl James said: [snip] >Hey does anyone know if you can use PHP and ASP 3.0 or I.I.S on the same >hard drive on XP pro? > >I need to know for school, because I m taking classes for both languages. [snip] Sure you can. The correct interpreter (script engine) is selected by the IIS from the document extension (.asp => ASP engine, .php => PHP interpreter). Check the server settings for IIS on your machine after installing PHP. Good luck with your studies! -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] virtual() test
At 03:09 28.02.2003, John W. Holmes said: [snip] >Can anyone with Apache verify that you can pass arguments inside of a >virtual() call? Something like: > >Virtual("script.pl?id=1") > >And have $id available within script.pl. > >I don't have access to an Apache server right now to test, so thank you >very much. [snip] Nope - doesn't work (Apache 1.327, PHP 4.2.3). Here's a URL for you to check this out: http://www.vogelsinger.at/test.php Basically the test.php offers you the choice to either virtual() or readfile() an external file, passing URI parameters. As you can see when using virtual() the callee has the same environment as the caller, however using readfile() via HTTP everything works as expected. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Emacs?
Nope. It's 41 (I don't use Emacs) At 15:30 27.02.2003, Larry Brown spoke out and said: [snip] >Oops...I stand corrected. > >Larry S. Brown >Dimension Networks, Inc. >(727) 723-8388 > >-Original Message- >From: Matt Giddings [mailto:[EMAIL PROTECTED] >Sent: Thursday, February 27, 2003 12:26 AM >To: 'Larry Brown'; 'PHP List' >Subject: RE: [PHP] Emacs? > >Don't you mean 42? > >> -Original Message- >> From: Larry Brown [mailto:[EMAIL PROTECTED] >> Sent: Wednesday, February 26, 2003 7:55 PM >> To: PHP List >> Subject: RE: [PHP] Emacs? >> >> 25 >> >> -Original Message- >> From: Sascha Braun [mailto:[EMAIL PROTECTED] >> Sent: Tuesday, February 25, 2003 12:00 PM >> To: PHP General list >> Subject: [PHP] Emacs? >> >> How many Persons in this List are using Emacs as there default Editor? >> > >--- >Outgoing mail is certified Virus Free. >Checked by AVG anti-virus system (http://www.grisoft.com). >Version: 6.0.459 / Virus Database: 258 - Release Date: 2/25/2003 > > > >-- >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 [snip] -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] including db content as part of script
At 13:28 27.02.2003, Dennis Heuer spoke out and said: [snip] >One single question. Is including() a script on runtime only possible with >files or can I include() code from a database? [snip] If you have code in your database, you don't include() it but eval() it. Make sure though that the code is error-free (at least no fatal errors): global $php_errormsg; $php_errormsg = null; $result = @eval($code); $error = $php_errmsg; This will execute the contents of "$code" as if it were a PHP source file. You can even use such constructs: // do some stuff here ?>Hello from outside PHP O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] session_start
At 01:36 27.02.2003, Mr Percival said: [snip] >What I was hoping to do was to be able to give a error message if the server >was having this problem, but in order to do that I was needing a way of >knowing if it was because the session_start failed or users who didnt have >cookies turned on. > >I probably just need to get a new host since these disk full errors happen >regularly. :( [snip] session_start() cannot fail - the failure happens after the end of your influence. Ask these guys at your webhost to move /tmp to another partition, or _at_least_ to have session.save_path point to a partition that doesn't get exhausted too quickly. God. What do these webhosts think... -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] WebTV vs PHP
At 16:49 26.02.2003, Martin Mandl spoke out and said: [snip] >Has anybody expirienced troubles with clients using some sort of WebTV? >I got a bug report saying - sbdy using WebTV has problems with our >sites. We are using pure PHP - no JAVA, no JAVAScript ... Thus it's >puzzling. The only thing I are sessions. However they are working also >with cookies switched off [snip] If the browser has cookies disabled PHP will automatically switch to url-based session handling (provided you have url_rewrite enabled). The rest is a html or possibly css issue. If you need to get this sorted out you should try to work with a WebTV client appliance to see what's actually happening... -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php