search
HomeBackend DevelopmentPHP TutorialHow to correctly implement PHP and Javascript interaction_PHP tutorial

How to correctly implement PHP and Javascript interaction_PHP tutorial

Jul 15, 2016 pm 01:33 PM
javascriptphpandinteractionuseexisthowaccomplishuscorrectof

We are using

The method of PHP interacting with Javascript: interacting through cookies. There are three files in total, namely:

index.htm, action.php, main.htm

The principle is that the front page main.htm and the background action.php pass through the page frame, index. Htm is organized and the page width of action.php is set to 0, which does not affect the display. action.php puts information into cookies, and main.htm realizes interaction by reading
cookies. In main.htm, you can also control the background CGI program by re-reading action.php.

Implementation code for interaction between PHP and Javascript:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> </span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">title</span><span class="tag">></span><span>Test</span><span class="tag"><span> /title</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> <br></span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> /head</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">frameset</span><span> </span><span class="attribute">framespacing</span><span>=</span><span class="attribute-value">"0"</span><span> <br></span><span class="attribute">border</span><span>=</span><span class="attribute-value">"false"</span><span> </span><span class="attribute">frameborder</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">cols</span><span>=</span><span class="attribute-value">"0,*"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">frame</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"leftFrame"</span><span> </span><span class="attribute">scrolling</span><span>=</span><span class="attribute-value">"no"<br></span><span> noresize </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"action.php"</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">frame</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"rightFrame"</span><span> </span><span class="attribute">scrolling</span><span>=</span><span class="attribute-value">"auto"</span><span> <br></span><span class="attribute">src</span><span>=</span><span class="attribute-value">"main.htm"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> /frameset</span><span class="tag">></span><span class="tag"><span> </span><span class="tag-name">noframes</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">body</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#FFFFFF"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">p</span><span class="tag">></span><span>本页使用页面框架,但是您的浏览器不支持。</span><span class="tag"><span> /p</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> /body</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> /noframes</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> /html</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> ?  </span></span></li>
<li><span>srand((double)microtime()*1000000);  </span></li>
<li class="alt">
<span>$</span><span class="attribute">result</span><span>=</span><span class="attribute-value">rand</span><span>(0,100);  </span>
</li>
<li><span>setcookie("action",$result,time() 900,"/");  </span></li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol>

The above is the specific implementation method for interaction between PHP and Javascript.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446054.htmlTechArticleThe way we use PHP to interact with Javascript: interact through cookies. There are three files in total, namely: index.htm, action.php, main.htm. The principle is the front page main.htm and the background acti...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.