text
stringlengths 1
254
| output
stringlengths 2
255
|
---|---|
For example, if an attacker had gleaned information about a page based on a prior form submission, they may attempt to override variables, or modify them:
|
æšæºçãªæ»æææ³ã®äžã«äžå®å
šãªããŒã¿ãã·ã¹ãã ã«éä¿¡ããè¿ããããš ã©ãŒã®çš®é¡ãšå
容ã調ã¹ãããšã«ãããã·ã¹ãã ã調ã¹ããšãããã®ãã ããŸããããã«ãããã·ã¹ãã ã®ã¯ã©ãã«ãŒããããã匱ç¹ã調æ»ããã ãã«ãã®ãµãŒãã«é¢ããæ
å ±ã調ã¹ãããšãå¯èœã«ãªããŸãã äŸãã°ãããæ»æè
ãäºåã®ãã©ãŒã æçš¿ã®éã«ããããŒãžã«é¢ããŠåé ããæ
å ±ãæã£ãŠããå Žåã倿°ãäžæžãããããä¿®æ£ãããããããšã ããããããŸããã
|
Attacking Variables with a custom HTML page
|
äŸ 5-11ã«ã¹ã¿ã HTMLããŒãžã«ãã倿°ãæ»æãã
|
Especially dangerous is running code from known sources with built-in debugging handlers, or using common debugging techniques.
|
äŸ 5-12äžè¬çãªãããã°å€æ°ãæ¢ã
|
Example 5-12.
|
ãšã©ãŒåŠçã®æ¹æ³ã®æ¹æ³ã®ãããã«ãããããšã©ãŒã調ã¹ãæ©èœã¯ãæ»æ è
ã«ããå€ãã®æ
å ±ãäžããããšã«ã€ãªãããŸãã
|
Regardless of the method of error handling, the ability to probe a system for errors leads to providing an attacker with more information.
|
äŸãã°ãå€ãã®äžè¬çãªãšã©ãŒåœ¢åŒã§ã¯ãã·ã¹ãã ã¯PHPãå®è¡ããŠãã ããšã瀺ããŸããæ»æè
ã .html ããŒãžã調ã¹ã(ã·ã¹ãã ã®æ¢ç¥ã®åŒ±ç¹ ãæ¢ãããã«)誀ã£ãããŒã¿ãéä¿¡ããããšã«ããããã¯ãšã³ãã調ã¹ã ããšæã£ãå Žåãã·ã¹ãã ãPHPãšå
±ã«æ§ç¯ãããŠããããšãç¥ãããšã å¯èœãšãªãå¯èœæ§ããããŸãã
|
A function error can indicate whether a system may be running a specific database engine, or give clues as to how a web page or programmed or designed.
|
颿°ãšã©ãŒã¯ãã·ã¹ãã ãç¹å®ã®ããŒã¿ããŒã¹ãšã³ãžã³ãå®è¡ããŠããã ãšããŸãã¯ãWebããŒãžã®ããã°ã©ã å
容ãèšèšã«é¢ããéµã瀺ãããšã ãããŸããããã«ãããããŒã¿ããŒã¹ããŒãããªãŒãã³ããããWebã㌠ãžã«åºæã®ãã°ã匱ç¹ã調ã¹ããšãã£ããã詳现ãªèª¿æ»ãè¡ãããšãå¯èœ ãšãªããŸããäŸãã°ãç°ãªã£ãäžæ£ãªããŒã¿ãéä¿¡ããããšã«ãããæ»æ è
ã¯ã(ãšã©ãŒè¡çªå·ãã)ãã®ã¹ã¯ãªããã®ç°ãªãå Žæã調ã¹ãããšãšå æã«ãã®ã¹ã¯ãªããã®èªèšŒã®é çªãå®çŸ©ããããšãå¯èœã§ãã
|
By feeding different pieces of bad data, for example, an attacker can determine the order of authentication in a script, (from the line number errors) as well as probe for exploits that may be exploited in different locations in the script.
|
ãã¡ã€ã«ã·ã¹ãã ãŸãã¯äžè¬çãªPHPãšã©ãŒã¯ãWebãµãŒããæããèš±å¯å± æ§ãWebãµãŒãã®ãã¡ã€ã«æ§é ã瀺ãããšããããŸãããšã©ãŒã³ãŒããæž ãéçºè
ã¯ãå
ã¯ç§å¯ã®æ
å ±ã容æã«å
¬éããããšã«ããããã®åé¡ãæª åãããå¯èœæ§ããããŸãã
|
Developer written error code can aggravate this problem, leading to easy exploitation of formerly "hidden" information.
|
ãã®åé¡ã«å¯ŸããŠã¯3çš®é¡ã®å¯ŸçããããŸããæåã®å¯Ÿçã¯ãå
šãŠã®é¢æ° ããã調ã¹ã倧éšåã®ãšã©ãŒã®ä¿®æ£ã詊ã¿ãããšã§ãã2çªç®ã¯ãå®è¡ã ãã³ãŒãã®ãšã©ãŒãªããŒããå®å
šã«ç¡å¹ã«ããããšã§ãã3çªç®ã¯ã PHPã®ã«ã¹ã¿ã ãšã©ãŒåŠç颿°ã䜿çšããŠç¬èªã®ãšã©ãŒãã³ãã©ãäœæã ãããšã§ããã·ã¹ãã ã®ã»ãã¥ãªãã£ããªã·ãŒã«åºã¥ãããããã®3çš®é¡ ã®å¯Ÿçãé©çšå¯èœãã©ãããå€å®ããŸãã
|
By testing your code, prior to deployment, with E_ALL, you can quickly find areas where your variables may be open to poisoning or modification in other ways.
|
ãã®åé¡ãäºåã«é²æ¢ããææ®µã®äžã€ã¯ãPHPã® error_reporting() ã䜿çšããããšã§ããããã«ããã ã³ãŒããå®å
šã«ããããã®æããããåŸãããå±éºãšæããã倿°ãäœ¿çš ãããŠããéšåãã¿ã€ããããšãå¯èœã§ããå®äœ¿çšã®åã«E_ALLãæå®ã㊠ã³ãŒãããã¹ãããããšã«ããã倿°ãä»ã®ææ®µã§æ±æãããããä¿®æ£ã ãããããå¯èœæ§ãããéšåãç°¡åã«èŠã€ããããšãå¯èœã§ãã å®äœ¿çšã®æºåãã§ããéã«ã¯ãE_NONEã䜿çšããããšã«ãããã³ãŒããå€ éšãã調ã¹ãããããšã鲿¢ããããšãå¯èœã§ãã
|
Example 5-13.
|
äŸ 5-13E_ALLã§å±éºãªå€æ°ãèŠã€ãã
|
Care should be taken with any files which are world readable to ensure that they are safe for reading by all users who have access to that filesystem.
|
PHP ã¯ããã¡ã€ã«ããã³ãã£ã¬ã¯ããªæ¯ã«æš©éãèšå®ããå€ãã®ãµãŒãã· ã¹ãã äžã«çµã¿èŸŒãŸããã»ãã¥ãªãã£ãæäŸããŸããããã«ããããã¡ã€ ã«ã·ã¹ãã å
ã®ãã¡ã€ã«ãèªã¿èŸŒã¿å¯èœã«å¶åŸ¡ããããšãå¯èœã«ãªããŸãã å
šãŠã®ãã¡ã€ã«ã¯äžçäžããèªã¿èŸŒã¿å¯èœã§ããããã®ãã¡ã€ã«ã·ã¹ãã ã«ã¢ã¯ã»ã¹ããå
šãŠã®ãŠãŒã¶ããèªã¿èŸŒãŸããŠãå®å
šã§ããããšã確èªã ãå¿
èŠããããŸãã
|
This has some obvious implications, in that you need to ensure that the files that you read from and write to are the appropriate ones.
|
PHPã¯ããã¡ã€ã«ã·ã¹ãã ã«ãŠãŒã¶ã¬ãã«ã®ã¢ã¯ã»ã¹ãèš±å¯ããããã«èš èšãããŠãããããPHPã¹ã¯ãªãããã/etc/password ã®ãããªã·ã¹ãã ãã¡ã€ã«ãèªã¿èŸŒã¿å¯èœãšããããã€ãŒãµãããæ¥ç¶ãä¿®æ£ãããã巚倧 ãªããªã³ã¿ãžã§ããåºåãããããããšãã§ããŸããããããæããã«ã ããããšã§ãããèªã¿æžããããã¡ã€ã«ãé©åã«èšå®ããå¿
èŠããããŸãã
|
This assumes a situation where a PHP web interface is regularly used for file management, so the Apache user is allowed to delete files in the user home directories.
|
åèªã®ããŒã ãã£ã¬ã¯ããªã«ãããã¡ã€ã«ãåé€ããæ¬¡ã®ã¹ã¯ãªãããèŠ ãŠã¿ãŸããããããã¯ããã¡ã€ã«ç®¡ççšã«Webã€ã³ã¿ãŒãã§ãŒã¹ã䜿çšã ãå Žåã«éåžžçãããããªèšå®ãä»®å®ããŠããŸãããã®å ŽåãApacheãŠãŒ ã¶ã¯ãã®ãŠãŒã¶ã®ããŒã ãã£ã¬ã¯ããªã«ãããã¡ã€ã«ãåé€å¯èœã§ãã
|
Poor variable checking leads to....
|
äŸ 5-1çã倿°ã®ç¢ºèªããçãããªã¹ã¯
|
A filesystem attack
|
äŸ 5-2... ãã¡ã€ã«ã·ã¹ãã ãžã®æ»æ
|
If PHP has root access: $username = ".. / etc /"; $homedir = "/ home /.. / etc /"; $file_to_delete = "passwd"; unlink (" / home /.. / etc / passwd"); echo "/ home /.. / etc / passwd has been deleted !";?
|
PHP WebãŠãŒã¶ãã€ããªã«å¶éãããæš©éã®ã¿ãèš±å¯ããã
|
Check all variables which are submitted.
|
æçš¿ãããå
šãŠã®å€æ°ã確èªããã
|
More secure file name checking
|
äŸ 5-3ããå®å
šãªãã¡ã€ã«åã®ç¢ºèª
|
More secure file name checking
|
äŸ 5-4ããå®å
šãªãã¡ã€ã«åã®ç¢ºèª
|
But in some cases, every little bit of extra security is desirable.
|
äžè¬ã«é èœãšããææ®µã¯ã»ãã¥ãªãã£ãšããŠã¯åŒ±ããã®ã ãšèšãããŠããŸãã ãããããããææ³ãæãŸããå ŽåããããŸãã
|
By setting expose_php = off in your php.ini file, you reduce the amount of information available to them.
|
PHPãé ãããã®ç°¡åãªææ³ãããã€ããããã·ã¹ãã ã®åŒ±ç¹ãèŠã€ãã ããšããæ»æãé
å»¶ãããããšãã§ããå¯èœæ§ããããŸãã php.ini ãã¡ ã€ã«ã§expose_php = offãšèšå®ããããšã«ãããæ»æè
ãå©çšå¯èœãªæ
å ±ãæžããããšãå¯èœã§ãã
|
You can then use misleading file extensions:
|
ä»ã®ææ®µã¯ãApacheã®ãããªWebãµãŒããPHPã«ç°ãªããã¡ã€ã«åœ¢åŒãã㌠ã¹ãããããã«èšå®ããããšã§ããããã¯ã.htaccessãã£ã¬ã¯ãã£ã㟠ãã¯Apacheã®èšå®ãã¡ã€ã«èªäœã§æå®ããŸããããã«ãããçŽãããã ãã¡ã€ã«æ¡åŒµåã䜿çšå¯èœã§ãã
|
# Make PHP code look like other code types AddType application / x-httpd-php .asp .py .pl
|
äŸ 5-18PHPãä»ã®èšèªãšããŠé ã
|
# Make PHP code look like unknown types AddType application / x-httpd-php .bop .foo .133t
|
äŸ 5-19PHPæ¡åŒµåçšã«æªç¥ã®åã䜿çšãã
|
# Make all PHP code look like html AddType application / x-httpd-php .htm .html
|
äŸ 5-20PHPæ¡åŒµåãšããŠHTMLåã䜿çšãã
|
As there are many different ways of utilizing PHP, there are many configuration options controlling its behaviour.
|
PHP ã®äœ¿çšæ³ã«å€ãã®ç°ãªã£ãææ®µãããããã«ãPHP ã®åäœãå¶åŸ¡ãã å€ãã®èšå®ãªãã·ã§ã³ããããŸãããªãã·ã§ã³ã®éžæè¢ãåºããããPHP ãæ§ã
ãªçšéã«äœ¿çšããããšãã§ããŸãããããããã®ããšã¯ããããã® ãªãã·ã§ã³ãšãµãŒããŒèšå®ã®çµã¿åããã«ãã£ãŠã¯ãå®å
šã§ãªãèšå®ãšãª ãããšãæå³ããŸãã
|
The configuration flexibility of PHP is equally rivalled by the code flexibility.
|
PHPã®èšå®ã®èªç±åºŠã¯ãã®ã³ãŒãã®æè»ãã«ã»ãŒå¹æµããŸããPHPã¯ãã·ã§ ã«ãŠãŒã¶ã³ãã³ããå
šãŠå®è¡å¯èœãªå®å
šãªãµãŒããŒã¢ããªã±ãŒã·ã§ã³ã å³ããå¶åŸ¡ãããç°å¢ã§äœãªã¹ã¯ã®ç°¡åãªãµãŒããŒãµã€ãã€ã³ã¯ã«ãŒãã 䜿çšã§ãããããªã¢ããªã±ãŒã·ã§ã³ãæ§ç¯ããå Žåã«äœ¿çšããããšãå¯èœ ã§ããããããç°å¢ã®æ§ç¯æ¹æ³ãã»ãã¥ãªãã£ã®ã¬ãã«ã¯PHPã®éçºè
ã«å€§ ããäŸåããŠããŸãã
|
How you build that environment, and how secure it is, is largely up to the PHP developer.
|
æ¬ç« ã¯ãå®å
šã«äœ¿çšå¯èœãªç°ãªã£ãèšå®ãšæ¡ä»¶ã®çµã¿åããã«ã€ããŠã®èª¬ æããå§ããŸããç¶ããŠãè€æ°ã®ã»ãã¥ãªãã£ã¬ãã«ã®ã³ãŒãã£ã³ã°ã«ã ããè€æ°ã®èæ
®äºé
ã«ã€ããŠèª¬æããæåŸã«ããã€ãã®äžè¬çãªã»ãã¥ãª ãã£äžã®ã¢ããã€ã¹ãè¡ããŸãã
|
A completely secure system is a virtual impossibility, so an approach often used in the security profession is one of balancing risk and usability.
|
å®å
šã«å®å
šãªã·ã¹ãã ã¯çæ³ã®ç£ç©ã§ãããªããããã»ãã¥ãªãã£æ¥çã§ ãã°ãã°äœ¿çšãããææ³ã¯ããªã¹ã¯ãšå©äŸ¿æ§ã®ãã©ã³ã¹ã®ãšããææ³ã§ãã 倿°ããŠãŒã¶ããæçš¿ããã床ã«(ç¶²èã¹ãã£ã³ãšæçŽã®ãããª)2çš®é¡ã® çäœèªèšŒãå¿
èŠã ãšããããæ¥µç«¯ã«é«ãã¬ãã«ã®èª¬æçŸ©åãçããŸãã㟠ããããªãè€éãªãã©ãŒã ãåããããã«30åãããããšããã°ããŠãŒã¶ ãã»ãã¥ãªãã£ããã€ãã¹ããææ®µãæ¢ãæ°åã«ãããåŸåããããŸãã
|
It would also take half an hour to fill out a fairly complex form, which would tend to encourage users to find ways of bypassing the security.
|
æåã®ã»ãã¥ãªãã£ã¯ãéåžžããŠãŒã¶ã«ããæ¥åã®éæãé²ãããã«èŠæ± ãååã«éæã§ããçšåºŠã«ããã§ããŸãããªããã®ã§ãããããããã〠ãã®ã»ãã¥ãªãã£æ»æã¯ãåçŽã«ãã®çš®ã®å€ããã«æ§ç¯ãããæéãæµªè²» ããã¡ãªã»ãã¥ãªãã£æ©æ§ãçããã®ã§ãã
|
Indeed, some security attacks are merely exploits of this kind of overly built security, which tends to erode over time.
|
èšæ¶ããã«å€ããèšèãšããŠæ¬¡ã®ãããªãã®ããããŸãããã·ã¹ãã ã¯é ã®æã匱ã茪ãšåçšåºŠã«åªããŠãããå
šãŠã®ãã©ã³ã¶ã¯ã·ã§ã³ãæéãå Ž æããã©ã³ã¶ã¯ã·ã§ã³ã®åçã«åºã¥ã倧éã«èšé²ãããŠãããããŠãŒã¶ã¯ äžã€ã®ã¯ãããŒã®ã¿ã«ããèªèšŒãããŠããå ŽåããŠãŒã¶ãšãã®ãã©ã³ã¶ã¯ ã·ã§ã³ãã°ã®çµã³ä»ãã®ç¢ºå®æ§ã¯ããªã匱ããªããŸãã
|
This is why it 's best to look at the code from a logical perspective, to discern where unexpected data can be introduced, and then follow how it is modified, reduced, or amplified.
|
ãã¹ãã®éã«ãæãç°¡åãªããŒãžã«é¢ããŠã§ãããå
šãŠã®å¯èœæ§ããã¹ã ããããšã¯äžå¯èœã§ãããšããããšãé ã«å
¥ããŠãããŠäžãããæåŸ
ãã å
¥åã¯ãäžæ©å«ãªç€Ÿå¡ãçµéšã®ããã¯ã©ãã«ãŒãããŒããŒãã®äžãæ©ãå®¶ ã®ç«ã«ããå
¥åãšã¯å
šãç¡é¢ä¿ã§ããããããããæ³å®å€ã®ããŒã¿ãå
¥å ãããå¯èœæ§ãããå ŽæãèŠåããããã«è«ççãªèŠç¹ããã³ãŒããèŠãŠã ãã®åŸãä¿®æ£ãæžå°ããŸãã¯è©³çްã«èª¿ã¹ããšããã®ããæåã§ãããšãã çç±ã§ãã
|
It doesn 't matter if you have a small or large site, you are a target by simply being online, by having a server that can be connected to.
|
ã€ã³ã¿ãŒãããã«ã¯ããªãã®ã³ãŒããå£ããããã·ã¹ãã ãç Žå£ãããã äžé©åãªå
容ãæçš¿ãããããã®ä»ããªãã®äžæ¥ãäžå¿«ã«ãããããªããš ã«ããèªåã®åã銳ããããšæã人ãããããããŸãããµã€ãã®èŠæš¡ã®å€§ å°ã«ããããåã«ãªã³ã©ã€ã³ã§ãããæ¥ç¶ã§ãããµãŒããæããŠããã ã ã§æ»æç®æšãšãªãããŸããå€ãã®ã¯ã©ãã¯çšããã°ã©ã ã¯ãµã€ãã®å€§ãã ãèæ
®ãããç ç²è
ãæ¢ãã€ã€å€§ããªIPãããã¯ã§ç¶²ã匵ã£ãŠããŸãã
|
By turning off the ability for any user-submitted variable to be injected into PHP code, you can reduce the amount of variable poisoning a potential attacker may inflict.
|
ã»ãã¥ãªãã£ãåäžãããããã«äœ¿çšå¯èœãªPHPã®æ©èœã®äžã€ã¯ã PHPã§register_globals = offãæå®ããŠèšå®ãè¡ãªãããšã§ãã ãŠãŒã¶ãæçš¿ãã倿°ãå
šãŠPHPã³ãŒãã«å°å
¥ããããã®æ©èœã ãªãã«ããããšã«ãããæœåšçãªæ»æè
ãæ»æã§ãã倿°ã®æ°ã æžããããšãå¯èœãšãªããŸããããã«ãããæçš¿ãäœæãããã ã«ããå€ãã®æéãèŠããå
éšå€æ°ã¯ãŠãŒã¶ã«ããæçš¿ãããã ãŒã¿ããå¹ççã«éé¢ããããšãå¯èœãšãªããŸãã
|
While it does slightly increase the amount of effort required to work with PHP, it has been argued that the benefits far outweigh the effort.
|
ãã®å ŽåãPHPã§åäœãããããã«å¿
èŠãªã³ãŒãã®éã¯è¥å¹²å¢å ããŸããããã®å©çã¯åªåãäžåããšè°è«ãããŠããŸãã
|
Working with register_globals=on
|
äŸ 5-14register_globals=offãæå®ããªãå Žåã®åäœ
|
?php if( $_COOKIE['username']) {/ / can only come from a cookie, forged or otherwise $good_login = 1; fpassthru (" / highly / sensitive / data / index.html");}?
|
äŸ 5-15register_globals = offãæå®ããå Žåã®åäœ
|
Detecting simple variable poisoning
|
äŸ 5-16ç°¡åãªå€æ°ã®æ±æã®æç¡ã®æ€åº
|
For this reason, you should always take the time to consider the implications of a given piece of code, to ascertain the possible damage if an unexpected variable is submitted to it.
|
å€ãã®PHPã§æãè匱ãªéšåã¯ãèšèªèªäœã«èµ·å ãããã®ã§ã¯ãªããåã« ã»ãã¥ãªãã£ãèæ
®ããŠæžãããŠããªãã³ãŒãã®åé¡ã§ãããã®åå ã«ã€ ããŠãæå®ããã³ãŒãã®éšåã®æå³ãåžžã«æéããããŠåå³ããäºæ³å€ã® 倿°ãæçš¿ãããå Žåã«æãåŸãæå®³ã確ãããå¿
èŠããããŸãã
|
Dangerous Variable Usage
|
äŸ 5-17å±éºãªå€æ°ã®äœ¿çš
|
Can unusual or undesirable data be acted upon?
|
ãã®ã¹ã¯ãªããã¯æå³ãã以å€ã®æ¹æ³ã§äœ¿çšããããšãå¯èœã?
|
Can this be used in conjunction with other scripts in a negative manner?
|
ãã®ã¹ã¯ãªããã¯ãæªãæå³ã§ä»ã®ã¹ã¯ãªãããšçµã¿åãããŠäœ¿çšã ãããšãå¯èœã?
|
Will any transactions be adequately logged?
|
ãã©ã³ã¶ã¯ã·ã§ã³ã¯é©åã«èšé²ãããŠããã?
|
Working with PHP in error_reporting( E_ALL) mode can also help warn you about variables being used before they are checked or initialized (so you can prevent unusual data from being operated upon).
|
register_globals,magic_quotes, ãŸãã¯ä»ã®äŸ¿å©ãªèšå®ã¯ãæå¹æ§ãçº ä¿¡å
ãæå®ãã倿°ã®å€ã«ã€ããŠæ··ä¹±ãçããå¯èœæ§ããããããèšå®ã ãªãã«ããããšæããããããŸãããerror_reporting(E_ALL) ã¢ãŒãã§ PHPãåäœãããå Žåã確èªãŸãã¯åæåããåã«äœ¿çšããã倿°ã«é¢ã ãŠèŠåãçºçãããããšãå¯èœã§ãã(ããã«ãããåŠçæã«éåžžãšã¯ç° ãªãããŒã¿ã鲿¢ããããšãå¯èœã§ã)
|
Unless noted otherwise, the semantics of the functions are identical.
|
äŸ 43-1PHPããŒã ããŒãžã衚瀺ããããã®ç°¡åãªã¹ããªãŒã ã®äŸ
|
The nmemb parameter is assumed to have a value of 1, so the prototype looks more like read( 2)
|
以äžã®è¡šã«ãã®ä»ã®äžè¬çãªANSI stdio颿°ãšç䟡ãªã¹ããªãŒã 颿°ã 瀺ããŸããæ³šèšã§é€å€ãããŠããªãéãã颿°ã®æå³ã¯åãã§ãã
|
The nmemb parameter is assumed to have a value of 1, so the prototype looks more like write( 2)
|
衚 43-1ANSI stdioãšç䟡ãªã¹ããªãŒã API颿°
|
Prev
|
æ¬ã»ã¯ã·ã§ã³ã«ç€ºãäžé£ã®é¢æ°ã¯ãããŒã«ã«ãã¡ã€ã«ããã³ãªã¢ãŒããã¡ã€ã« (ãã®æ©èœãã©ãããŒããµããŒãããå Žå!)ã§åäœããŸãã
|
Using a single API with standard functions for common operations, the streams API allows your extension to access files, sockets, URLs, memory and script-defined objects.
|
PHPã¹ããªãŒã APIã¯ãPHPæ¡åŒµã¢ãžã¥ãŒã«ã«ãã¡ã€ã«ããã³ãœã±ããåŠç çšã®çµ±äžåãããææ®µãå°å
¥ãããã®ã§ãã å
±éã®æäœãè¡ãªãããã®æšæºé¢æ°ãæããåäžã®APIã䜿çšããããšã« ãããã¹ããªãŒã APIã¯æ¡åŒµã¢ãžã¥ãŒã«ããã¡ã€ã«ããœã±ãããURLãã¡ã¢ãª ã¹ã¯ãªãããå®çŸ©ãããªããžã§ã¯ãã«ã¢ã¯ã»ã¹ããããšãå¯èœã«ããŸãã ã¹ããªãŒã ã¯ãæ°èŠã¹ããªãŒã ãç»é²ããããã«åçã«ããŒãããã ã¢ãžã¥ãŒã«(ããã³ã¹ã¯ãªãã!)ãšããããšãã§ããå®è¡æã«æ¡åŒµå¯èœãª APIã§ãã
|
The aim of the Streams API is to make it comfortable for developers to open files, urls and other streamable data sources with a unified API that is easy to understand.
|
ã¹ããªãŒã APIã®ç®çã¯ããã¡ã€ã«ãURLããã®ä»ã®ã¹ããªãŒã ã«ã§ããããŒã¿ ãœãŒã¹ãå¹³æãªçµ±äžãããAPIã«ãããéçºè
ã容æã«ãªãŒãã³ã§ããããã« ããããšã§ããAPIã¯ãã»ãŒANSI C stdio颿°ãš(å€ãã®äž»ãªé¢æ°ã«ã€ããŠåç ã®æå³ãæããŠããã)é¡äŒŒããŠããŸãããã®ãããCããã°ã©ãã¯ã ã¹ããªãŒã ã«æ
£ããŠããå°è±¡ãåããã¯ãã§ãã
|
The streams API operates on a couple of different levels: at the base level, the API defines php_stream objects to represent streamable data sources.
|
ã¹ããªãŒã APIã¯ãããã€ãã®ç°ãªãã¬ãã«ãåŠçããŸãã åºæ¬ã¬ãã«ã§ã¯ãAPIã¯ã¹ããªãŒããã«ãªããŒã¿ãœãŒã¹ã衚ã php_streamãªããžã§ã¯ããå®çŸ©ããŸãã ããé«ãã¬ãã«ã§ã¯ãAPIã¯ãURLããã®ããŒã¿ããã³ã¡ã¿ããŒã¿ã®ååŸã ãµããŒãããããã«äœã¬ãã«APIãã©ããããphp_stream_wrapper ãªããžã§ã¯ããå®çŸ©ããŸãã
|
Streams can be cast (converted) into other types of file-handles, so that they can be used with third-party libraries without a great deal of trouble.
|
ã¹ããªãŒã ã¯ããã¡ã€ã«åŠçã®ä»ã®åœ¢åŒã«ãã£ã¹ã(倿)ã§ãã 倧ããªåé¡ããªããµãŒãããŒãã£è£œã®ã©ã€ãã©ãªãšçµã¿åãããŠäœ¿çšãã ããšãã§ããŸããããã«ããããããã®ã©ã€ãã©ãªãURLãœãŒã¹ããããŒã¿ã« çŽæ¥ã¢ã¯ã»ã¹ã§ããããã«ãªããŸãã 䜿çšããã·ã¹ãã ã« fopencookie() 颿°ãããå Žåã ä»»æã®PHPã¹ããªãŒã ãANSI stdioã䜿ãä»»æã®ã©ã€ãã©ãªã«æž¡ãããšãã ã§ããŸã!
|
One or more of these values can be combined using the OR operator.
|
One or more of these values can be combined using the OR operator.
|
Requests that the include_path is to be searched for the requested file.
|
This is the default option for streams; it requests that the include_path is not to be searched for the requested file.
|
Other non-URL wrappers will be taken into consideration when decoding the path.
|
Requests that the include_path is to be searched for the requested file.
|
Requests that the underlying stream implementation perform safe_mode checks on the file before opening the file.
|
On Windows systems, this is equivalent to IGNORE_URL. On all other systems, this flag has no effect.
|
If this flag is set, and there was an error during the opening of the file or URL, the streams API will call the php_error function for you.
|
Requests that the underlying stream implementation perform safe_mode checks on the file before opening the file. Omitting this flag will skip safe_mode checks and allow opening of any file that the PHP process has rights to access.
|
Note:
|
泚æ If the requested resource is network based, this flag will cause the opener to block until the whole contents have been downloaded.
|
The is particularly useful when accessing HTTP URLs where the start of the actual stream data is found after an indeterminate offset into the stream.
|
The is particularly useful when accessing HTTP URLs where the start of the actual stream data is found after an indeterminate offset into the stream.
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
Note:
|
php_register_url_stream_wrapper() registers wrapper as the handler for the protocol specified by protocol.
|
Prev
|
泚æ If you call this function from a loadable module, you *MUST* call php_unregister_url_stream_wrapper() in your module shutdown function, otherwise PHP will crash.
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
It returns SUCCESS if the stream can be converted into the form requested, or FAILURE if the conversion cannot be performed.
|
This function is equivalent to calling php_stream_cast() with ret set to NULL and flags set to 0. It returns SUCCESS if the stream can be converted into the form requested, or FAILURE if the conversion cannot be performed.
|
Although this function will not perform the conversion, some internal stream state *might* be changed by this call.
|
泚æ Although this function will not perform the conversion, some internal stream state *might* be changed by this call.
|
See also php_stream_cast() and php_stream_is().
|
泚æ You must explicity compare the return value of this function with one of the constants, as described in php_stream_cast().
|
php_stream_is_persistent
|
See also php_stream_cast() and php_stream_is().
|
php_stream_cast() attempts to convert stream into a resource indicated by castas.
|
(no version information, might be only in CVS)
|
Tries as hard as possible, at the expense of additional resources, to ensure that the conversion succeeds
|
衚 43-1Resource types for castas
|
This causes the stream to be closed in such a way the underlying handle is preserved and returned in ret.
|
In addition to the basic resource types above, the conversion process can be altered by using the following flags by using the OR operator to combine the resource type with one or more of the following values:
|
Note:
|
衚 43-2Resource types for castas
|
If the fopencookie synthesis is not desireable, you should query the stream to see if it naturally supports FILE* by using php_stream_is()
|
泚æ If you ask a socket based stream for a FILE*, the streams API will use fdopen() to create it for you. Be warned that doing do may cause data that was buffered in the streams layer to be lost if you intermix streams API calls with ANSI stdio calls.
|
Be warned that doing do may cause data that was buffered in the streams layer to be lost if you intermix streams API calls with ANSI stdio calls.
|
See also php_stream_is() and php_stream_can_cast().
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
Returns 0 on success, but -1 on failure.
|
php_stream_closedir() closes a directory stream and releases resources associated with it. Returns 0 on success, but -1 on failure.
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
After stream has been closed, it 's value is undefined and should not be used.
|
php_stream_close() safely closes stream and releases the resources associated with it. After stream has been closed, it's value is undefined and should not be used.
|
Regardless of the success of the call, stream is undefined and should not be used after a call to this function.
|
php_stream_close() returns 0 if the stream was closed or EOF to indicate an error. Regardless of the success of the call, stream is undefined and should not be used after a call to this function.
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
It then reads maxlen bytes from src and stores them in the allocated buffer.
|
php_stream_copy_to_mem() allocates a buffer maxlen +1 bytes in length using pemalloc() (passing persistent). It then reads maxlen bytes from src and stores them in the allocated buffer.
|
You, the caller, are responsible for freeing the buffer by passing it and persistent to pefree().
|
The allocated buffer is returned in buf, and the number of bytes successfully read. You, the caller, are responsible for freeing the buffer by passing it and persistent to pefree().
|
Note:
|
If you want to copy all remaining data from the src stream, pass the constant PHP_STREAM_COPY_ALL as the value of maxlen.
|
Prev
|
泚æ This function will attempt to copy the data in the most efficient manner, using memory mapped files when possible.
|
Prev
|
(no version information, might be only in CVS)
|
php_stream_copy_to_stream() attempts to read up to maxlen bytes of data from src and write them to dest, and returns the number of bytes that were successfully copied.
|
php_stream_copy_to_stream() attempts to read up to maxlen bytes of data from src and write them to dest, and returns the number of bytes that were successfully copied.
|
Note:
|
If you want to copy all remaining data from the src stream, pass the constant PHP_STREAM_COPY_ALL as the value of maxlen.
|
Prev
|
泚æ This function will attempt to copy the data in the most efficient manner, using memory mapped files when possible.
|
Prev
|
(no version information, might be only in CVS)
|
php_stream_eof() checks for an end-of-file condition on stream.
|
php_stream_eof() checks for an end-of-file condition on stream.
|
Prev
|
php_stream_read() returns the 1 to indicate EOF, 0 if there is no EOF and -1 to indicate an error.
|
Prev
|
(no version information, might be only in CVS)
|
php_stream_flush() causes any data held in write buffers in stream to be committed to the underlying storage.
|
php_stream_flush() causes any data held in write buffers in stream to be committed to the underlying storage.
|
Prev
|
php_stream_flush() returns 0 if the buffers were flushed, or if the buffers did not need to be flushed, but returns EOF to indicate an error.
|
Prev
|
(no version information, might be only in CVS)
|
php_stream_fopen_from_file() returns a stream based on the file. mode must be the same as the mode used to open file, otherwise strange errors may occur when trying to write when the mode of the stream is different from the mode on the file.
|
php_stream_fopen_from_file() ã¯ã file ã«åºã¥ãã¹ããªãŒã ãè¿ããŸãã mode ã¯ã file ããªãŒãã³ãã éã«äœ¿çšãããã¢ãŒããšåãã§ããå¿
èŠãããããããªããšã ã¹ããªãŒã ããã¡ã€ã«ã®ã¢ãŒããšç°ãªã£ãå Žåã«ãæžã蟌ã¿ãè¡ããšã ããããªçµæãçããå¯èœæ§ããããŸãã
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
The temporary file will be deleted automatically when the stream is closed or the process terminates.
|
php_stream_fopen_from_file() returns a stream based on a temporary file opened with a mode of "w+b". The temporary file will be deleted automatically when the stream is closed or the process terminates.
|
(no version information, might be only in CVS)
|
(no version information, might be only in CVS)
|
php_stream_getc() may block in the same way as php_stream_read() blocks.
|
php_stream_getc() reads a single character from stream and returns it as an unsigned char cast as an int, or EOF if the end-of-file is reached, or an error occurred.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.