简体   繁体   English

如何通过PHP访问index.php内的其他页面?

[英]How to get access of other pages inside of index.php by PHP?

I installed PHP and Apache server in my computer. 我在计算机上安装了PHP和Apache服务器。 So inside of "htdocs" I created 2 files(index.php, Contact.php) and a directory(MyClass), after that inside of "MyClass" I created a file(class.php).. 因此,在“ htdocs”内部,我创建了2个文件(index.php,Contact.php)和目录(MyClass),在“ MyClass”内部,我创建了文件(class.php)。

In web browser when I am using the url " http://localhost/MyClass/class.php ", the result is : "class.php" sending data to the web browser. 在Web浏览器中,当我使用URL“ http://localhost/MyClass/class.php ”时,结果是:“ class.php”将数据发送到Web浏览器。

In the same situation is there any way in PHP/Apache to take control of it from the "index.php" ?? 在相同的情况下,PHP / Apache中可以通过“ index.php”来控制它吗?

Or 要么

I want to be known about all the requests inside of "index.php" which came from web browser, is it possible ???? 我想知道来自网络浏览器的“ index.php”内部的所有请求,这可能吗?

But I don't want to use any GET variable like " http://localhost/index.php?class=page2 " .. 但我不想使用任何GET变量,例如“ http://localhost/index.php?class = page2 ..

Apology for my bad English. 为我的英语不好而道歉。

Thanks.. 谢谢..

You should use include , in your case you would use 您应该使用include ,如果您要使用

include 'MyClass/class.php';

More information about include can be found right here 关于include更多信息可以在这里找到

I'm not sure I understand correctly but a way to not use ?class=page2 我不确定我是否正确理解,但是不使用?class = page2的方法

is to create a .htaccess file 是创建一个.htaccess文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

This will rewrite all requests to non existing files or folders to your index.php the use $_SERVER['REQUEST_URI'] to make your navigation. 这会将对不存在的文件或文件夹的所有请求重写到index.php中,使用$ _SERVER ['REQUEST_URI']进行导航。 for example you could use http://localhost/class/page/2 例如,您可以使用http:// localhost / class / page / 2

$_SERVER['REQUEST_URI'] would then be class/page/2 $ _SERVER ['REQUEST_URI']然后为class / page / 2

If your website is in a subfolder of htdocs be sure to edit 如果您的网站位于htdocs的子文件夹中,请务必进行编辑

RewriteBase /dir/here/
[...]
RewriteRule . /dir/here/index.php [L]

to match it 匹配它

My problem solved. 我的问题解决了。

Which changes I did they are below : 我在下面做了哪些更改:

In "C:\\Apache24\\conf" need to change file "httpd.conf" 在“ C:\\ Apache24 \\ conf”中需要更改文件“ httpd.conf”

Just active : 刚刚活跃:

1) 1)

LoadModule rewrite_module modules/mod_rewrite.so

2) 2)

<Directory />
      #AllowOverride none
      AllowOverride All
      Require all denied
   </Directory>

3) I am using "Virtual Host", so in "C:\\Apache24\\conf\\extra" need to change file "httpd-vhosts.conf" 3)我正在使用“虚拟主机”,因此在“ C:\\ Apache24 \\ conf \\ extra”中需要更改文件“ httpd-vhosts.conf”

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@test.com
    DocumentRoot "E:/TEST"
    <Directory "E:/TEST">
        Allow From All
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule . /index.php [L]
    </Directory>
    ServerName test.com
    ServerAlias www.test.com
    ErrorLog "logs/test.com-error.log"
    CustomLog "logs/test.com-access.log" common
</VirtualHost>

If you are not using "Virtual Host", then I think you need to add some lines to the "Directory" inside of "httpd.conf" !! 如果您不使用“虚拟主机”,那么我认为您需要在“ httpd.conf”内部的“目录”中添加一些行!

<Directory>
    Allow From All
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /index.php [L]
</Directory>

Use the PHP include function. 使用PHP include函数。 You can include your MyClass/class.php in you index file. 您可以在索引文件中包含MyClass / class.php。 You can then add an htaccess file to restrict files in the MyClass directory from being viewed directly. 然后,您可以添加htaccess文件以限制MyClass目录中的文件不被直接查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM