简体   繁体   English

上传我的网站时出现PHP问题?

[英]PHP problems when uploading my website?

I made a website on localhost. 我在本地主机上创建了一个网站。 Then I uploaded it to different servers, and no problem. 然后我将其上传到其他服务器,没有问题。 However, this time I tried to upload the web to another server, and in this one the code, which is exactly the same working on the other sites, does not work well. 但是,这次我尝试将Web上传到另一台服务器,并且在此服务器中,与在其他站点上完全相同的代码无法正常工作。 I was simplifying the mistake and must be in one of the following lines. 我正在简化错误,必须在以下行之一中。

If I type on the URL my website, my code has to add the default language to the URL automatically (which is es ), if this one has not been specified yet. 如果我在网站的URL上键入代码,则我的代码必须自动将默认语言添加到URL(即es )(如果尚未指定)。 For example, if I type mydomain.com , it must be converted to mydomain.com/es . 例如,如果输入mydomain.com ,则必须将其转换为mydomain.com/es

Here the codes ( Note: lang was declared in htaccess, and is the name of the first parameter introduced on the URL, in this case, the language ): 此处的代码( 注意:lang在htaccess中声明,是URL上引入的第一个参数的名称,在本例中为language ):

index.php CODE: index.php代码:

<?php
    $idiomas = array("ES", "GL", "EN");
    if (!(isset($_GET['lang']) && $_GET['lang'] == "admin")) {
        require_once("pages/language.php");
    }
?>

language.php CODE: language.php代码:

<?php
    if (isset($_GET['lang']) && $_GET['lang'] != "") {
        switch ($_GET['lang']) {
            case strtolower($idiomas[0]):
            case strtolower($idiomas[1]):
            case strtolower($idiomas[2]):
            case 'admin':
                $_SESSION['lang'] = $_GET['lang'];
                break;
            default: {
                header("Location: ".ROOT);
            }
        }
    }
    else {
        if (!isset($_SESSION['lang']) || $_SESSION['lang'] == "") {
            echo '<meta http-equiv="refresh" content="0; url='.strtolower($idiomas[0]).'">';
            exit;
        }
    }
?>

Now, what is happening is: you type mydomain.com and this one is converted to mydomain.com/es on the URL, right, but it starts to do this each milisecond, reloading and reloading the page forever. 现在,发生的事情是:键入mydomain.com,然后在URL上将其转换为mydomain.com/es ,但是,它每隔一毫秒就会开始执行此操作,从而永久重新加载和重新加载页面。 I realised that when mydomain.com/es is already on the URL, in language.php the first condition of the if is not kept, and it should be kept. 我意识到,当mydomain.com/es已存在于URL上时,在language.php中, if的第一个条件未保留,应将其保留。

I do not know why this code always worked in different servers and not in this one. 我不知道为什么这段代码总是在不同的服务器上工作而不是在另一台服务器上工作。 Any idea, please? 有什么主意吗? Thank you in advance. 先感谢您。

As per your concern , URL is converted to other URL , this might be the reason for your problem as the $_GET['lang'] will not be exist on other converted URL. 根据您的关注,URL已转换为其他URL,这可能是导致您出现问题的原因,因为$ _GET ['lang']在其他转换后的URL中将不存在。

Please check .htaccess file in your code directory. 请检查代码目录中的.htaccess文件。

There's a problem with the session handling You should start with session_start(); 会话处理有问题。您应该从session_start()开始; also you have to set the "lang" variable when you redirect ... Another option would be to include in the end of the url the ?lang= parameter (GET method) 也需要在重定向时设置“ lang”变量。另一种选择是在URL的末尾包含?lang =参数(GET方法)

echo '<meta http-equiv="refresh" content="0; url=/'.strtolower($idiomas[0]).'?lang='.$idiomas[0].'">';

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

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