HTTP_REFERER& REMOTE_ADDR合并

时间:2017-05-17 22:49:42

标签: php wordpress

有一个小问题,我希望有人可以帮助我。我有一个WordPress网站,我只想授予员工访问权限。所以我想使用HTTP Referer,这样我就可以从我们的Intranet站点添加一个链接,就像这样......

public class PanelAcces extends JPanel implements ActionListener{
    JLabel labelIdentifiant; 
    JTextField entrerIdentifiant; 
    JLabel labelMotDePasse; 
    JTextField entrerMotDePasse; 
    JButton boutonConnexion = new JButton("Connexion");
    PanelLogiciel panelLogiciel;
    Connexion connexion;


    public PanelAcces(PanelLogiciel parLogiciel, Connexion parConnexion){
        panelLogiciel = parLogiciel;
        labelIdentifiant = new JLabel("Identifiant:");
        entrerIdentifiant = new JTextField(10);
        labelMotDePasse = new JLabel("Mot de passe:");
        entrerMotDePasse = new JTextField(10);
        connexion = parConnexion;

        this.add(labelIdentifiant);
        this.add(entrerIdentifiant);
        this.add(labelMotDePasse);
        this.add(entrerMotDePasse);
        this.add(boutonConnexion);
        boutonConnexion.addActionListener(this);
    }


    public void actionPerformed(ActionEvent parEvt) {
        if (parEvt.getSource() == boutonConnexion){
            try {
                if (SQL.methodeConnexion(connexion,this.entrerIdentifiant.getText(),this.entrerMotDePasse.getText()) == true){
                    this.panelLogiciel.diaporama.show(panelLogiciel.panelSite,"site");
                    System.out.println("cc");
                }
                else {
                    System.out.println("marche ap");
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
}}

但是,我还想使用以下代码添加可信IP地址列表...

if (strpos($_SERVER["HTTP_REFERER"],'intranetsite.com') == true) 
   {     
 echo "/";
   }
else
   {
 header( 'Location: http://wordpress.com/wp-admin' ) ;
   } 

组合此代码的最简单方法是什么?或者有更好的方法我应该这样做吗?

希望这一切都有意义,如果不是让我知道我是否需要澄清任何事情。

为我缺乏编码能力而道歉,仍在学习绳索。任何帮助都将非常感激。

1 个答案:

答案 0 :(得分:2)

从安全角度来看,引荐来源是限制访问网站的不可靠手段。它可以是伪造的,并非所有浏览器都能正确发送它。

如果您想要一种更安全,更统一的方式来限制对您网站的访问,请考虑使用位于网站根目录中的Apache .htaccess文件。

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /var/www/your_path/.htpasswd
Require valid-user

order deny,allow
deny from all
allow from <your first IP>
allow from <your second IP>
allow from <your third IP>
...

带有Auth指令的第一部分允许您指定.htpasswd文件,该文件将包含用户在访问网站时将对其进行身份验证的用户名和加密密码。有多种方法可以创建此文件,但最简单的方法是使用this one等工具在线完成。

第二部分指定将拒绝所有IP的连接,但您在 allow 指令的帮助下列出的连接除外。

相关问题