LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: Nathan Wallace Date: Sun May 14 20:59:48 2000 Subject: [FAQTS] PHP Knowledge Base Update -- May 14th, 2000
I've added some more entries and did some tidying up. If you see
anything below that you can improve, please don't hesitate to do so:
http://php.faqts.com
cheers,
Nathan
## Unanswered Questions ########################################
-------------------------------------------------------------
How do I add hypertext links (such as 1-10,11-20,next,back etc) using PHP/MySQL to serve portions of query results ?
http://www.faqts.com/knowledge-base/view.phtml/aid/2825
-------------------------------------------------------------
Niketan Pandit
## New Entries #################################################
-------------------------------------------------------------
How can I get the mime type of an uploaded file?
How does PHP work out the mime type of an uploaded file?
http://www.faqts.com/knowledge-base/view.phtml/aid/2828
-------------------------------------------------------------
Nathan Wallace
Brent Sims, Richard Lynch, Dieter Kneffel
Assuming a post method upload, accomplishing this is very very tricky...
$userfile - the temp file name
$userfile_name - gives you the original name
$userfule_size - gives you the file size in bytes
$userfile_type - give you, you guessed it, the mime type.
The hardest part of figuring out how to do all of this was believing it
is just this simple. Upload the file, give it a name and then tack _name
or _size or _type onto that name and, well, that's the size of it...
But, just how careful is the PHP code in determining $userfile_type?
Does it rely on what the browser sent (does the browser say?), or merely
the extension, or does it look at the actual file's contents?
The docs say:
* $userfile_type - The mime type of the file if the browser provided
this information. An example would be "image/gif".
This would lead me to believe that relying on $userfile_type would not
be the most secure idea, since it would not be rocket science for a
malicious user to convince their own computer to lie to your server.
It is not safe at all; We've had some problems with this in the past. As
expectible, most problems occured when using MSIE on MacOS. In our
cases, we were running in the problem that IE did not give any
information about the type, resulting in an empty '$userfile_type'
On the other side, Netscape made no problems at all.
-------------------------------------------------------------
What is the fastest way to get the MD5 checksum of a file?
http://www.faqts.com/knowledge-base/view.phtml/aid/2829
-------------------------------------------------------------
Nathan Wallace
Nathan Benson, Richard Lynch
You could use 'md5sum' through a system/exec call.
(phuzz:tdp-ws--00 ~)$ md5sum lynx_bookmarks.html
62cb158904a682847c4625d556e3843f lynx_bookmarks.html
(phuzz:tdp-ws--00 ~)$
See the exec() function in the manual.
The file would have to be pretty big before the speed of exec() would be
faster than the speed of fopen/fread(,1000000)/fclose though...
Run some tests on varying sizes of sample files on your server and see
where the breakpoint is before you get too carried away.
-------------------------------------------------------------
Why does the a GET variable called quote show up as a quote mark (")?
Can I use quote as the name of a GET variable?
http://www.faqts.com/knowledge-base/view.phtml/aid/2830
-------------------------------------------------------------
Nathan Wallace
Daniel Convissor, Richard Lynch
In HTML """ is the way to escape quote marks. So, when you ask
for
?item=$data[$i]"eid=
^^^^^
" is being replaced by a "
v
?item=31"eid=57
Microsoft assumes its users are too dumb to remember to add the ; at
the end of a character entity, so if IE sees "e, ®, ©, even
as part of something else in a URL (such as you have) IE decides you
must have meant the HTML character entity and renders it as such.
Note that this is just a problem of displaying in the content area: The
URL itself works just fine and dandy.
If you want to fix it, you could use HTMLEntities() on any portion you
expect to be displayed in the content portion of the browser window.
This will replace & with the correct character entity & so then IE
will do the right thing.
I guess technically it's your fault for not using & for & but, jeez,
IE assuming that you meant the & to be the beginning of some other
character entity is just pretty dumb.
-------------------------------------------------------------
Where is a safe temp directory for uploading files in safe mode?
http://www.faqts.com/knowledge-base/view.phtml/aid/2831
-------------------------------------------------------------
Nathan Wallace
Richard Lynch
I think this is explained in the PHP Manual in the section on SAFE MODE.
You'll have to create the directory in your home dir (*NOT* your
web-tree) and give it permissions to allow PHP to write to it.
-------------------------------------------------------------
What is the best way to write an application for different languages?
What is gettext used for?
http://www.faqts.com/knowledge-base/view.phtml/aid/2832
-------------------------------------------------------------
Nathan Wallace
chuck
I'd suggest gettext - there is gettext support in php 3.0.something (6?
9?) and later, and in php4 (compile --with-gettext). There's not much
documentation right now, but it's pretty easy to use - you make the
translations, set the locale, and then put _() around all your strings,
and boom, it works. Fast, and also fairly standard.
-------------------------------------------------------------
I'm new to PHP, where should I start?
http://www.faqts.com/knowledge-base/view.phtml/aid/2836
-------------------------------------------------------------
Nathan Wallace
Well, you've started in a good place. :)
The PHP web site as a lot of useful information:
http://www.php.net
in particular, the manual:
http://www.php.net/manual
One of the best things to do is just get PHP etc installed and start
using it. The best place to do that is with the instructions here:
http://www.e-gineer.com/instructions
## Edited Entries ##############################################
-------------------------------------------------------------
I can upload files and send mails with PHP, how do I attach these files to my mail?
http://www.faqts.com/knowledge-base/view.phtml/aid/1593
-------------------------------------------------------------
Jeroen Keppens, Matt Gregory, Richard Heyes, Fiona Czuczman
Email attachments are really just part of the body of the email. You
must encode them with mime/uuencode or some other standard binary-ascii
encoding standard and then send them in the body of the email.
---
There are various scripts/functions/classes available to help out with
this, one of which is here:
http://phpclasses.upperdesign.com/browse.html/package/32
HTH
Richard Heyes
-------------------------------------------------------------
How do I pass a sting in a url eg. $MyString='Have a nice day' <a href="gretting.php3?greeting=". $MyString This doesn't work as I only get 'have'
http://www.faqts.com/knowledge-base/view.phtml/aid/2780
-------------------------------------------------------------
William Holt, Arcady Novosyolov, Christian Hope, Richard Heyes
%20
Spaces should be replaced by pluses in query strings. To achieve this
use the following code:
<?php // main file
$MyString = 'Have a nice day';
$s = strtr($MyString,' ','+');
echo "<a href=gr.php3?var=$s> Click here</a>";
?>
with called file gr.php3:
<?php // file gr.php3
echo $QUERY_STRING."<br>";
echo $var."<br>";
?>
I'm afraid this will not work. Actually, please remember that "space"
is not allowed in a URL. You should change the string into "Have%20a%
20nice%20day". I think this will work.
Sincerely,
Bill
------
Alternatively, a better way would be the urlencode() function. Like so:
echo '<A HREF="greeting.php3?greeting='.urlencode($MyString).'">';
This will not only deal with spaces, but other questionable characters
too.
HTH
Richard Heyes
-------------------------------------------------------------
How do get the number of columns in a MySQL query?
http://www.faqts.com/knowledge-base/view.phtml/aid/2783
-------------------------------------------------------------
Zlatko Knezevic, Richard Heyes
Like so:
$data = mysql_fetch_row($result);
$num_columns = count($data);
You could also use mysq_fetch_array() but since that brings back an
enumerated array as well as an associative, you will need to divide the
total by two. Like so:
$data = mysql_fetch_array($result);
$num_columns = count($data) / 2;
-------------------------------------------------------------
Help! I can't install PHP4 RC2. I use win98 SE and win-apache 1.3.12. I have entered the information in the apaches httpd.conf
http://www.faqts.com/knowledge-base/view.phtml/aid/2799
-------------------------------------------------------------
Emir Musabasic, William Holt
I'll rather suggest you to use OmniHTTP. I've configured it for PHP4
RC2 on my NT in one minute.
-------------------------------------------------------------
Does PHP work with Lotus Notes?
http://www.faqts.com/knowledge-base/view.phtml/aid/2808
-------------------------------------------------------------
Brad Atkins, Nathan Wallace
Richard Lynch
As far as I know, PHP does not run with Lotus Notes.
This question has come up before, though, so maybe one of the askers has
started a port. Check the mailing list archives.
How to make it would be to download the PHP source tarball, then get
ahold
of any Lotus Notes API/source/documentation you can (good luck) and
start
figuring out how the two could relate...
Compare the Notes API to the various database APIs (MySQL, MS-SQL, ODBC,
etc) and look for commonalities -- The database functions in PHP are
thinly disguised wrappers around the underlying database API.
http://cvs.php.net may be useful.
I've almost completed a base for Lotus Notes. Have a few more things to
do, then I'm committing it to the PHP 4 cvs. If you have any questions,
just email me about it. brad@youreshop.com
-------------------------------------------------------------
Is there a ORACLE - PHP dedicated mailing list?
http://www.faqts.com/knowledge-base/view.phtml/aid/1284
-------------------------------------------------------------
Andrew Sheh, Nathan Wallace
It is not as popular as the main list, but if you have Oracle
questions, SEND an email to:
php-oracle@stetson.edu
In the BODY:
subscribe php-oracle
Andrew Sheh
-------------------------------------------------------------
Do PHP3 or PHP4 support Windows Component Object Model framework?
http://www.faqts.com/knowledge-base/view.phtml/aid/1089
-------------------------------------------------------------
Matt Gregory, Michael Zedeler, Nathan Wallace
At this time PHP does not support COM/DCOM. But then, support under
Linux for COM/DCOM is a little shallow. I can tell you that there will
be a Win32 COM module in PHP4 but I don't know much about it. Perhaps
someone who has been able to find the module can shed more lite on
this. I also know that, as the name implies the module will be a Win32
only module.
-------------------------------------------------------------
What does the $$ mean in variables?
http://www.faqts.com/knowledge-base/view.phtml/aid/2694
-------------------------------------------------------------
harry f, Sheni R. Meledath, Nathan Wallace
$$ is like pointers in C.
I will use an example to describe this:
$a=1;
$b='a';
echo $$b; will display 1.
or
$$b==1;
-------------------------------------------------------------
What does the period do in this statement: $svarname = "other_site" . $i; Concactenation?
http://www.faqts.com/knowledge-base/view.phtml/aid/2746
-------------------------------------------------------------
harry f, Nathan Wallace, Colin Dellow
The period does indeed concatenate the two clauses.
However, because you are using double quotes, you could also do:
$svarname = "other_site $i";
and PHP would substitute in the $i.
Whereas:
$svarname = 'other_site $i';
would be taken literally, as it uses single quotes.
-------------------------------------------------------------
How do I build dynamic websites with PHP and templates?
http://www.faqts.com/knowledge-base/view.phtml/aid/798
-------------------------------------------------------------
Dave Cross, Matt Gregory, Jeff Wilcox, Fiona Czuczman, Nathan Wallace
Quick and Easy Approach
====-------------------
The best way I have found of creating templates is to go ahead and
design your template in regular html. Then place the templates in a
common header file included in all your scripts. I usually use
commonHeader and commonFooter functions to fill in the templates on
each page. This model can be expanded to include any extra
functionality that you might need, including class-based page layout
and image-arrays for the links etc. etc.
Advanced, Extensible Model
====----------------------
When creating a truly dynamic, extensible website, you may find that
pages including and running basic header/footer functions is not
advanced enough.
A large project which would pay off once your site begins to grow would
be to create a set of classes to manage your entire web site and its'
organization. Your classes for your website would manage the
properties of your pages, how they should be displayed, what types of
content they should include, how they should be organized, etc.
Using some of the methods found in previous PHPBuilder Articles
(http://www.phpbuilder.com/), you could create an application processor
for your website.
For example, a basic script called App could be in charge of loading
most of the pages on your site, displaying them according to their
properties, and including content from multiple sources. Using the
$REQUEST_URI Apache value, you could parse the URL the page is at.
Examples:
/App/Home/
The Application loader (App) parses the REQUEST_URI, determines that
the browser is trying to access an application called Home, and loads
the 'Home' mini-application's PHP object and involks it.
/App/Companies/ABC/
This time, the object Companies is informed that a sub-application,
ABC, has been called. Then it's up to the Companies object to either
display the data regarding ABC, query a database, or load the correct
content.
I am working on a detailed reference for creating extensive dynamic
sites with PHP, and hopefully that reference, when completed, will be
easier to understand. I welcome any email questions you may have
regarding this.
Warning:
===-----------------
When using the class based method which depends on the REQUEST_URI your
site may not be portable to other web server platforms.
Also beware class-based website creation for parse-time costs. The
bigger your application for serving your pages the bigger the box
required to serve it in a decent amount of time.
I have found that having your template removed from your page-
generation scripts allows you to have a little more efficient code
reuse and signifigantly faster parse times (since you only have to
parse the generator script specific to the page you are calling).
-------------------------------------------------------------
How can I execute a program called zgv, for viewing jpeg files, on a linux server using php3?
http://www.faqts.com/knowledge-base/view.phtml/aid/2320
-------------------------------------------------------------
daryl lamble, Henrik Hansen, Fiona Czuczman, Nathan Wallace
Look at these functions
http://www.php.net/manual/function.system.php3
and
http://www.php.net/manual/function.exec.php3
-------------------------------------------------------------
I need to build a template-based PHP solution. Which one is a better choice to start from: FastTemplate or the functions in PHPLib?
http://www.faqts.com/knowledge-base/view.phtml/aid/1554
-------------------------------------------------------------
toby cabot, Thompson Marzagao, Nathan Wallace
I prefer phplib. First, if all other things are equal, then I'd prefer
phplib simply because it's one fewer component to install, track, learn,
etc.
The biggest issue for me is that phplib templates will almost always be
faster than fasttemplates. The reason is obvious from looking at the
source to the respective parse() routines: phplib does one regular
expression search and replace, and fasttemplates spins in a loop and
does one replacement for each replacement variable. This can be a 30%
difference or it can be a 250% difference but phplib will always come
out ahead.
Other than that they appear to be similar. If you check the phplib
developer's mailing list for April 2000 there are some comments about
just this question, too.
-------------------------------------------------------------
How can you calculate the difference between 2 times?
http://www.faqts.com/knowledge-base/view.phtml/aid/1943
-------------------------------------------------------------
Jay, Greg Wake, Christian Schmidt, Nathan Wallace
Assuming that you have two times in the format returned by time() and
mktime() (or e.g. UNIX_TIMESTAMP() in MySql) you simply simply subtract
the two. The result is the difference measured in seconds.
Then divide the difference by 86400 which is the seconds in a day
Here's an example 4 ya:
$bdnum="04/05/2000";
$ednum="05/05/2000";
$from_month = substr($bdnum, 0,2);
$from_day = substr($bdnum, 3,2);
$from_year = substr($bdnum, 6,4);
$till_month = substr($ednum, 0,2);;
$till_day = substr($ednum, 3,2);
$till_year = substr($ednum, 6,4);
$from_date = mktime(0, 0, 0, $from_month, $from_day, $from_year);
$till_date = mktime(0, 0, 0, $till_month, $till_day, $till_year);
for($ts = $from_date; $ts <= $till_date; $ts+=86400) {
if ($begtimestamp=="") {
$begtimestamp=$ts; //this line freezes first timestamp
}
// echo $ts; //echos the timestamps
// echo date("l, F d Y.",$ts); //echos the actual Day, month day year
}
$endtimestamp=$ts; //this line freezes the last timestamp
$totalsecs = ($endtimestamp-$begtimestamp) / 86400;
-------------------------------------------------------------
My hosting service just upgraded to PHP4, beta 2, from PHP3. My scripts which call "dbmopen()" no longer work - "undefined function". Ideas?
http://www.faqts.com/knowledge-base/view.phtml/aid/1988
-------------------------------------------------------------
Matteo Beccati, Kenneth Malmquist, Nathan Wallace
Just try to use these:
$id = dba_open($filename, $mode, "gdbm")
and the other functions:
dba_fetch($id)
dba_insert($id)
etc...
This should work, as long as your ISP configured php4 with
"--enable-module=dbase --enable-module=gdbm" options.
-------------------------------------------------------------
How can I use a Microsoft Access database with PHP?
http://www.faqts.com/knowledge-base/view.phtml/aid/451
-------------------------------------------------------------
Nathan Wallace, John Kos
Dannie M Stanley,John Kos
Dannie M Stanley wrote:
You can use an ODBC connection to your Access database. Information
about the ODBC functions can be found at:
http://www.php.net/manual/ref.odbc.php3
However ODBC in my experience is somewhat clunky and is not really very
useful in large applications.
John Kos wrote:
On non-windows platforms, the Easysoft ODBC-ODBC Bridge provides direct
access to MS Access and any other ODBC enabled databases for PHP
developers. Free evaluation can be downloaded from
http://www.easysoft.com. Advice and support available from
support@easysoft.com.
-------------------------------------------------------------
Is there any way to force PHP to do garbage collection before the end of the request?
http://www.faqts.com/knowledge-base/view.phtml/aid/1722
-------------------------------------------------------------
Marek Narkiewicz, Greg Billock, Nathan Wallace
http://www.php.net/manual/function.unset.php
unset()
-------------------------------------------------------------
Can php and perl run on the same server, and on the same site?
http://www.faqts.com/knowledge-base/view.phtml/aid/1878
-------------------------------------------------------------
Christiaan Schaake, ofer r, Rob Garth, Nathan Wallace
yes.
If you install both modules.
-------------------------------------------------------------
How do I open a directory located on a remote machine (WinNT), with proper permissions?
http://www.faqts.com/knowledge-base/view.phtml/aid/1233
-------------------------------------------------------------
Matthew Gregory, Jibril GUEYE, Matt Gregory, Nathan Wallace
Ok, after a little research here is what you need to do:
1.) You must mount the remote drive. In order to do this, PHP must
have permissions to do mounting or you must do it from the root login.
The remote drive must (of course) be shared. WARNING: This is a MAJOR
security issue. Not really a wise thing to do via PHP. I reccommend
that you consider other options like serving up the directory on a
secure FTP or something of the nature.
2.) treat the directory like any other directory on your Linux box, it
should be mounted under your mnt/yourmountpoint directory.
-------------------------------------------------------------
How do I retrieve raw HTTP POST data into a PHP script?
How can I get POST data from a non-browser based application into PHP?
http://www.faqts.com/knowledge-base/view.phtml/aid/2562
-------------------------------------------------------------
Jon Bahary, Ken Crismon, Nathan Wallace
To do this you must set the content type in the request header to
something PHP doesn't recognize. For example, "Content-Type: xyz". If
php3 doesn't recognize the content type it will assign the posted data
to: $HTTP_RAW_POST_DATA which is then readily available in the script.
See post.c in the source for details.
Here is some sample codde using the MFC CHttpConnection class:
char *szHeaders = _T("Content-Type: xyz\r\n");
int stat = pFile->SendRequest(szHeaders, strlen(szHeaders),
pszRequest, strlen(pszRequest));
Jon Bahary
-------------------------------------------------------------
What are the steps involved in implementing a PHP wrapper for accessing an API written in C?
http://www.faqts.com/knowledge-base/view.phtml/aid/1658
-------------------------------------------------------------
Jacob Verhoeks, Catherine Grogan, Nathan Wallace
The first step is to download the latest sourcecode. (I used RC1).
You find there a directory called dl. There are some examples. Read
api-doc.txt and api-doczend.txt in the phprootdir. Try to understand
these examples.
For my extension i stripped down the cal example. I don't know if this
is the right way to write a PHP extension but it seems to work fine.
After stripping down i got 3 functions. minit,mshutdown and my
testfunction.
The init function is called when the module is loaded.
Shutdown ... by closing the module (shutdown of apache)
And testfunction is callable from php.
How to program in zendextensions read the 2 apidocs. The use of
variables and memory allocation is different than normal C programs
Don't forget to update the function and module table. (also the
prototype in the headerfile) Modify the makefile,compile it.
Now you can use your function by include an extra line in php.ini or by
using dl("yourext.so"); in php.
Hope this helps. Write me (Jacob Verhoeks) an email if you want more
info
-------------------------------------------------------------
How do I check the user input password from a form with encrypted one in the Apache htpasswd file?
http://www.faqts.com/knowledge-base/view.phtml/aid/2133
-------------------------------------------------------------
Nikhil Mehta, Russell Speed, Nathan Wallace
Carlos Azevedos
The first two characters of the password are the "salt" to be passed
to crypt. So the following snippet should result in an equivalently
encrypted password for string comparision.
$salt=substr($Password_From_Passwd_File,0,2);
$pass=crypt( $Password_From_Form,$salt );
if( strcmp( $pass, $Password_From_Passwd_File ) )
// Fail authentication.
| Navigate in group php.kb at sever news.php.net | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by PHP Developer
Powered By PHP Consultants |