RE: [PHP] Re: session cookies enabled?
Mike, Thanks for the super clear explanation. This brings up a question. In order to decide whether to use cookies or SID the built-in sessions must be testing to see if the user's browser will accept the session cookies. How do they do that? By sending it out and checking to see whether it comes back on the next page. ... That being the case I can never find out (using the built-in sessions) until the second page request and it will always include the session cookie in the URL. Which means the value of the seesion cookie will be exposed, even if I am using SSL. :( Back to the drawing board... Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: session cookies enabled?
Ford, Mike writes: You can also set up php.ini and use the built-in sessions with http://php.net/session_start so that PHP will take care of this for you. That is what I was intending to do. How do I find out if whether or not the session cookie was accepted using the built-in sessions? I found no function for such a test. Check the SID constant after you've done session_start(). If it has an empty value, the session is using cookies; otherwise, it'll have a value of the form 'sessionname=sessionid', which is what is appended to the URL (or inserted in forms as a hidden value) to propagate the session-id. Interesting idea. This brings up a question. In order to decide whether to use cookies or SID the built-in sessions must be testing to see if the user's browser will accept the session cookies. How do they do that? If they do it by the 2 page, send a cookie and see if it comes back to the second page method we have been talking about, then somehow, they are sureptiously inserting a forward to a non- existant page! Right? How do they do that? Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] session cookies enabled?
Hello, How does one check to see if the user's browser accepts session cookies? Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: session cookies enabled?
Richard Lynch writes: How does one check to see if the user's browser accepts session cookies? Apparently I should have said cookie and left off the 's' as that is what I had in mind. Send one cookie, see if it comes back, and if it does, tie everything to that cookie. OK. So how do I see if it comes back? I send the user a page that tries to set a session cookie. That page would then have to forward him to a second page which would check for the cookie being sent. Right? So I there is nothing I can check so I can do it with a single page? You can also set up php.ini and use the built-in sessions with http://php.net/session_start so that PHP will take care of this for you. That is what I was intending to do. How do I find out if whether or not the session cookie was accepted using the built-in sessions? I found no function for such a test. Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Cheap Ping
Hello, I am trying to find a simple way to test to see if a web site is up or not. I tried using $file = file_get_contents(http://www.example.com/page.html;); but when the site is down it takes too long and seems to time out terminating the script rather than returning a false I can test. Is there some way I can set a shorter limit? Or something? Any other suggestions? Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Cheap Ping
Jim Lucas writes: Is there some way I can set a shorter limit? http://us.php.net/manual/en/function.stream-set-timeout.php As far as I can tell I can only use that if I have a stream resource available. Presumably file_get_contents() creates and uses a stream but its resource is not accessible to me, is it? I could write my own file_get_contents() using lower level functions so I would have access to the stream resource used. But I was trying to keep it simple, if I can. Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Random Unique ID
Robert Cummings writes: Bleh, you can solve this with at most 2 queries. Thanks. That is a bit different than what I was thinking about but it might work for my purposes. Thanks also to all the other people who made suggestions. It appears to me that ther are 3 distinct approaches. 1) Generate a random number. Query the DB to see if it has been used before and if so generate another random number and repeat. It seems to me that this would require that the DB be locked for the checking and insertion to make sure a duplicate was not slipped in. 2) Generate a random number. Make a trial insertion for a unique field. If the insertion fails repeat. This functions just like the above but uses Mysql's native behavior to handle the checking so no user locking is necessary. Almost all the time this will require only 1 insertion whereas the above will require 2 or more accesses. 3) Generate a unique identifier from the record sequence number. Since the sequence number is guaranteed to be unique the identifier will also be unique and can be used without any worry. There are various schemes I can think of by which the unique identifier, altho uniquely determined by the sequence number, can be generated so that it will not reveal the sequence number and appear unpredictable. This will require 3 accesses to the DB (insertion, mysql_insert_id, and update). I have a number of options to try and think about. Thanks again. Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Random Unique ID
Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about doing this? Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Random Unique ID
Stut writes: [EMAIL PROTECTED] wrote: I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about doing this? 1) Not even slightly PHP related. Perhaps not. It is Mysql related. And seeing other Mysql discussion on this list inspired me to ask. 2) Why random? Incrementing not good enough for you? I want to use it in a way that will expose it to the user. And I don't want to give out information as to the order of records in my database. Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Random Unique ID
Rabih Tayyem writes: PS: I don't take credit for the code as it is a modified version of a code I found long time back (this same code is running on one of my applications for months without any problem).. Thanks. I'll find use for that! However, altho I know that by making the random number big enough the likelyhood of collisions can be made vanishingly small, I was actually concerned with eliminating the possibility of collisions altogether by checking to see if the number had been used before. I just don't know how to do that properly with Mysql. Perhaps it is necessary to lock to table, check, make the insert and then unlock it. But I was hoping that there would be a simpler way. Best, Craig On 3/21/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about doing this? Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Random Unique ID
Jim Moseby writes: However, altho I know that by making the random number big enough the likelyhood of collisions can be made vanishingly small, I was actually concerned with eliminating the possibility of collisions altogether by checking to see if the number had been used before. I just don't know how to do that properly with Mysql. Perhaps it is necessary to lock to table, check, make the insert and then unlock it. But I was hoping that there would be a simpler way. One way is to make your id field a unique key. MySQL will not let you insert a record with a duplicate unique key, and will issue an error. Your code should always check for errors on insert anyway, so if you get an error, generate a new key and try again. Thanks. Yes, I check for errors. But there are other types of errors so I'd need to verify that it is a duplicate key error and, in my ignorance, I have not yet figured out how to do that programatically. I worry about getting into an infinite loop. Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Stream Functions
Hello, I have been trying to get the stream functions to work in PHP. While undoubtedly my problems are due to ignorance I'd appreciate anything helpful anyone would care to say that might alleviate that ignorance. Basically, I have just been trying to get the examples given in the manual to work for the unix domain. I created the two files below and hit them with my browser. servertest.php -- ?php $socket = stream_socket_server(unix://testsock, $errno, $errstr, STREAM_SERVER_BIND); if (!$socket) { echo ERROR: $errno - $errstrbr /\n; } else { while ($conn = stream_socket_accept($socket)) { fwrite($conn, date(D M j H:i:s Y\r\n)); fclose($conn); } fclose($socket); } ? This appears to be working. It creates the socket file in the file system. Then after a long delay, which I presume is waiting for a client request, it returns the following. Warning: stream_socket_accept() [function.stream-socket-accept]: accept failed: Operation timed out in /usr/local/www/data/servertest.php on line 6 Afterward the socket file is left on the file system. socktest.php ?php $fp = stream_socket_client(unix://testsock, $errno, $errstr); if (!$fp) { echo ERROR: $errno - $errstrbr /\n; } else { fwrite($fp, \n); echo fread($fp, 26); fclose($fp); } ? Running this while the server is waiting (or after it has given up) produces the following. Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to unix://testsock (Connection refused) in /usr/local/www/data/socktest.php on line 2 ERROR: 61 - Connection refused If the socket is removed the message changes to file not found and if the permissions are changed the message changes to permission denied. So the program seems to be finding the socket and have permission to access it. Can anyone suggest why the connection might be refused? Best, Craig -- - Virtual Phonecards - Instant Pin by Email - - Large Selection - Great Rates- - http://speedypin.com/?aff=743co_branded=1 - -- ** ** * Craig Spencer * * [EMAIL PROTECTED]* ** ** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php