[PHP] preg_replace wierdness
Code snippet -> header('Content-type: text/plain'); $foo = ' '; echo "$foo\n"; $path = '../../../'; $bar = preg_replace('/()/', "$1" . $path . "$2", $foo); echo $bar; ?> The second image doesn't get affected by preg_replace(). But if I break $foo into multiple lines like -> $foo = ' '; It works... Any tips would be appreciated... Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Logging out and session ids
I was just going through the archive. Seems this comes up enough for me to think I have something wrong. A simplistic code flow of events... session_start(); // user successfully logs in, set a session variable $_SESSION['user_id']; // when the user logs out, destroy session and redirect to top $_SESSION = array(); setcookie(session_name(), '', time() - 3600); session_destroy(); header('location: back_to_top'); ?> Ok, so when the user logs in, a session id is assigned to them. When they log out and are redirected to the beginning, the session id is the same (verified by the file name in /tmp and cookie manager in mozilla). My question is, even though the session contains no data after its destroyed, should the session id remain the same, after logging out, or should another be assigned when session_start() is called after the redirect??? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Logging out and session ids
Tom Rogers wrote: Hi, Friday, November 29, 2002, 4:58:02 PM, you wrote: GS> I was just going through the archive. Seems this comes up enough for me GS> to think I have something wrong. GS> A simplistic code flow of events... GS> GS> session_start(); GS> // user successfully logs in, set a session variable GS> $_SESSION['user_id']; GS> // when the user logs out, destroy session and redirect to top GS> $_SESSION = array(); GS> setcookie(session_name(), '', time() - 3600); GS> session_destroy(); GS> header('location: back_to_top'); ?>> GS> Ok, so when the user logs in, a session id is assigned to them. GS> When they log out and are redirected to the beginning, the session id is GS> the same (verified by the file name in /tmp and cookie manager in mozilla). GS> My question is, even though the session contains no data after its GS> destroyed, should the session id remain the same, after logging out, GS> or should another be assigned when session_start() is called after the GS> redirect??? The browser will send the old cookie and as the name is probably the same as the the old session it will get used again, or at least I think that is what is happening :) This should not be a problem as the data associated with the old session is gone. If that is the case, then the setcookie() call to destroy the clien't cookie probably isn't neccessary. If you close the browser and start a fresh one you will get a new session id. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sessions not written to db on windows...
I have a bit of code that uses sessions and stores session data in the database. Works flawlessly on FreeBSD 4.7/mySQL/PostgreSQL running php 4.2.3. When trying to run my code on Windows 2k with MSSQL and mySQL, its not working. The windows box is running php 4.1.2 (its a dev box). Here is the section on sessions from php.ini. Can anyone see anything wrong with this setup?? And also, can alternative means of storage be used under windows php?? Thanks for any insight you may provide... - [Session] ; Handler used to store/retrieve data. session.save_handler = files ; Argument passed to save_handler. In the case of files, this is the path ; where data files are stored. Note: Windows users have to change this ; variable in order to use PHP's session functions. session.save_path = c:\winnt\temp ; Whether to use cookies. session.use_cookies = 1 ; Name of the session (used as cookie name). session.name = PHPSESSID ; Initialize session on request startup. session.auto_start = 0 ; Lifetime in seconds of cookie or, if 0, until browser is restarted. session.cookie_lifetime = 0 ; The path for which the cookie is valid. session.cookie_path = / ; The domain for which the cookie is valid. session.cookie_domain = ; Handler used to serialize data. php is the standard serializer of PHP. session.serialize_handler = php ; Percentual probability that the 'garbage collection' process is started ; on every session initialization. session.gc_probability = 1 ; After this number of seconds, stored data will be seen as 'garbage' and ; cleaned up by the garbage collection process. session.gc_maxlifetime = 1440 ; Check HTTP Referer to invalidate externally stored URLs containing ids. session.referer_check = ; How many bytes to read from the file. session.entropy_length = 0 ; Specified here to create the session id. session.entropy_file = ;session.entropy_length = 16 ;session.entropy_file = /dev/urandom ; Set to {nocache,private,public} to determine HTTP caching aspects. session.cache_limiter = nocache ; Document expires after n minutes. session.cache_expire = 180 ; use transient sid support if enabled by compiling with --enable-trans-sid. session.use_trans_sid = 0 url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry" -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How to handle "so called" expired sessions??
Ive just been getting myself deep into using sessions. Sessions are working as it should except for one condition. Say I log into the site, and the session is started, and I don't do anything for the next 30 mins, then go back to the site. Im temporarily logged out, but because the session cookie is still good, the next page load logs me back in. How do the people who use sessions handle this type of scenario?? Thanks for any insight you may provide... -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to handle "so called" expired sessions??
I had something similar in mind. Thanks for your input... Tom Rogers wrote: Hi, Tuesday, December 3, 2002, 1:57:21 PM, you wrote: GS> Ive just been getting myself deep into using sessions. GS> Sessions are working as it should except for one condition. GS> Say I log into the site, and the session is started, and I don't do GS> anything for the next 30 mins, then go back to the site. GS> Im temporarily logged out, but because the session cookie is still good, GS> the next page load logs me back in. GS> How do the people who use sessions handle this type of scenario?? GS> Thanks for any insight you may provide... GS> -- GS> Gerard Samuel GS> http://www.trini0.org:81/ GS> http://dev.trini0.org:81/ Do your own session timing by storing a last access time in sessions and check the duration yourself, if it is over the timeout you want delete the session data and start again. That way the cookie is ok but won't point to any old data. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to handle "so called" expired sessions??
I was the original poster to this topic. Quite suprised it continued.. I have my sessions stored in a database, thus I thought the problem was there, but have come to realise, that is how sessions behave naturally. I originally thought, that the expired session garbage collection dumps stale sessions, if the user is away after the default 24 minutes. But in my case, it does, but since the user still has a valid session cookie containing valid data, the session is brought back from the dead even if hours has passed, and the browser hasn't closed. Not desirable for me. As Tom pointed out to me, (which I haven't gotten around to do as yet) in not so many words -> 1. When the user logs in assign a session variable to lets say time() + 600 (10 mins in the future). 2. Each page load, refresh the session variable in step 1 *if* the session variable references a future timestamp. 3. If on a page load, the session variable references a past (older than time() - 600) timestamp, core dump the session data -> $_SESSION = array(); to /dev/null, hell, whatever makes you happy... Although I haven't gotten around to using these steps, it seems like it would work for what Im trying to achieve. John W. Holmes wrote: No question :) It's just that this is what the original question was about and why I suggested doing his own sesssion timeout check as the deleting proccess is too unreliable to depend on for timeout handling. PHP will quite happily return stale data which could be bad in a login type of situation. Okay. I think I thought you were the original poster. How do you know it's returning "stale" data, though? If the cookie is valid, and there is still a session file (or data in memory), then why is it stale or expired. Maybe I'm just missing something here. If it's expired because you think it's too old, then you track your own timestamps and do your own cleanup. Is that what you're saying? ---John Holmes... -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Reject some?
What Im trying to do is, reject all email address strings ending in yahoo.com, except [EMAIL PROTECTED] Im trying -> if (preg_match('/[^[EMAIL PROTECTED]|yahoo.com]$/', '[EMAIL PROTECTED]')) { echo 'match found'; } else { echo 'match not found'; } ?> The search pattern must also be capable of expanding to something like -> ^[EMAIL PROTECTED]|yahoo.com|^foo@hotmail|hotmail.com Basically what Im trying to perform is to reject all email address strings ending in either yahoo.com or hotmail.com, except strings ending in [EMAIL PROTECTED] or [EMAIL PROTECTED] Thanks for any insight you may provide... -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sessions and AOL
I was wondering, if for example, an AOL user browses your site that uses php sessions, do the session ids change when they hop ip addresses? Im looking for a better way to counteract AOL's ip jumping. Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sessions and AOL
No its not a matter of tying a session to an ip address. Im modifiying some code that works as a "whosonline" on a site at any given time. Currently, it mainly works off ip address, of which we all know isn't accurate. As far as my usage of the word "AOL", that only represents my personal experience, with the ip address jumping phenomena. Mark Charette wrote: From: Gerard Samuel [mailto:[EMAIL PROTECTED] I was wondering, if for example, an AOL user browses your site that uses php sessions, do the session ids change when they hop ip addresses? No. Sessions are not (or should not be!) tied to IP numbers. Im looking for a better way to counteract AOL's ip jumping. Why? It's not just AOL! Mark C. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] stripslashes and quoted material
Hey all. I noticed a string containing slashes was breaking some code of mine on an w2k/IIS box running php 4.2.3. For example -> http://www.apache.org/\"; target=\"_blank\"> When trying to apply stripslashes, the slashes remained. So I applied str_replace('\"', '', $var) and that worked. Any idea as to why stripslashes would not remove the slashes in the string? Thanks for any input. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] stripslashes and quoted material
I figured out the problem. magic_quotes_sybase was turned on, on the IIS box. All is well with stripslashes() again. Chris Wesley wrote: On Wed, 8 Jan 2003, Gerard Samuel wrote: http://www.apache.org/\"; target=\"_blank\"> When trying to apply stripslashes, the slashes remained. So I applied str_replace('\"', '', $var) and that worked. Any idea as to why stripslashes would not remove the slashes in the string? stripslashes() will unescape single-quotes if magic_quotes_runtime = Off in your php.ini. If you have magic_quotes_runtime = On, then it will also unescape double-quotes (and backslashes and NULLs). ~Chris -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dynamic Regex
The example doesn't have to make sense, but Im looking for the correct syntax for $foo. I was trying -> $foo = '\[this\](.*?)that'; $bar = 'the other'; $str = preg_replace($foo, $bar, $other_string); But that doesn't work. I came across an example where the syntax of $foo is in -> $foo = '#\[this\](.*?)that#'; The second syntax of $foo works. I was wondering on the meaning of # in the string?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Dynamic Regex
What you suggested is what I was trying before. My original example was incorrect. Here is an good example for the variable holding the pattern -> $foo = '/\[url\]([a-z]+://.*?)\[/url\]/'; This pattern would not work, but if I change it to $foo = '#\[url\]([a-z]+://.*?)\[/url\]#'; It does work. Not complaining but just trying to figure out why the first version doesn't work for future references. Thanks Greg Beaver wrote: Hi Gerard, all the preg_* functions require delimiters surrounding regular expressions. $foo = '\[this\](.*?)that'; should be by default: $foo = '/\[this\](.*?)that/'; the code you tried uses # as the delimiter instead of /, an option preg_* allows Take care, Greg -- phpDocumentor http://www.phpdoc.org "Gerard Samuel" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... The example doesn't have to make sense, but Im looking for the correct syntax for $foo. I was trying -> $foo = '\[this\](.*?)that'; $bar = 'the other'; $str = preg_replace($foo, $bar, $other_string); But that doesn't work. I came across an example where the syntax of $foo is in -> $foo = '#\[this\](.*?)that#'; The second syntax of $foo works. I was wondering on the meaning of # in the string?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Dynamic Regex
Made sense. Thanks for your help. Greg Beaver wrote: hi Gerard, I didn't think you were complaining :) the problem is in [/url] $foo = '/\[url\]([a-z]+://.*?)\[/url\]/'; should be $foo = '/\[url\]([a-z]+://.*?)\[\/url\]/'; that "/" was ending the pattern, and so preg_* was trying to read "url\]/" as closing information, and probably giving an odd error about "u" not being appropriate that's why # worked, because there were no other # in the string. Hope that answers the question (properly this time!) Take care, Greg - Original Message - From: "Gerard Samuel" <[EMAIL PROTECTED]> To: "Greg Beaver" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, January 09, 2003 12:24 AM Subject: Re: [PHP] Re: Dynamic Regex What you suggested is what I was trying before. My original example was incorrect. Here is an good example for the variable holding the pattern -> $foo = '/\[url\]([a-z]+://.*?)\[/url\]/'; This pattern would not work, but if I change it to $foo = '#\[url\]([a-z]+://.*?)\[/url\]#'; It does work. Not complaining but just trying to figure out why the first version doesn't work for future references. Thanks Greg Beaver wrote: Hi Gerard, all the preg_* functions require delimiters surrounding regular expressions. $foo = '\[this\](.*?)that'; should be by default: $foo = '/\[this\](.*?)that/'; the code you tried uses # as the delimiter instead of /, an option preg_* allows Take care, Greg -- phpDocumentor http://www.phpdoc.org "Gerard Samuel" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... The example doesn't have to make sense, but Im looking for the correct syntax for $foo. I was trying -> $foo = '\[this\](.*?)that'; $bar = 'the other'; $str = preg_replace($foo, $bar, $other_string); But that doesn't work. I came across an example where the syntax of $foo is in -> $foo = '#\[this\](.*?)that#'; The second syntax of $foo works. I was wondering on the meaning of # in the string?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session_destroy problem
In my code, I usually dump session data before calling session_destroy() like -> $_SESSION = array(); // Now its empty session_destroy(); // Then call session destroy. Works for me. Ken Nagorski wrote: Hi there, I have written a class that manages sessions. I have never used sessions before so all this is new to me. Everything works fine as far as starting the session and logging in however when I call sessoin destroy it doesn't seem to work the function returns 1 as it should if all goes well however if I go to another page and do some other browsing even if I close the browser the session still hangs around. Is there something I don't know about sessions? I have read the documentation on the session_destroy function, I don't think that I am missing anything... Anyone have any suggestions? I am totally confused. Thanks Ken -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] XML Cleanup Regex
Im trying to clean up xml data of illegal characters. I need a pointer as to how to get a regex to perform this. Here is my feable attempt -> header('Content-type: text/plain'); $foo = 'It\'s a test'; //$bar = preg_replace('/[^\w\s<>\/]+/', ''', $foo); $bar = preg_replace('/()([\'])(<\/title>)/', '$1' . ''' . '$3', $foo); echo $bar; ?> Im trying the 2nd way, because I want to only do this clean up between certain tags.. Thanks for any help you may provide. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] session_cache_limiter with Internet Explorer
Has anyone gotten this function or something like it to work correctly with Micorsoft IE 5/6. When I have it set to private, Mozilla and Opera works wonderfully, but IE doesn't seem to have half a brain, and would continually would have to refresh the page to get current data. I've tried it under php 4.2.3 and 4.3.0 on FreeBSD/Apache and WinXP/Apache. Any suggestions would be appreciated. Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Internet Explorer cache friendly headers?
Browser cache that is. I started to use session_cache_limiter() with a value of private. It seems to work great with Mozilla and Opera, but IE 5 & 6 doesn't seems to handle it too well. I have to continually refresh the page to get the latest data. Is anyone else experiencing this behaviour? Are there any alternatives to using session_cache_limiter() that is friendly with all browsers? Any pointers would be appreciated. Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sessions and IP ports
Has anyone noticed that different port numbers creates additional session ids? So if someone is browsing the site, and the remote port number changes, additional sessions are created... Is this the expected behaviour??? www.xxx.yyy.zz,3941 www.xxx.yyy.zz,3940 -- Gerard Samuel http://www.trini0.org:81/ http://test1.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ob_gzhandler problems under 4.3.0???
I noticed this problem with one of my scripts when its running under php 4.3.0, Apache 2.0.44. It only happens when started with ob_start('ob_gzhandler'); Even with this test script from the php manual produces this error. Any insight would be appreciated. From php.ini -> ; Output buffering allows you to send header lines (including cookies) even ; after you send body content, at the price of slowing PHP's output layer a ; bit. You can enable output buffering during runtime by calling the output ; buffering functions. You can also enable output buffering for all files by ; setting this directive to On. If you wish to limit the size of the buffer ; to a certain size - you can use a maximum number of bytes instead of 'On', as ; a value for this directive (e.g., output_buffering=4096). output_buffering = 4096 ; You can redirect all of the output of your scripts to a function. For ; example, if you set output_handler to "mb_output_handler", character ; encoding will be transparently converted to the specified encoding. ; Setting any output handler automatically turns on output buffering. ; Note: People who wrote portable scripts should not depend on this ini ; directive. Instead, explicitly set the output handler using ob_start(). ; Using this ini directive may cause problems unless you know what script ; is doing. ; Note: You cannot use both "mb_output_handler" with "ob_iconv_handler" ; and you cannot use both "ob_gzhandler" and "zlib.output_compression". ;output_handler = ; Transparent output compression using the zlib library ; Valid values for this option are 'off', 'on', or a specific buffer size ; to be used for compression (default is 4KB) ; Note: Resulting chunk size may vary due to nature of compression. PHP ; outputs chunks that are few handreds bytes each as a result of compression. ; If you want larger chunk size for better performence, enable output_buffering ; also. ; Note: output_handler must be empty if this is set 'On' ; Instead you must use zlib.output_handler. zlib.output_compression = Off ; You cannot specify additional output handlers if zlib.output_compression ; is activated here. This setting does the same as output_handler but in ; a different order. ;zlib.output_handler = --- Example script -> ob_start("ob_gzhandler"); ?> This should be a compressed page. - Error reported -> This should be a compressed page. Warning: (null)() [ref.outcontrol]: output handler 'ob_gzhandler' cannot be used twice in Unknown on line 0 -- Gerard Samuel http://www.trini0.org:81/ http://test1.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ob_gzhandler problems under 4.3.0???
Thanks. Worked like a charm... Jason Sheets wrote: PHP is starting output buffering automatically for you and then you are starting it in your script as well, that is why you are receiving the message ob_gzhandler can not be used twice. Use ob_get_level to check if output buffering is not already started. You may want additional logic that checks to see if the output buffer hander is ob_gzhandler. Jsaon -- Gerard Samuel http://www.trini0.org:81/ http://test1.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] http benchmark tools
This is what I use -> http://www.joedog.org/siege/index.shtml Tamas Arpad wrote: Hi, I'm searching for a good http benchmark tool. Of course I found some, but don't know them and don't know which one to choose. I found JMeter slow, in other aspects it would be perfect. Used httperf before, but I need more complicated test cases. I'd like to simulate visitors who first go to the first page, then click there on an article or column and so on... Please if someone have expirience, share it! I also searched for tools that can use apache's log to make benchmarks by resending real-life's request, but couldn't find one. Is there such a tool? Thanks, Arpi -- Gerard Samuel http://www.trini0.org:81/ http://test1.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Control over your Session
Got a problem thats baffling me. I have a form that includes a file that starts a session. Creating sessions are no problem, but deleting the session variable is not working as its supposed to. Sudo code -> include('some_file.php'); // This file starts the session via session_start(); switch( $bar ) { case 'post': // do logic and insert into db unset($_SESSION['foo']); // we are finished with session variable, so delete it break; case 'preview': // preview form contents and set session to persist $_SESSION['foo'] = 'some data'; break; default: if (isset($_SESSION['foo'])) { unset($_SESSION['foo']); } // display form here break; } ?> For some reason thats beyond me, using unset() to kill the session variable isn't working. Does anyone know what could be causing this type of behaviour?? Any help would be appreciated. Thanks -- Gerard Samuel http://www.trini0.org:81/ http://test1.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Control over your Session
Thanks for saving my sanity. The best answer is the simplest one. Im testing my code on a domain where register_globals were on. Never would have thought of checking that. Thanks once again, now I can go to sleep... Leif K-Brooks wrote: If you have register_globals on, you'll need to session_unregister it. Gerard Samuel wrote: Got a problem thats baffling me. I have a form that includes a file that starts a session. Creating sessions are no problem, but deleting the session variable is not working as its supposed to. Sudo code -> include('some_file.php'); // This file starts the session via session_start(); switch( $bar ) { case 'post': // do logic and insert into db unset($_SESSION['foo']); // we are finished with session variable, so delete it break; case 'preview': // preview form contents and set session to persist $_SESSION['foo'] = 'some data'; break; default: if (isset($_SESSION['foo'])) { unset($_SESSION['foo']); } // display form here break; } ?> For some reason thats beyond me, using unset() to kill the session variable isn't working. Does anyone know what could be causing this type of behaviour?? Any help would be appreciated. Thanks -- Gerard Samuel http://www.trini0.org:81/ http://test1.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible to test an uploaded file to check the type?
The upload process, already collects info on file types when you upload. From the manual -> $_FILES['userfile']['type'] The mime type of the file, if the browser provided this information. An example would be "image/gif". So, check $_FILES['userfile']['type'] against a set of allowed file types, and you're set... Marek Kilimajer wrote: If you have compiled php with --enable-mime-magic, you can use mime_content_type() Dan Anderson wrote: Is it possible to check a file in $_FILES['userfile']['tmp_name'] to make sure it is of a certain format? I want to allow a user to only upload jpegs or mpegs, and want to check what format the file is in. Thanks in advance, Dan Anderson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible to test an uploaded file to check the type?
David Otton wrote: $_FILES['userfile']['type'] The mime type of the file, if the browser provided this information. An example would be "image/gif". So, check $_FILES['userfile']['type'] against a set of allowed file types, and you're set... A client-supplied value isn't going to be too useful - it can be spoofed, or may not be present. (I believe a Windows browser would set the mime-type based purely on the file extension, though I haven't tested this myself). Then my apologies. I thought php determined the file type on upload, and not rely on user input as your're saying. Makes me rethink some of my own code :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible to test an uploaded file to check the type?
Gerard Samuel wrote: A client-supplied value isn't going to be too useful - it can be spoofed, or may not be present. (I believe a Windows browser would set the mime-type based purely on the file extension, though I haven't tested this myself). Then my apologies. I thought php determined the file type on upload, and not rely on user input as your're saying. Makes me rethink some of my own code :) Looking for opinions. Can a spoofed uploaded file hurt a script or a webserver?? Reason why Im asking is because, I looked over the magic.mime file on my server, and I see that it doesn't support flash files (I may be wrong), of which I currently allow flash files to be uploaded. So who knows what else it may not support. I guess, can it really be bad for your script, your server, and/or your health?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] BigEndian to integer
A bit off topic Im trying to figure out how to convert BigEndian byte words to integers. For example -> 0 0 0 18 = 18 The only way I know how to convert this is by writing down on paper, and writing 8 4 2 1 above the numbers and adding up the values. Trying to figure out a way via plain old math/php has me stumped at the moment. (Maybe some sleep is in order) Any help and or tips would be greatly appreciated. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is it possible to test an uploaded file to check the type?
Thank you for your reply. A little background on what Im doing with file uploading. 1. Im allowing registered users to upload avatars for their own usage. 2. Im allowing image uploading for submitted articles by certain registered users. 3. And Im currently constructing a media gallery, where images, mp3, realaudio, etc can be presented/downloaded/streamed. All 3 points are based on a file upload class that I put together. Of which each section has their own allowed set of mime-types, based on what is supplied via $_FILES['xxx']['type'] An analogy that I have in mind is this. Lets look at the file upload class as the Post Office. They practically allow any package to be delivered to anyone by anyone. They do scrutiny checks on packages. Unfortunately, this one package, has a pipe bomb in it. Its delivered to my mailbox, and poses a threat. Now, is it the fault of the PostOffice for allowing that particular package through? What else can this PostOffice do to tighten things up? So Im at the point, where Im trying to figure out what else I can do to "tighten" scrutiny checks. Concerning infecting the server, if the files are chmodded without the executable bit, shouldn't that be considered *safer* It may seem that mime_content_type() isnt an option. I tried it on a flash file, and it reported it as text/plain. What would really be cool, is a php extension to a virus scanner. (Hey can I dream) Once again, thanks for your pointers/thoughts/comments. Dan Anderson wrote: There are some very good reasons to check a file's mime type. For one thing, if you send a user an executable when you meant to send them a jpg, and that executable unleashes a virus, that is no good. Not only will noone visit your site if they know you are a source of viruses, you may get sued for damages. (Computers are expensive!) Everything depends on how the file is used. If, for instance, the only person who will be downloading or handling the file will be the person who uploaded it, everything should be fine. (NObody's going to infect / r00t their own computer intentionally). But let's say you run the file yourself. In that case, that file can hurt your server. So basically, if you don't check your files scrupulously a hacker can and will do something evil. -Dan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] BigEndian to integer
Marek Kilimajer wrote: http://www.php.net/pack A little background on what Im doing. Im attempting to read realaudio files for their metadata, so Im reading from a binary string, and Im currently using unpack() (Im new to using this function, so I may be wrong with its usage) to unpack the data, along with ord(), and the result is something like what I posted before -> 0 0 0 18 (I put the spaces in there so we know that each number is a byte) So Im not exactly sure how the pack() function would play a role in this. David Nicholson wrote: Never heard of a BigEndian number beofre, but this should do it... function BigEndiantoInt($bigendian){ $bits = split(" ",$bigendian); $bits = array_reverse($bits); $value = 0; $columnvalue = 1; foreach($bits as $thisbit){ $value = $value + ($columnvalue * $thisbit); $columnvalue = $columnvalue * 2; } return $value; } For taste of what BigEndian or its counterpart LittleEndian is about, look at -> http://www.webopedia.com/TERM/B/big_endian.html http://whatis.techtarget.com/definition/0,,sid9_gci211659,00.html I'll give your function a shot, and see if I can get something meaningful from it. Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] BigEndian to integer
Joel Rees wrote: Just in case you're still groggy when you wake up this morning, the page for pack() lists an 'N' format for unsigned long big endian byte order for pack() and unpack(). I think what you probably want to do most is use the 'N' format when you unpack. (The other responses were amusing, was it a full moon last night? ;-)) Thanks for the heads up. Ill give it a try... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] BigEndian to integer
Tom Rogers wrote: Trying to use unpack by itself on large binary streams with variable packet sizes and content buried in them can become a nightmare. Try to unscramble an excel file using unpack() :) Yeah, not exactly the most exciting thing to do. As long as I have some specs on the format, its hasn't been too bad with mp3 and realaudio files so far... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex and variable usage
Has anyone had any success with using variables in a regex shown below?? $foo = 3; $bar = 4; preg_match('/^[a-z0-9\-_\.]+\.[a-z0-9]{$foo, $bar}$/', $some_string) or even preg_match('/^[a-z0-9\-_\.]+\.[a-z0-9]{' . $foo . ', ' . $bar . '}$/', $some_string) but this would work preg_match('/^[a-z0-9\-_\.]+\.[a-z0-9]{3,4}$/', $some_string) Thanks for any pointers.. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex and variable usage
Curt Zirzow wrote: Gerard Samuel <[EMAIL PROTECTED]> wrote: or even preg_match('/^[a-z0-9\-_\.]+\.[a-z0-9]{' . $foo . ', ' . $bar . '}$/', $some_string) that should work. Unfortunately it doesn't for some reason. Don't know why. but you could do this: $pattern = "/^[a-z0-9\-_\.]+\.[a-z0-9]{$foo, $bar}\$/"; preg_match($pattern, $some_string) But this does, so Im good. Thanks for the tips... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Recovering from a time out
Is it possible to *gracefully* recover from php timing out? For example, uploading a large file, and php times out, so display "Oops Timed out" This also assumes that we have no means of changing php's time out value?? Thanks for your comments.. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Securing File Uploads Was: Is it possible to test an uploaded fileto check the type?
Sorry for bring this back to life, but Im looking for some more opinions. A friend and I are somewhat dead locked, as to whether with available tools via php, that its possible to *reliably* secure file uploads. File uploads currently encompass, images, mp3, real audio files, with plans for ogg vorbis, flash, and what ever audio/visual/document file formats, I can make php read its metadata. These files will be used in a gallery type environment, to be displayed, downloaded, or streamed. The end product will be used by people who most likely will have their sites hosted, thus no real control over the server, and can be run on *nix/Windows environments. Browsers that I've tested with: IE 6, Mozilla 1.4(Windows/FreeBSD), Opera 6(FreeBSD) Spoofed file in question: Renamed putty.exe to putty.mp3 Side Note: Image uploading can be more or less be considered secure because Im running it throught getimagesize() which will report false on non image files. Currently, the upload process, checks the browser reported mime type against a predefined set of mime types. The file extention is checked against a set of predefined file extentions. Then the file is moved to its final destination, and is read for its sequence of magic bytes for its metadata (which depends on the file's extention, so it knows what to look for). Files are stored in a predefined directory under the webroot. With IE6, the upload fails because it correctly reported putty.mp3's mime type as not being an mp3 file. With the other browsers in question, they solely report the mime types according to the file's extention, so the file is successfully uploaded. Now remember, that the target audience for the script will most likely be on a shared host, thus no control over the server. Is there anything else I can do using php, that can help in making the process more secure??? mime_content_type() isn't an option, as it doesn't report all mime types. Reversing the order of reading the file's, magic bytes, and storing it, doesn't really improve matters, as it depends on a file's extention. Thanks for any tips/pointers you can provide, and sorry for the long post... Dan Anderson wrote: There are some very good reasons to check a file's mime type. For one thing, if you send a user an executable when you meant to send them a jpg, and that executable unleashes a virus, that is no good. Not only will noone visit your site if they know you are a source of viruses, you may get sued for damages. (Computers are expensive!) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Securing File Uploads Was: Is it possible to test an uploadedfile to check the type?
Jason Wong wrote: In a response to your previous posts on this matter, I suggested that you search freshmeat/sourceforge for a PHP-based media file metadata extractor (yes one does exist). I'm putting forward the same suggestion again. Ok, Ill look, but not sure what good it will do me, as Im already reading a file's metadata (using my own code). Im basing my assumption, on that binary data may share so called "magic" bytes. Like an mpeg header (111) may/or may not appear in other file formats. (Purely an assumption as of this moment) But thanks for reminding me on the other code... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Querying a form
Im looking for links to tutorials, or if someone can post code here, where php can be used to query a form, so that I can retrieve its results. Thanks for any pointers... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Querying a form
Those links pretty much show how to use forms with php. What Im looking for is a way to post data to a form, and retrieve the following page's results, within php, if it is at all possible... If Im not making sense, let me know, and Ill explain it a little more... Jeff Harris wrote: On Jul 30, 2003, "Gerard Samuel" claimed that: |Im looking for links to tutorials, or if someone can post code here, |where php |can be used to query a form, so that I can retrieve its results. |Thanks for any pointers... How about some of these? http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=php+form+tutorial -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Querying a form
David Nicholson wrote: You can either use the cUrl functions: http://uk2.php.net/curl or if this is not an option to you, you can use the socket functions: http://uk2.php.net/manual/en/ref.network.php but you will have to deal with sending the HTTP request yourself (which is not very complicated assuming you are not using HTTPS). Hehe. Unfortunately, its going to be HTTPS. So Ill see what I can come up with. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Session ID as a regex
How would you best describe a session id as a regex? [a-z0-9]{32} Just checking to see if any other characters can be in a session id. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Associative to Numeric
What would be the quickest, most reliable means to convert an associative array to a numeric array. Running an implode()/explode() combination comes to mind, but reliablity can be questioned when it comes to deciding a delimiter, since, the data can possibly contain any character. Any suggestions are welcome. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP5 on IIS
Are there any issues, or has anyone have any problems installing PHP5 with IIS 5? Following the install directions from the manual, always results with a 404 error when trying to view a php file. I have no problems with installing PHP 4.3.3R2 with IIS 5, so Im not sure if there are any issues with PHP5... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Associative to Numeric
Excellent. Thanks. Greg Beaver wrote: $num = array_values($assoc); Regards, Greg -- phpDocumentor http://www.phpdoc.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mod_php issues with security or stablility?
Jason Sheets wrote: On cavaeat is with CGI PHP can execute as the owner of the script, with mod_php it executes as the web server. IMHO, the biggest difference between the two as far as security is concerned in favour for CGI. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex for Browser Versions
Im trying to pull the Mozilla version and *possibly* the MSIE x.xx string out $_SERVER['HTTP_USER_AGENT'] If I did this correctly, (MSIE\s\d\.\d{1,2})? should mean that if its there pull it out, else move on, since its not there. When viewing this script via a windows browser, it doesn't match the MSIE section. If I take out the trailing ?, it will match successfully. But when viewing it with a mozilla browser, the regex fails as there is not MSIE string in there. Any help with this would be appreciated. Thanks var_dump($_SERVER['HTTP_USER_AGENT']); echo ''; preg_match('/^(Mozilla\/\d\.\d{1,2}|Opera\/\d\.\d{1,2})\s\(.*?(MSIE\s\d\.\d{1,2})?.*?\)(\sOpera)?/', $_SERVER['HTTP_USER_AGENT'], $foo); var_dump($foo); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex for Browser Versions
True, but since the code is being run by 3rd parties, I don't have a guarantee that the browsecap.ini file is available on the server. Monty wrote: Maybe it might be easier to just use the get_browser() function: http://www.php.net/manual/en/function.get-browser.php Monty -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Making a PHP Script "Very" Cache Friendly
Searching through the archives, most people are running away from caching php scripts. Im trying to do the opposite. I have a script that fetches css files. Im trying to add header() calls to it so that browsers can cache it like a normal css file. This is what I have at the top of the file -> -- header('Content-type: text/css'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime('./foo.php')) . ' GMT'); For the life of me, according to the output of ethereal (a network sniffer), this file is always fetched from the server. Yes I did breeze by the HTTP 1.1 spec, but I didn't pick up on anything special that I should be doing. Is there a way to make the file be put into cache, or am I barking up the wrong tree. Thanks for your insight. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a PHP Script "Very" Cache Friendly
Gerard Samuel wrote: Searching through the archives, most people are running away from caching php scripts. Im trying to do the opposite. I have a script that fetches css files. Im trying to add header() calls to it so that browsers can cache it like a normal css file. This is what I have at the top of the file -> -- header('Content-type: text/css'); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime('./foo.php')) . ' GMT'); For the life of me, according to the output of ethereal (a network sniffer), this file is always fetched from the server. Yes I did breeze by the HTTP 1.1 spec, but I didn't pick up on anything special that I should be doing. Is there a way to make the file be put into cache, or am I barking up the wrong tree. Thanks for your insight. Ok, I think it has been working all along. Someone asked if I was viewing the actual headers. Yes I am, using ethereal. During my previous tests, I was reloading the page, which caused the dynamic css file to regenerate output, while the other css files send a "304". If I were to click on a link normally, the dynamic file doens't show up in the header stream, so Im assuming that means its cached. Someone else suggested that I add header('Cache-Control: max-age=3600'); Ill do that as its the http 1.1 version of expire. Its not going to hurt anything. Thanks for your pointers/comments. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] header() and mozilla - HELP!
Im assuming you are running mozilla 1.3.x Its not a php issue but a mozilla bug, that I've experienced first hand http://bugzilla.mozilla.org/show_bug.cgi?id=202210 deno vichas wrote: i'm runnig into a random problem of having all the headers being displayed instead on the actual web page in mozilla, Ie doesn't seem to suffer from this, when using header("location: www.url.com"); this is happening randomly. has anybody seen this or have a fix? -deno -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php editor?
Because some of us, work directly on the server, instead of modifying files, then uploading to the server to test :) electroteque wrote: boy how painfully dweebish is vi why make it harder for yourself :O -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] When to escape slashes, and when not to???
I have a class method that does one thing and one thing only. Escape characters before going to the DB. Part of it is -> if (!get_magic_quotes_gpc()) { $string = pg_escape_string( $string ); } return "'" . $string . "'"; In everyday get/post operation it seems to work flawlessly. I've come across a situation where Im parsing an XML file to insert into the DB. The content needed to be escaped, so I modified the above to -> if (!get_magic_quotes_gpc() || !get_magic_quotes_runtime()) { $string = pg_escape_string( $string ); } return "'" . $string . "'"; And the XML data is escaped correctly for DB insertion. Now going back to my everyday get/post operation, the code is broken somehow, as content, that is not normally escaped is escaped, and breaking stuff, like serialized data in the DB. Is the above code valid for escaping characters in get/post/cookie and external data operation? Can they be safetly used together as in my example above. (Where if one condition doesn't meet, and the other does, escape characters). Or there may be something else in my code that is messing things up. Any pointers/experience would be greatly appreciated. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Passing objects into methods or functions
Im trying to pass an object into functions and class methods, and for some reason, Im unable to access the object's methods. When I var_dump() the object, its a valid object with the function or class method. When I check via get_class_methods, all the methods are there, from within the function or class method. I tried passing by reference, and the regular "copied" way. I end up with the error -> Fatal error: Call to undefined function: display_thumbnails() in .. I can access the object's variables, but not it's methods Maybe because Im tired, but if anyone experienced this before, I'd greatly appreciate any feed back on this. Thanks class class { var $_tpl; var $gal_tpl = array(); function gallery_class(&$tpl) { if (is_object( $tpl )) { $this->_tpl = $tpl; } } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] unpack() and binary data
First of all, I have nearly no idea as to how to interpret binary data. But Im attempting to parse binary data for file metadata information (like mp3 files). Concerning unpack(), I can across this link from the notes in the manual -> http://fooassociates.com/phpfer/html/rn45re877.html This has somewhat made things a little clearer as to how to move around in a binary string. But as a total newbie at this, I was wondering if there are any more examples or tutorials, that would be geared towards my intellectual ablity in this matter. Any tips and or hints would be greatly appreciated. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex Help with -> ?
I have a string something like -> <[TIT2]> ABC <[TPE1]> GHI <[TALB]> XYZ Im applying a regex as such -> // Title/Songname/Content preg_match('/<\[TIT2\]>(.*?)(<\[)?/', $foo, $match); $title = trim( $match[1] ); The above regex doesn't work. At the end of the pattern Im using (<\[)? The pattern may or may not end with <[ For example searching for -> <[TALB]> XYZ The string, is *NOT* expected to hold a certain order as how it is retrieved. How does one go about to fix up this regex? Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] session_regenerate_id() -> "Call to undefined function"
PHP 4 >= 4.3.2 D. R. Hansen wrote: I am getting a "Call to undefined function" when invoking session_regenerate_id(). No typos -- I've checked. Fatal error: Call to undefined function: session_regenerate_id() in /path_to_my_script/resetsession.php3 on line 5 Running PHP 4.3.1 on RH 8.0 and Apache 2 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regex Help with -> ?
sven wrote: looks like id3v2 ;-) how about this: $string = "<[TIT2]> ABC <[TPE1]> GHI <[TALB]> XYZ"; $pattern = "/<\[TIT2\]>([^<]*)/"; // matches anything exept '<'; till '<' or end of string preg_match($pattern, $string, $match); var_export($match); Yeah, Im trying to figure out a way to parse these tags. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Paying Job...
Basically, someone is looking to get a database driven site built, and Ive never written code for money before. Im looking for advice, as to how the experienced coders in here charge for their work. Do you charge by the page, script or by the hour (that would be nice). Thanks for any input you may provide... -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable naming standards???
A philosophical question Are there any standards to naming variables?? I was told that one should include a letter or combination of letters to describe a variable i.e. $sfoo = 'string'; // string $bfoo = true; // bool $nfoo = 10; // interger etc Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Output Compression & output buffering..
In an included file, I have an error handler that is using the 'output buffering' trick to dump a page in progress to display the error page. I also happened to have a switch to turn on output compression. When output compression is on, if an error is comitted while the page is displaying, I get an empty page, instead of the expected error page or the page hangs, depending on the browser. Has anyone gotten both forms of output control to work together without ill side effects?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Output Compression & output buffering..
Basically the included file containing the error handler is like so -> - -- In another file, I start compression like -> if ($compress == '1') { ob_start('gz_handler'); } - Then at the end of the script I have ob_end_flush(); I believe the sequence of events are correct. I just so happened to pass by zend.com, and in the newsletter #100 from the 26th, there is a blurb about ob_gzhandler being broken. Im running php 4.2.2, so it may apply to me, as Im getting the blank page that its describing. Thanks for your help. Eric Pignot wrote: >Hi Gerard, > >I never had any problem using output buffering... >Do you correctly dump the buffer when an error occurs ? I suppose you have >built your own error() function, a bit like this one : > >exit_on_error($msg){ >ob_end_clean(); >echo $msg; >exit(); >} > >can you tell us a bit more concerning the way you handle the exit of your >program ? > >regards > >Eric > > > >"Gerard Samuel" <[EMAIL PROTECTED]> a écrit dans le message de news: >[EMAIL PROTECTED] > > >>In an included file, I have an error handler that is using the 'output >>buffering' trick to >>dump a page in progress to display the error page. >>I also happened to have a switch to turn on output compression. >>When output compression is on, if an error is comitted while the page is >>displaying, I get an empty page, >>instead of the expected error page or the page hangs, depending on the >>browser. >> >>Has anyone gotten both forms of output control to work together without >>ill side effects?? >> >>Thanks >> >>-- >>Gerard Samuel >>http://www.trini0.org:81/ >>http://dev.trini0.org:81/ >> >> >> >> > > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] flaking out on foreach
Bad code. Take the ';' off the end of the foreach... ROBERT MCPEAK wrote: >Why is this code: > > > $bob=array(1,2,3,5,6); > > foreach($bob as $foo); > { > echo "$foo"; > } > ?> > >Rendering only "6". That's it. Just "6". What am I missing here? > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHPSESSID appended to URL on initial page load
Actually, over the weekend, I started using sessions in my scripts. All I did was start it using session_start(); I only noticed this behaviour using Opera 6.02 Linux browser running under FBSD 4.6-Stable. (It may have happened in mozilla 1.0 r3, but I may have not paid attention to it). I load the page the first time and the PHPSESSID is appended to the url. All links on the pages has the same appended SID. Then a reload clears it away. I thought it was something in my code since Im not too familiar on session usage. Im running php 4.2.2 on FBSD 4.6.2-Release. Thx Monte Ohrt wrote: > Hi, I have a few questions with php sessions, below is an example script: > > test_sess.php > - > > > session_cache_limiter(""); > session_start(); > > ?> > local path > > > > When I initially load the file (session cookie gets set), the HREF > link gets the PHPSESSID appended to it. If I reload the page (cookie > already set) the appendage goes away. > > According to the PHP manual, the PHPSESSID gets appended to the URL > only in the case the session cookie is not accepted by the browser. > > I would guess that on the first page load the server has no way of > knowing if the browser accepted the cookie. So maybe this is > intentional? I'm trying to figure out how to avoid PHPSESSID in the > URLs entirely unless the browser does not accept cookies. I suppose I > could disable URL rewriting altogether and rely soley on cookies. How > do I disable PHP session URL rewriting? I don't see a setting in > php.ini for it. > > PHP 4.2.2, Solaris Sparc > > > TIA > Monte > > php.ini > --- > > > > [Session] > ; Handler used to store/retrieve data. > session.save_handler = files > > ; Argument passed to save_handler. In the case of files, this is the > path > ; where data files are stored. Note: Windows users have to change this > ; variable in order to use PHP's session functions. > session.save_path = /export/tmp > ; Whether to use cookies. > session.use_cookies = 1 > > > ; Name of the session (used as cookie name). > session.name = PHPSESSID > > ; Initialize session on request startup. > session.auto_start = 0 > > ; Lifetime in seconds of cookie or, if 0, until browser is restarted. > session.cookie_lifetime = 0 > > ; The path for which the cookie is valid. > session.cookie_path = / > > ; The domain for which the cookie is valid. > session.cookie_domain = > > ; Handler used to serialize data. php is the standard serializer of PHP. > session.serialize_handler = php > > ; Percentual probability that the 'garbage collection' process is started > ; on every session initialization. > session.gc_probability = 1 > > ; After this number of seconds, stored data will be seen as 'garbage' and > ; cleaned up by the garbage collection process. > session.gc_maxlifetime = 1440 > > ; Check HTTP Referer to invalidate externally stored URLs containing ids. > session.referer_check = > > ; How many bytes to read from the file. > ;session.entropy_length = 0 > session.entropy_length = 32 > > ; Specified here to create the session id. > ;session.entropy_file = > session.entropy_file = /dev/urandom > > ; Set to {nocache,private,public} to determine HTTP caching aspects. > session.cache_limiter = nocache > > ; Document expires after n minutes. > session.cache_expire = 180 > > ; use transient sid support if enabled by compiling with > --enable-trans-sid. > session.use_trans_sid = 1 > > url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry" > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dumb Question
And I feel foolish asking... What is meant by 'procedural code' ??? -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dumb Question
Google didn't have much to offer. But if I should also check 'object-oriented' then I believe it deals with classes. I thought it was something else. Just trying to figure out if phpdoc is for me, which it seems like its not :( Thanks @ Edwin wrote: > My "dumb" answer :) > > Try Google. Type: > > "procedural code" > > You might want to check, > > "object-oriented" > > as well... > > I'm sure, you'll find helpful explanations... > > - E > >> >> And I feel foolish asking... >> What is meant by 'procedural code' ??? >> >> -- >> Gerard Samuel >> http://www.trini0.org:81/ >> http://dev.trini0.org:81/ >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > _ > $B2q0wEPO?$OL5NA!&=< http://auction.msn.co.jp/ > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dumb Question
Here is my stab at it. One person described it as the opposite of OO. So something similar to -> would be considered "procedural code". If Im wrong I stand corrected Michael Sims wrote: >On Sat, 31 Aug 2002 14:04:11 -0400, you wrote: > > > >>And I feel foolish asking... >>What is meant by 'procedural code' ??? >> >> > >It's the opposite of "declarative code". Here's a page that briefly >explains the difference: > ><http://www.wdvl.com/Authoring/DB/SQL/BeginSQL/beginSQL2_1.html> > >and > ><http://www.wdvl.com/Authoring/DB/SQL/BeginSQL/beginSQL2_2.html> > >There may be other contexts that the term "procedural" could be used >in, and if so it may have other meanings that I am not aware of > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regex help
Im trying to apply htmlspecialchars() to hrefs in a string. Here is what I have. my friend! this message uses html entities http://www.trini0.org";>test!'; $str = preg_replace('/(.*<\/a>)/', htmlspecialchars("$1"), $str); print($str); ?> Any help would be appreciated. Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Info into Class
Are there any rules as to how information from outside a class can be moved into it. What Ive been doing so far is 1. Through the constructor 2. defining a constant 3. Create a method whose sole purpose is to move data from the outside into the class. i.e. bar = $bar; } .. } // class constructor here ... $class->outside_data($php); ?> -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Comments in code
I just started writing comments in my code for use with phpdocumentor. And Im beginning to wonder if too many comments is a *bad* thing. I was wondering about file size, but dont think that can be avoided, and php's parser speed. Nothing bad, just looking to see what others have to say about it. Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Attack of the ghost double slash??
A few months ago, I wrote a bit of code to stripslash() "PATH_TRANSLATED" on a w2k box, because, php was reporting it with double slashes like C:\\winnt\\some_dir Today I noticed that the code is broken because PATH_TRANSLATED is now reported with one slash like C:\winnt\some_dir Does anyone know when paths contain double slashes on a w2k box, so that I can anticipate for them?? Thanks for any insight you may provide. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Attack of the ghost double slash??
Thanks much, that made all the difference in the world. The function would be get_magic_quotes_gpc() Chris Shiflett wrote: > Gerard, > > The most likely reason is a php.ini configuration called magic_quotes. > When enabled, PHP will automatically add slashes to single and double > quotes, as well as slashes themselves (to escape them). This is > helpful in some environments to help protect against attacks that can > be used to execute arbitrary database commands. However, this > particular setting is one of the more annoying ones, in my opinion, > because it makes it more difficult to write portable code. > > Hopefully this answers your question, and you can just check your > php.ini. If you need to dynamically check the configuration, there is > a function that will give you the setting of magic_quote. A quick > reference in the manual will give it to you. > > Oh, also, you cannot disable this per script, because the slashes are > added perior to the data being given to PHP, hence prior to your > script's execution. > > Happy hacking. > > Chris > > Gerard Samuel wrote: > >> A few months ago, I wrote a bit of code to stripslash() >> "PATH_TRANSLATED" on a w2k box, because, >> php was reporting it with double slashes like C:\\winnt\\some_dir >> >> Today I noticed that the code is broken because PATH_TRANSLATED is >> now reported with one slash like C:\winnt\some_dir >> Does anyone know when paths contain double slashes on a w2k box, so >> that I can anticipate for them?? >> >> Thanks for any insight you may provide. > > > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] unlink() and IIS
Im running a dev box with IIS 5/Apache/php 4.1.2 I just noticed that part of a script that is supposed to delete a file isn't working under IIS but is under Apache. Under IIS, php is installed as isapi. Paths are correct, and the file in question is created by the script and according to the permissions, SYSTEM has full access to the file. MARC and user notes under unlink() didn't reveal anything about why unlink() works for some and not for others. Code snippet in question -> -- $log = '../../includes/error/error.log'; if (isset( $_POST['Reset'] )) { if (!unlink($log)) { trigger_error('UNABLETORESETLOGFILE' , E_USER_WARNING ); } } Can anyone shed any light for me. Thanks for any insight you may provide. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] form and php
I believe -> Test Test Tao Hou wrote: >Hi, >I jsut install apache1.3.26 and php 4.2.3 on my win2000 machine for my >course project. > >when I run: >phpinfo(); >?> >everything works fine, it will show me the information. but when I try >the followings, it give me an error: > > >test.html > > >This page is for Power Calculation > > >Variable 1: >Variable 2: > > > > > > > >testphp1.php > >Test > >Test >$tmp = 20; >print("the value of tmp variable is $tmp"); >print("the first variable is $varone"); >print("the second variable is $vartwo"); >?> > > > >error message > >Test > >the value of tmp variable is 20 >Notice: Undefined variable: varone in c:\apache\htdocs\testphp1.php on >line 8 >the first variable is >Notice: Undefined variable: vartwo in c:\apache\htdocs\testphp1.php on >line 9 >the second variable is >*** > >please help me, thank you > > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] running slow on Win2k
I have a dev setup running IIS/MSSQL & Apache/MySQL on a w2k box with 800PIII/128M Ram. It flies for me. php 4.2.2 as isapi Support @ Fourthrealm.com wrote: > Hi everyone, > I notice that my PHP runs really slow on Win2k Server w/ IIS 5, and > even slower when accessing a mySQL database. It's a PIII-800 with > 256MB RAM. It is otherwise a great machine, and fast. > > Any suggestions? > > Peter > > > - - - - - - - - - - - - - - - - - - - - - > Fourth Realm Solutions > [EMAIL PROTECTED] > http://www.fourthrealm.com > Tel: 519-739-1652 > - - - - - - - - - - - - - - - - - - - - - > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Regex Help
Im trying to explode a string into an array of words using -> $title = preg_split('/[^\w\']/', $title, -1, PREG_SPLIT_NO_EMPTY ); It seems to work well with words like "this" and "don't" but it doens't work with words with accents to it like "Guantánamo" Could my regex be expanded to handle non-english type characters, or any workarounds to get a string into an array of words, where the string contains non english characters?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ^M at the end of each line when I use php to write file
Im not sure, but I believe Ive noticed this when I fopen() a file with the 'b' value like fopen($foo, 'wb'); I may be totally wrong... Brandon Orther wrote: Hello, Does anyone know a way around all the ^M at the end of each line that my php file writes to on a linux box? Brandon Orther WebIntellects Design/Development Manager <mailto:brandon@;webintellects.com> [EMAIL PROTECTED] 800-994-6364 <http://www.webintellects.com/> www.webintellects.com -------- -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] xml parser breaking on legal xml chars
Im some what new to xml but I've put together a basic xml parsing script, and for some reason, on data like -> It's been a few days since... the parser thinks its 3 lines. Its parsing a new line on htmlentities like ' So with the above line the looped output is like -> Data --> It Data --> ' Data --> s been a few days since Here is a downsized version of the script Im working with -> - class XMLParser { var $xmlparser; function XMLParser() { $this->xmlparser = xml_parser_create(); xml_set_object($this->xmlparser, $this); xml_set_element_handler($this->xmlparser, 'start_tag', 'ending_tag'); xml_set_character_data_handler($this->xmlparser, 'character_handler'); xml_parser_set_option ($this->xmlparser, XML_OPTION_CASE_FOLDING, FALSE); } function parse($data) { xml_parse($this->xmlparser, $data); } function parse_File($xmlfile) { $fp = fopen($xmlfile, 'r'); while ($xmldata = fread($fp, 4096)) { // parse the data chunk if (!xml_parse($this->xmlparser, $xmldata)) { // if parsing fail print the error description and line number echo 'ERROR: '; echo xml_error_string(xml_get_error_code($this->xmlparser)) . ''; echo 'Line: '; echo xml_get_current_line_number($this->xmlparser) . ''; echo 'Column: '; echo xml_get_current_column_number($this->xmlparser) . ''; } } fclose($fp); } function start_tag($xmlparser, $tag, $attributes) { echo 'Opening tag: ' . $tag . "\n"; } function ending_tag($xmlparser, $tag) { echo 'Ending tag: ' . $tag . "\n"; } function character_handler($xmlparser, $data) { echo 'Data --> ' . $data . "\n"; } function close_Parser() { xml_parser_free($this->xmlparser); } } ?> - Thanks for any input you may provide. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] My 2cents on xml/php
This is not meant to put down the php/xml combo. Just putting down my 2 cents from my experience thus far, into the archive for anyone else looking for info. I just started getting deep into parsing xml yesterday, and the dust has just begun to settle. Im parsing rss files versions 0.91 - 2.0 just for content. Before, I was using a class from phpheaven.net, phpsyndication, which basically is using regex to scan/grab content from an rss file. On my PIII 450 dev box running FBSD 4.7, there is a noticeable hit using php's xml functions to parse the rss file. Using siege, http://www.joedog.org/siege/index.shtml, I did some before and after tests. Im experiencing on average a 9-14% drop in number of requests my script can handle. And for some reason, the percentage drop is a bit larger when parsing rss 2.0 files. (Maybe my code). But I going to accept this, and Im going to keep my new code. I have plans to use caching in my script at a later date, so its not going to be too bad. So xml may have some advantages, but in my opinion, if you're going to use it extensively in your scripts, consider caching its final destination, because, using php xml functions to parse xml is going to add overhead to your script. Thats my 2 cents... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Your opinion on globals/reference
Something I just thought of about using global in a function. Mostly I global objects in a function like -> function foo() { global $bar_object; $bar_object->do_something(); } Is it better, more effiecient, if I pass it by reference, like -> function foo(&$bar_object) { $bar_object->do_something(); } Thanks for your thoughts... -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Geographic IP location
Try GeoIP. http://www.maxmind.com/app/php olinux wrote: Hi all, I am looking for a way to determine the geographic location based on IP address. I understand that 100% accuracy is impossible. Does anyone know of a good software or service provider that provides quality geographic detection to US state level based on IP of website visitors. I have tried several and find that they simply use whois records. This is great but seems highly inaccurate. Ideally I am looking for a utility that I can feed a list of IP's to and then use this data to update mysql records. These two services look pretty decent. http://www.geobytes.com http://www.serviceobjects.com/products/dots_ipgeo.asp Thanks for any input, olinux __ Do you Yahoo!? HotJobs - Search new jobs daily now http://hotjobs.yahoo.com/ -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Your opinion on globals/reference
That is true. Didn't think about it like that. Thanks for your input.. rolf vreijdenberger wrote: but what if you decide later you want more objects or globals in your function?? your parameter list could get quit long! -- Rolf Vreijdenberger De Pannekoek en De Kale W: www.depannekoekendekale.nl "Gerard Samuel" <[EMAIL PROTECTED]> schreef in bericht news:3DC54436.2090803@;trini0.org... Something I just thought of about using global in a function. Mostly I global objects in a function like -> function foo() { global $bar_object; $bar_object->do_something(); } Is it better, more effiecient, if I pass it by reference, like -> function foo(&$bar_object) { $bar_object->do_something(); } Thanks for your thoughts... -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Resource type numbers
Im debugging a script that opens a connection to a pop3 server. When I var dump the return of fsockopen() from the script Im debugging, I get -> resource(38) of type (socket) I made up a dummy script to see what I would get and the return of fsockopen is -> resource(1) of type (socket) My dummy script is able to to recieve a +OK from the pop3 server but the other file is getting an empty string. Is there a difference between 1 and 38?? Thanks... --- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Socket Connections Was: Re: [PHP] Resource type numbers
Ok, I think I found out why the script Im debbugging is returning an empty string. 1. It opens a socket to the mailserver with fsockopen 2. It checks the greeting by reading using fgets() 3. Then it check the reponse by supplying the username to the fsockopen() connection 4. It returns an empty string. It seems as if the first time fgets() was used on the open connection, it reads it to EOF. Any further attemps would fail because the data from the socket connection is at EOF. I tried to rewind() it, but rewind() doens't take socket resource. So, going by what this script is trying to do, (I have no experience with this), is it correct to assume, that with each attempt to talk to the server, a new connection must be made to read data from it?? If you want more info, feel free to ask... Thanks Gerard Samuel wrote: Im debugging a script that opens a connection to a pop3 server. When I var dump the return of fsockopen() from the script Im debugging, I get -> resource(38) of type (socket) I made up a dummy script to see what I would get and the return of fsockopen is -> resource(1) of type (socket) My dummy script is able to to recieve a +OK from the pop3 server but the other file is getting an empty string. Is there a difference between 1 and 38?? Thanks... --- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP and UTF-8
Do you store this utf-8 stuff only in xml files?? Do you use a database? I was under the impression that mysql doesn't support utf-8 [EMAIL PROTECTED] wrote: I utf8_encode and utf8_decode all data that I put into XML files. The application is on a large site so it is thoroughly tested and has encoded and decoded data without problems. I have run the application on Linux Slackware and FreeBSD. Quoting Charles Wiltgen <[EMAIL PROTECTED]>: Hello, I anyone out there using UTF-8 for files and databases? I want to use it for everything, and it'd be a major hassle if PHP's UTF-8 support was super- dependent on underlying OS issues, so any feedback is appreciated. -- Charles Charles Wiltgen wrote... How mature is PHP's support for UTF-8, real-world? Is it ubiquitous enough to use for commercial applications that'll be running on systems that you don't configure yourself? From the notes in the documentation, it sounds like there are dependencies on the underlying OS, and that I wouldn't be able to count on this functionality. I'd love to hear about the experience of list members who use this on many different PHP platforms. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] error handler
I got an error handler setup, and Im using trigger_error() to do certain things. function errorhandler($type, $msg, $file, $line) { switch ($type) { /* case E_NOTICE: $exit = FALSE; break; */ case E_USER_WARNING: pretty_error_display($msg); $exit = TRUE; break; case E_USER_ERROR: error_display($msg); break; default: return; } $date = date('D, M d Y H:i:s'); $msg = sprintf("[%s]: %s in %s on line %d\n", $date, $msg, $file, $line); $test = error_log($msg, 3, './error/error.log'); if ($exit === TRUE) exit; } When I trigger and error with E_USER_ERROR, it executes error_display() but it continues to display the rest of the content for the page. I thought E_USER_ERROR stops execution of the script. Thanks for any input. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] use of fsockopen
Im trying to modify a script that fetches rss newfeeds. I was using fopen, but I decided to use fsockopen() for the timeout value. -- --- Does anyone see anything wrong with this code?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] use of fsockopen
Oh I forgot to mention that its not writing any content to the cache file... Gerard Samuel wrote: > Im trying to modify a script that fetches rss newfeeds. > I was using fopen, but I decided to use fsockopen() for the timeout > value. > -- > $data = ''; > $filehandle = fsockopen ($sourceurl, 80, $errno, $errstr, 5); > if (!$filehandle) > { >$data = $errstr; > } > else > { >while (!feof($filehandle)) >{ > $data .= fgets($filehandle, 1024); >} > } > > $cacheFile = fopen( _CACHEDIR. $cacheFile, "w"); > fwrite($cacheFile, $data); > fclose($cacheFile); > fclose($filehandle); > ?> > ------- > > Does anyone see anything wrong with this code?? > Thanks > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PEAR Benchmark & other benchmark techniques??
Im looking for ways to benchmark my script. I read on O'Reilly that I could use PEAR, and I tried it a few weeks ago when I was running php 4.1.2. Today I upgraded to php 4.2.1 and when I try to include the benchmark the script is unable to find the PEAR benchmark class.| include_once("Benchmark/Timer.php");| Warning: Failed opening 'Benchmark/Timer.php' for inclusion (include_path='.:/usr/local/lib/php') Also on a side note, I dont know much about benchmarking utilities, but what else is out there for windows/bsd?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Date?
Speaking of which. I was thinking about this this morning. Is there a part of the Unix timestamp that tells php what timezone to report. Reason why I ask, is I would like to offset the unix timestamp relative to where a server is to a particular user. So lets say the user is in Europe, and the server is in USA and the script is set to display date as 'H:i T', and I offset the unix timestamp to the user in Europe, would the timezone adjust to the European timezone... Im going to try on a windows box where I can change the date easily and see what happens... John Taylor-Johnston wrote: >I added a comment to the FAQ: >http://www.php.net/manual/en/function.date.php > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Date?
Ill look into gmdate. I was going to get the timezone from the user to store in the database.. David Freeman wrote: > > Speaking of which. I was thinking about this this morning. > > Is there a part of the Unix timestamp that tells php what > > timezone to > > report. > >You could use the gmt-based date manipulation to do this. > > > Reason why I ask, is I would like to offset the unix > > timestamp relative > > to where a server is to a particular user. > > So lets say the user is in Europe, and the server is in USA and the > > script is set to display date as 'H:i T', and > >Your main problem will be in identifying where the user is. Probably >the only truly reliable way is to ask them to tell you what their time >zone is. Pretty much every other method will result in a percentage of >inaccurate reporting - the degree of error will be dependant on the >method chosen. > >CYA, Dave > > > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO Question
Im no OO coder but I did try this before. I made (well started to anyway) a class that uses two other classes, and yes, $this->that->do_something() did work for me Jay wrote: >I was wondering can I create a new Object inside of a different class? > >class One >{ >//constructor >function One >{ >$this->two = new Two; >$this->test = $this->two->test(); >} >} > >Can you do that? If so is that how you do it? > >Thanks. > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] regex
Im expecting a string like foo.png. Im trying to replace 'foo' with another value that I have. Im trying this -> $file = preg_replace('/([a-z][0-9]-_*)(.[a-z]{3,4})/i', $new_file . "$2", $_FILES['upload']['name']); The second regex group works ok, its the first one I cannot figure out. It is supposed to contain alpha numeric characters and '_' and '-'. Thanks for any input. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regex
Well Ive gotten (.*) and ([a-z]*[0-9]*_*-*) to work thus far as the first group. I would like to avoid option 1, and option 2 doesn't seem right.... Gerard Samuel wrote: > Im expecting a string like foo.png. > Im trying to replace 'foo' with another value that I have. > Im trying this -> > $file = preg_replace('/([a-z][0-9]-_*)(.[a-z]{3,4})/i', $new_file . > "$2", $_FILES['upload']['name']); > > The second regex group works ok, its the first one I cannot figure out. > It is supposed to contain alpha numeric characters and '_' and '-'. > Thanks for any input. > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] printf()
Im trying to make a dynamic printf(). By that I mean -> function this($foo, $bar) { if (strlen($bar) == '0') { print($foo); } else { printf($foo, $bar); } } Now it works if there is one argument passed, but it doesn't when there is more than one. $str = 'should'; this('This %s work', $str); // work $str = 'is, a'; this('This %s just %s test', $str); // doesn't work So I guess, arguments passed to it has to be physical arguments, and not represented in a string. Am I banging my head on a wall with this?? Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] printf()
Well I figured out a solution. Using a combination of explode() to create an array from $bar, check to see if $bar is an array and feed the array to vprintf() Gerard Samuel wrote: > Im trying to make a dynamic printf(). > By that I mean -> > > function this($foo, $bar) > { >if (strlen($bar) == '0') >{ > print($foo); >} >else >{ >printf($foo, $bar); >} > } > > Now it works if there is one argument passed, but it doesn't when > there is more than one. > > $str = 'should'; > this('This %s work', $str); // work > > $str = 'is, a'; > this('This %s just %s test', $str); // doesn't work > > So I guess, arguments passed to it has to be physical arguments, and > not represented in a string. > Am I banging my head on a wall with this?? > Thanks > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_replace
When you think you got it, you don't get it.. Im trying to scan the link for =A-Z0-9_=, dump the '=' and evaluate the remainder as a defined constant. Yes its funny looking, but if I could get this going Im golden. $bar is always returned with '=_L_OL_HERE=' as the link and not 'here' as it supposed to be. Any help would be appreciated. Thanks =_L_OL_HERE='; $bar = preg_replace('/(=)([A-Z0-9_])(=)/e', ' . constant("$2") . ', $foo); echo $bar; ?> -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Escaping escaped chars
Im trying to move some binary strings from mysql to postgresql, and the binary strings has escape chars '\' in them. I was told to double escape them like so -> '\\\' Here is what Im trying -> $data = '\0PZ\0<Îê˜Úµ'; // This is a representation from an mysql dump $data2 = str_replace('/\', '/\/\/\', $data); Im getting -> Unexpected character in input: '\' (ASCII=92) state=1 I guess my str_replace() isn't correct. Am I going about the right way to double escape them. Thanks. -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Escaping escaped chars
One of the guys over on the php-db list told me that to store the binary string correctly in postrgresql, that I would have to double quote whats already there. So in essence, by the time it hits the database, it has to be -> \\\0PZ\\\0<Îê˜Úµ Any suggestions to modify the string like this... Maybe I should be looking into one of the preg functions Thank You. Michael Sweeney wrote: >Just escape the \ with a single escape character. eg. your string >'\0PZ\0<Îê˜Úµ' would end up as '\\0PZ\\0<Îê˜Úµ' - each \ simply >escapes the backslash following it. If you add two backslashes, you end >up with one too many which is what the error is referring to. > > >..micahel.. > >On Thu, 2002-06-20 at 10:59, Gerard Samuel wrote: > > >>Im trying to move some binary strings from mysql to postgresql, >>and the binary strings has escape chars '\' in them. >>I was told to double escape them like so -> '\\\' >>Here is what Im trying -> >> >>$data = '\0PZ\0<Îê˜Úµ'; // This is a representation from an mysql dump >>$data2 = str_replace('/\', '/\/\/\', $data); >> >>Im getting -> >>Unexpected character in input: '\' (ASCII=92) state=1 >>I guess my str_replace() isn't correct. >> >>Am I going about the right way to double escape them. >>Thanks. >> >> > > > > > > -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Stumped.
In a file with functions only, one of the functions is structured like -> function foo() { if (isset($_POST['submit'])) { /* DO SOME SQL */ header('location: x'); } else { /* SHOW A FORM HERE */ } } I noticed today that when I turned off output buffering, that the header redirect doesn't work anymore... I turned on E_ALL error reporting, and I didn't get any errors. I checked the file that called on this particular file, and there is no 'white space' before or after I checked all included files that this function calls on and there is no 'white space' before or after Are there any other reasons why header() would fail while output buffering is off. Im running php 4.2.1 on FreeBSD 4.5-R p6 Thanks -- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php