【发布时间】:2021-10-03 06:02:45
【问题描述】:
我有一个 codeignte 项目,我是旧版本,我在 codeigite 3.1.11 和 php 7.1 中升级了我的项目,一切正常,但我的自定义路线不起作用。但我的旧项目这条路线工作正常。请检查我的代码并给我一些解决方案。我正在尝试所以可能会改变我的 htacess 和 rout。我使用配置 uri_protocol 是 REQUEST_URI
这是我的 roue.php
$url = $_SERVER['REQUEST_URI'];
$url = explode('/',$url);
$url=end($url);
$secondlasturl = explode('/',$_SERVER['REQUEST_URI']);
$controller = $secondlasturl[1];
$second_url = $secondlasturl[2];
if(isset($secondlasturl[3])){
$third_url = $secondlasturl[3];
}else{
$third_url='';
}
//$min=explode('-',$second_url1);
$con = mysqli_connect('localhost','root','','mydb');
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
if($url!=''){
$sql = 'select CompanyID, shorturl, BusinessType from lxn_companies where shorturl ="'.$url.'"';
$res=mysqli_query($con, $sql);
if(mysqli_fetch_assoc($res))
{
$row = mysqli_fetch_row($res);
//print_r($row);
$type = $row[2];
if($type=='Exporters')
{
$userlink = 'ExporterDetail/'.$row[0];
}
else
{
$userlink = 'ImporterDetail/'.$row[0];
}
$route['(:any)'] = "user/".$userlink."";
}
else
{
$sql = 'select CompanyID, sef_url, BusinessType from lxn_companies where sef_url ="'.$url.'"';
$res=mysqli_query($con, $sql);
if(mysqli_num_rows($res)>0)
{
$row = mysqli_fetch_row($res);
//print_r($row);
$type = $row[2];
if($type=='Exporters')
{
$userlink = 'ExporterDetail/'.$row[0];
}
else
{
$userlink = 'ImporterDetail/'.$row[0];
}
$route['(.*)'] = "user/".$userlink."";
}
}
}
我正在为我的项目使用这个 htacess 代码。
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
【问题讨论】:
-
您的“工作版本”是否也在 PHP 7.1 上运行? mysql_xxxx 自 PHP 7 以来已被删除,这可能是它不起作用的原因。您还应该检查服务器上的错误日志。
-
@TimBrownlaw 你能解释一下查询是有效的吗?我检查了查询结果
-
@TimBrownlaw 是的,我升级了 mysql 查询但不工作
-
@MinhazurRahaman - 您需要检查您的 IF 语句。在最后一个中,您使用 mysqlI_num_rows 正确执行此操作。在第一个中,您实际上阅读了该行。所以你试图做同样的事情,两种不同的方式。为什么不使用内置的 CI 函数,如 $this->db->query($sql),你一开始就不会遇到这个问题。
标签: php .htaccess codeigniter codeigniter-3 php-7