PHP Knowledge Base Update -- July 3rd, 1999
[email protected] (Nathan Wallace) Sun, 4 Jul 1999 07:42:31 -0500
| Newsgroups | php.kb |
|---|---|
| Message-ID | <[email protected]> |
I've improved the search engine marginally. It now searches the
questions for matches to your query. I have also changed the
presentation of results so that each answer is only displayed once with
all it's questions listed.
Cheers,
Nathan
------------------------------------------------------------
How can I create a cookie that works with both www.mydomain.com and
mydomain.com?
Is a cookie set for www.mydomain.com sent in a query to mydomain.com?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/362
------------------------------------------------------------
Flint Doungchak, Tom Henry, Jim Winstead, Steve Lianoglou
Cookies only work for the exact domain name that they are set. For
example:
SetCookie("Cookie",$value,"time()+3600","/dir/","www.mydomain.com",0);
sets a cookie that will only ever be sent by the client to the server if
the server domain name is *www.mydomain.com. The client looks to see if
the cookie domain matches exactly the tail end of the request domain.
Reading the Netscape Cookie Specification:
http://home.netscape.com/newsref/std/cookie_spec.html
you will learn that the domain in the cookie must contain two periods
(.). This is to prevent people setting a cookie that might be sent to
every .com domain for example. That means that a cookie like this:
SetCookie("Cookie",$value,"time()+3600","/dir/","mydomain.com",0);
will not be remembered by the browser.
This is a problem because often people access the same site using both:
http://www.mydomain.com
http://mydomain.com
so neither of the cookie setting techniques above will work.
You can set a single cookie that will work for both of these domains by
including a leading period in the domain name.
SetCookie("Cookie",$value,"time()+3600","/dir/",".mydomain.com",0);
The difference is that ".domain.com" sets a domain-wide cookie (which
will be sent to http://domain.com, http://www.domain.com, and
http://whatever.domain.com). Without the leading ".", it will only
get sent to that specific hostname.
An alternative solution, is to redirect people who log in to
http://mydomain.com
to the site (with www.mydomain.com cookie):
http://www.domain.com
but this may inconvenience some users.
------------------------------------------------------------
Is the memory used by variables freed automatically during script
execution?
Do I need to explicitly free the memory used by variables in PHP
scripts?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/364
------------------------------------------------------------
Zeev Suraski
You shouldn't worry about PHP variables consuming memory, except for
very specific cases when you use indirect reference to variable names
and reference different variables in every iteration (extremely rare).
If you use the same variables all throughout the loop (which is almost
always the case), only the memory necessary to store the current value
of the variable(s) remains allocated. The old values are freed and do
not consume memory.
------------------------------------------------------------
Why isn't eregi_replace() working?
http://www.e-gineer.com/e-gineer/phpkb/view.phtml/qid/361
------------------------------------------------------------
B. Szyszka, Chad Cunningham, Fred Isler
A common error when using eregi_replace() is forgetting to assign the
processed string to a variable. In the following example, we need to
replace the angle brackets with their corresponding HTML representations
so the brackets will show up in the browser:
<?php
$one = "String like this <with stuff in brackets>";
eregi_replace("<", "<", $one);
eregi_replace(">", ">", $one);
echo "$one\n\n"
?>
When we echo $one to the browser, this is all we see:
String like this
The brackets haven't been replaced, so the rest of the string is hidden.
The solution: assign the results of eregi_replace() back to the
original variable:
<?php
$one = "String like this <with stuff in brackets>";
$one = eregi_replace("<", "<", $one);
$one = eregi_replace(">", ">", $one);
echo "$one\n\n"
?>
This time when we echo to the browser, we see this:
String like this <with stuff in brackets>
In the first example, eregi_replace() had nowhere to return the
processed string. In the second example, we returned the process string
back to $one, and the changes were saved.
------------------------------------------------------------
Why won't my table display in the browser?
Why do my tables only work in Internet Explorer, and not Netscape?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/366
------------------------------------------------------------
Stephen Benjamin
Netscape is very picky about tables. If you are missing the closing
tags on a table, for example just:
</td></tr>
</table>
Netscape will not show any of the table.
Internet Explorer is a little more forgiving, it will display your table
properly in many cases even if the HTML is a little malformed.
The moral, test your tables using Netscape.
------------------------------------------------------------
What does a "too few parameters" error message mean?
What is a common cause of the "too few parameters" error message?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/368
------------------------------------------------------------
Brad Marsh
When inserting data into a database it expects a certain number of
parameters, one for each column in the table. If you use the insert
sytax to specify the columns then you need to provide data for each
column.
If you do not specify as many parameters as there are columns then you
will get a "too few parameters" error.
This may also occur when you do not format your SQL correctly. In
particular you need to be careful to include single quotes around
strings.
An example:
$fname = fname;
$lname = lname;
$connection = odbc_connect("phpdb","","");
$query = "INSERT INTO patient (fname, lname) ";
$query .="VALUES ($fname, $lname) ";
gives the following error:
Warning: SQL error: [Microsoft][ODBC Microsoft Access 97 Driver] Too
few parameters. Expected 2., SQL state 07001 in SQLExecDirect in
c:\apache136\htdocs/newpatient.php3 on line 8
But if you use single quotes around the names when creating your query
above like so:
$query = "INSERT INTO patient (fname, lname) ";
$query .="VALUES ('$fname', '$lname') ";
the error will not occur.
------------------------------------------------------------
Is there an ISAPI or NSAPI version of PHP?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/372
------------------------------------------------------------
Rasmus Lerdorf
There will be ISAPI and NSAPI versions of PHP4. They are not available
for PHP3.
------------------------------------------------------------
Is there a module version of PHP available for Windows?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/373
------------------------------------------------------------
Rasmus Lerdorf
There is no module version of PHP3 for Windows, you have to run PHP as a
CGI program.
------------------------------------------------------------
Can PHP be run using fast cgi?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/374
------------------------------------------------------------
Rasmus Lerdorf
No PHP cannot be run under fastcgi.
------------------------------------------------------------
Can safe mode be used on a per directory basis?
How can I give my web server users access to only PHP in safe mode?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/375
------------------------------------------------------------
Rasmus Lerdorf
You can turn on php's safe_mode on a per-directory basis. Simply put
'php3_safe_mode On' in the appropriate directory blocks in your
httpd.conf file.
------------------------------------------------------------
How can I read from a file and strip all HTML tags?
What is fgetss() used for?
http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/378
------------------------------------------------------------
Jim Winstead, Zak Greant
Taken from:
http://www.php.net/manual/function.fgetss.php3
Identical to fgets(), except that fgetss attempts to strip any HTML and
PHP tags from the text it reads.