gpt4 book ai didi

php - 如何使用 javascript 和 php 更改 php 读取文件。新Q如何阻止它影响标题

转载 作者:行者123 更新时间:2023-11-29 00:04:03 26 4
gpt4 key购买 nike

请注意,这仍然无法按预期工作,它不会将信息放入页面中,而只是重定向到新页面

更新新问题是我不希望用户看到大量标题,这是我使用此读取文件系统的原因,有什么方法可以在更改 contentFile 时避免大量标题?提前致谢这是否可以从 .htaccess 文件中实现,或者这不是一个选项

提前致谢

我的问题是,是否可以使用 ajax、jscript 或 html 更改读取文件。因此,如果用户单击 php 中的一个按钮,它会更改读取的文件

例子

//display content    
<?php
$contentFile = "content.php";
readfile( $contentFile );
?>

重定向

<script type="text/javascript">
document.getElementById("myButton").onclick = function ()
{
location.href = "./content2.php";
};
</script>

<p>TO POPULATE THE TABLES CLICK THE BUTTON:
<button id="myButton2" class="float-left submit-button" >changecontent</button></p>
</br>
//

任何帮助都会很棒

更新下面的工作代码

  <section id="content" class="content">
<button id="newButton" class="float-left submit-button" >changecontent</button></p>
</br>
<?php
if(isset($_GET['filename'])){
$contentFile = $_GET['filename'];
}else{
$contentFile = 'content.';
}
readfile( $contentFile.'php' );
?>

<script type="text/javascript">
document.getElementById("newButton").onclick = function()
{
location.href= "test.php?filename=content2.";
};
</script>
</section>

最佳答案

Try this logic
PHP code...
if(isset($_GET['filename'])){
$contentFile = $_GET['filename'];
}else{
$contentFile = 'content1';
}
readfile( $contentFile.'.php' );

<script type="text/javascript">
document.getElementById("myButton").onclick = function ()
{
location.href = "change_file.php?filename=content2";
};
</script>

关于php - 如何使用 javascript 和 php 更改 php 读取文件。新Q如何阻止它影响标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28365406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com