php-general Digest 10 Aug 2003 17:07:36 -0000 Issue 2228
Topics (messages 159018 through 159036):
Re: Simple cookie question
159018 by: Chris Shiflett
159020 by: Justin French
Re: checking the return value of member function with empty
159019 by: Justin French
config tests
159021 by: Uros Gruber
159022 by: John W. Holmes
159023 by: Uros Gruber
159033 by: Curt Zirzow
Why Redirection works on 1 machine but not on another
159024 by: Ow Mun Heng
159025 by: John W. Holmes
159026 by: David Otton
need help with table lock - could this be performed with mysql commands or do I to
write my own PHP function
159027 by: anders thoresson
159034 by: Curt Zirzow
PHP5 on IIS
159028 by: Gerard Samuel
Container functions....
159029 by: Mike Morton
does PHP have a equivalent to the C++ #ifndef #define?
159030 by: Dan Anderson
159031 by: Miles Thompson
159032 by: David Nicholson
159035 by: Curt Zirzow
HELP strip slashes ???
159036 by: Didier McGillis
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
--- Liam Gibbs <[EMAIL PROTECTED]> wrote:
> Does it have to be a cookie? I use the IP address and store
> that somewhere.
Please don't. An IP address is a terrible means of user identification.
I would explain why, but I think it would be more informative to search through
the archives, as previous explanations have been quite good.
Chris
=====
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/
--- End Message ---
--- Begin Message ---
On Sunday, August 10, 2003, at 01:36 PM, Liam Gibbs wrote:
Does it have to be a cookie? I use the IP address and store that
somewhere.
Liam, please don't advise relying on the IP address for anything. It's
been discussed to death on the list before, but in short, the
highlights are:
1. users sharing a connection behind a firewall or router will often
all have the same IP address
2. users of larger ISPs (AOL being the widely documented example) will
often have a new IP address for each request they make
Justin
--- End Message ---
--- Begin Message ---
Count the number of ('s and )'s, or get a text editor which can help
you balance them out in some way:
1 2 3 321
if (!empty($this->GetParam('someparameter'))) {
// foo
}
This *SHOULD* be syntactically correct, but php doesn't think so.
Should I file a bug on this one?
Oh yeah, normal information about running environment.
PHP version 4.3.2
You file a bug to whoever wrote the code :P
Seriously, find a text editor that highlights or somehow assists you
with matching up your braces... BBEdit (mac) beeps and/or flashes the
screen when you screw up, and when you double-click on a brace, it
highlights all the code all the way up or down to the matching brace at
the other end.
Crimson editor (PC) underlines the matching brace when you highlight it.
If all else fails, count :)
Justin
--- End Message ---
--- Begin Message ---
Hello!
I just made some speed tests getting configuration from DB.
For now I figured 2 ways doing this.
1. One value in each row
id | name | val
----------------------
1 | name1 | value1
........
2. using serialize($config) and saving this in one row.
$config is predefined array of configuration.
I test this with 100 config values. First I read all 100 rows for 1st
example, then I read only one row and then unserialize this to get
array.
Here is result:
1st example 0.0478450059891 86.74%
2nd example 0.0073139667511 13.26%
There you can see speed of second example. I wan't to know what do you
think about this. And what's your solutions of reading config from DB.
I saw that many big project still use first example.
--
Best regards,
Uros
--- End Message ---
--- Begin Message ---
Uros Gruber wrote:
Hello!
I just made some speed tests getting configuration from DB.
For now I figured 2 ways doing this.
1. One value in each row
id | name | val
----------------------
1 | name1 | value1
........
2. using serialize($config) and saving this in one row.
$config is predefined array of configuration.
I test this with 100 config values. First I read all 100 rows for 1st
example, then I read only one row and then unserialize this to get
array.
Here is result:
1st example 0.0478450059891 86.74%
2nd example 0.0073139667511 13.26%
There you can see speed of second example. I wan't to know what do you
think about this. And what's your solutions of reading config from DB.
I saw that many big project still use first example.
Question: How many people selected 'blue' for their config color?
1. SELECT COUNT(*) FROM Table WHERE config_color = 'blue';
2. ?? SELECT COUNT(*) FROM Table WHERE serialized_column LIKE
'"config_color";s:4:"blue";'
Basically, method 1 is more flexible. With method 2, you'll need to
store it in a TEXT column or hope your serialized value never goes over
255 characters.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
PHP|Architect: A magazine for PHP Professionals – www.phparch.com
--- End Message ---
--- Begin Message ---
Hi,
You don't need to do that way. I also test speed if you select for
example 5 diferent values. You get 5 queries.
I just select everything in one place then I use
$config['config_color']
or you can write some function getConfig('config_color') to get
selected value from this array.
I use text to store this because there's no need to index this.
I also make some script to easy add and remove config values.
But I agree with you that 1st one is more flexible.
--
Best regards,
Uros
Sunday, August 10, 2003, 10:32:13 AM, you wrote:
JWH> Uros Gruber wrote:
>> Hello!
>>
>> I just made some speed tests getting configuration from DB.
>>
>> For now I figured 2 ways doing this.
>>
>> 1. One value in each row
>>
>> id | name | val
>> ----------------------
>> 1 | name1 | value1
>> ........
>>
>> 2. using serialize($config) and saving this in one row.
>> $config is predefined array of configuration.
>>
>>
>> I test this with 100 config values. First I read all 100 rows for 1st
>> example, then I read only one row and then unserialize this to get
>> array.
>>
>> Here is result:
>>
>> 1st example 0.0478450059891 86.74%
>> 2nd example 0.0073139667511 13.26%
>>
>> There you can see speed of second example. I wan't to know what do you
>> think about this. And what's your solutions of reading config from DB.
>> I saw that many big project still use first example.
>>
JWH> Question: How many people selected 'blue' for their config color?
JWH> 1. SELECT COUNT(*) FROM Table WHERE config_color = 'blue';
JWH> 2. ?? SELECT COUNT(*) FROM Table WHERE serialized_column LIKE
JWH> '"config_color";s:4:"blue";'
JWH> Basically, method 1 is more flexible. With method 2, you'll need to
JWH> store it in a TEXT column or hope your serialized value never goes over
JWH> 255 characters.
--- End Message ---
--- Begin Message ---
* Thus wrote Uros Gruber ([EMAIL PROTECTED]):
> Hello!
>
> I just made some speed tests getting configuration from DB.
>
> For now I figured 2 ways doing this.
>
> 1. One value in each row
>
> 2. using serialize($config) and saving this in one row.
> $config is predefined array of configuration.
>
> ...
> Here is result:
>
> 1st example 0.0478450059891 86.74%
> 2nd example 0.0073139667511 13.26%
>
IMO, the serialize vs. db rows time is significant (although many
might argue that.)
I think the biggest draw back is that you loose structure of the
config by realying on just a defined array in php. Using the db
rows enables an easier interface with adding, changing and removing
values in the config.
I think the best solution would be is to use both of them. Having
the database structure there for modifications and such. Then use
the serialize method for the website. So the serialize would be
like a cache of what is actually stored in the db.
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."
--- End Message ---
--- Begin Message ---
Hi,
I have this peculiar problem, my header
header( "Refresh:2;url=$g_prog_path/$l_refresh_url" );
is set up correctly to be the FULL pathname. It works on some PC but now on
some others. I'm using IE on win98/2000. The offending one is IE6 (128bit)
on Win98. (IE5.5/win98 works but I've yet to try it on another win98/ie6)
Any ideas?
Cheers,
Mun Heng, Ow
H/M Engineering
Western Digital M'sia
DID : 03-7870 5168
--- End Message ---
--- Begin Message ---
Ow Mun Heng wrote:
Hi,
I have this peculiar problem, my header
header( "Refresh:2;url=$g_prog_path/$l_refresh_url" );
is set up correctly to be the FULL pathname. It works on some PC but now on
some others. I'm using IE on win98/2000. The offending one is IE6 (128bit)
on Win98. (IE5.5/win98 works but I've yet to try it on another win98/ie6)
This is a client side issue, not a PHP issue. Make sure you have the
correct format for you refresh (double check) and then check for bugs in
the browser. Nothing to do with PHP.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
PHP|Architect: A magazine for PHP Professionals – www.phparch.com
--- End Message ---
--- Begin Message ---
On Sun, 10 Aug 2003 17:32:21 +0800, you wrote:
> I have this peculiar problem, my header
>
>header( "Refresh:2;url=$g_prog_path/$l_refresh_url" );
>
>is set up correctly to be the FULL pathname. It works on some PC but now on
>some others. I'm using IE on win98/2000. The offending one is IE6 (128bit)
>on Win98. (IE5.5/win98 works but I've yet to try it on another win98/ie6)
I believe that the Refresh: header isn't part of the HTTP/1.1 spec.
Having said that, IE6 does support it.
If the offending browser works against this page
http://www.hixie.ch/tests/evil/mixed/refresh1.http.html
I would assume that your code is at fault - replace header() with echo() and
find out what's really being displayed.
--- End Message ---
--- Begin Message ---
Hi,
For an application that I'm working on, I wan't users to be able to show
content even while an editor/administrator makes changes in one of my
database's tables. But if another editor tries to load the same content for
editing, he/she shouldn't be able to do this.
I've been reading up on MySQL's internal LOCK command, but it doesn't seem
to be what I need. I need a read/write lock based on what the current
user/editor want's to do, and not only based on what content an editor is
working with at the moment.
I'm thinking of the following solution:
Create a new database:
CREATE TABLE table_lock
(
table_name VARCHAR(40),
table_id INT,
PRIMARY_KEY (table_name, row_id)
);
And two functions:
set_lock($table_name, $row_id), check_lock($table_name, $row_id) and
release_lock($table_name, $row_id). Whenever an editor opens some content
for editing, check_lock() will be called to se if table_lock contains a row
with the same table_name and row_id. If, the content isn't loaded and the
editor is told that someone else is working on the content, and are asked
to try again later. If not, set_lock() is called to make sure that no other
editor opens the content before it's saved and release_lock() is called,
which will remove the line from table_lock again.
Is this a good way to do this? Or are there any other suggestions?
--
anders thoresson
--- End Message ---
--- Begin Message ---
* Thus wrote anders thoresson ([EMAIL PROTECTED]):
> set_lock($table_name, $row_id), check_lock($table_name, $row_id) and
> release_lock($table_name, $row_id). Whenever an editor opens some content
> for editing, check_lock() will be called to se if table_lock contains a row
> with the same table_name and row_id. If, the content isn't loaded and the
> editor is told that someone else is working on the content, and are asked
> to try again later. If not, set_lock() is called to make sure that no other
> editor opens the content before it's saved and release_lock() is called,
> which will remove the line from table_lock again.
What happens when the user doesn't finish editing or the browser
simply crashes on him?
If you do use this method, it needs to be atomic. if two users
access the page at the same time they both will pass the
check_lock() function but only one will pass set_lock(), if the
database constraints are enforced.
You'd want something like:
if (! set_lock() ) {
// table is already locked
} else {
// we have the lock
}
Curt
--
"I used to think I was indecisive, but now I'm not so sure."
--- End Message ---
--- Begin Message ---
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...
--- End Message ---
--- Begin Message ---
In a language that I used to program in - for development we used to be able
to make a function that basically just executed everything inbetween:
<hidecode>
Print "This is html printed" <some programming code> Print "this is more
code";
</hidecode>
So basically everything in between hidecode and /hidecode is executed the
same as if the hide code did not exist - except that the hidecode container
would be something like:
Function hidecode() {
if(getenv("remoteaddress")=="myaddress") {
%s (all code contained within the tags)
}
}
So - the question is does PHP have some way that I cannot see to do this?
I realize that I could create a function and pass everything in as an
argument - but that would involve putting everything into variables, and
overall being just a pain in the ass to add and remove the container.
Is PHP too sophisticated a language to be able to do this easily and
quickly? Or am I just missing some form of function that is totally
obvious?
Finally - yes, I know that I could slap an if tag around it - but that is
also a big pain in the ass to add and remove each if tag when you go 'live'
with the change, as opposed to a quick find and replace with a container
function like this...
TIA
--
Cheers
Mike Morton
****************************************************
*
* Tel: 905-465-1263
* Email: [EMAIL PROTECTED]
*
****************************************************
"Indeed, it would not be an exaggeration to describe the history of the
computer industry for the past decade as a massive effort to keep up with
Apple."
- Byte Magazine
Given infinite time, 100 monkeys could type out the complete works of
Shakespeare. Win 98 source code? Eight monkeys, five minutes.
-- NullGrey
--- End Message ---
--- Begin Message ---
I'm coding a really large web page in PHP. One of the problems I run
into is I'll create a function in file inc.function.something.php and it
will need a function included in inc.function.somethingelse.php. If I
require() somethingelse.php in something.php and it's already been
required in main.php, I get an error about the function being defined
twice.
Is there an equivalent to the C++:
#ifndef some_header_file_h
#define some_header_file_h
// insert code that shouldn't be repeated here
#endif // some_header_file_h
Thanks in advance,
Dan Anderson
--- End Message ---
--- Begin Message ---
Not quite, but have a look at the function handling functions:
http://www.php.net/manual/en/ref.funchand.php
particularly
http://www.php.net/manual/en/function.function-exists.php
May not be what you want, but might get you close.
Miles
At 10:42 AM 8/10/2003 -0400, Dan Anderson wrote:
I'm coding a really large web page in PHP. One of the problems I run
into is I'll create a function in file inc.function.something.php and it
will need a function included in inc.function.somethingelse.php. If I
require() somethingelse.php in something.php and it's already been
required in main.php, I get an error about the function being defined
twice.
Is there an equivalent to the C++:
#ifndef some_header_file_h
#define some_header_file_h
// insert code that shouldn't be repeated here
#endif // some_header_file_h
Thanks in advance,
Dan Anderson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hello,
This is a reply to an e-mail that you wrote on Sun, 10 Aug 2003 at
15:51, lines prefixed by '>' were originally written by you.
> I'm coding a really large web page in PHP. One of the problems I
run
> into is I'll create a function in file inc.function.something.php
and
> will need a function included in inc.function.somethingelse.php.
If I
> require() somethingelse.php in something.php and it's already been
> required in main.php, I get an error about the function being
defined
> twice.
You can use the require_once() and include_once() functions
instead of require() and include() to avoid this happening.
All the best,
David.
--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/
Free PHP error handling script: www.phpmachine.com/error-handler/
Professional Web Development by David Nicholson
http://www.djnicholson.com/
QuizSender.com - How well do your friends actually know you?
http://www.quizsender.com/
--- End Message ---
--- Begin Message ---
* Thus wrote Dan Anderson ([EMAIL PROTECTED]):
>
> Is there an equivalent to the C++:
>
> #ifndef some_header_file_h
> #define some_header_file_h
>
> // insert code that shouldn't be repeated here
>
> #endif // some_header_file_h
>
Yes. sort of..
if (! defined('_SOME_HEADER_FILE_H_') ) {
define('_SOME_HEADER_FILE_H_', 1);
} // some_header_file_h
I usually define it like this though, to avoid the extra
indentation.
if (defined('_SOME_HEADER_FILE_H_') )
return; // leave included file
// define header file and continue.
define('_SOME_HEADER_FILE_H_', 1);
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."
--- End Message ---
--- Begin Message ---
Everyone,
I am doing an admin site for a person and their small site. I need to allow
them to put in paragraphs of information. I am allowing them to put in some
HTML like <b>, <br>, <p> <a href=""> a very limited amout of tags. What is
the best way to submit and then show this information to make sure that bad
tags, characters ad quotes dont mess up the code when displaying it.
any help would be appreciated.
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
--- End Message ---