php - 重定向出目录

标签 php html

我有一个 CMS,并且正在 CMS 文件夹之外开发一个移动网站。我已包含 CMS 文件以使用 CMS 中的所有功能。

<?php include_once'/home/flyeurov/public_html/core/codon.config.php';?>

在移动网站上,我有一个登录表单。使用包含文件中的功能将信息提交回 CMS。

<form name="loginform" action="<?php echo url('/login');?>" method="post">

提交后,这会将其带到 site_url/index.php/login。在表单的“提交”按钮上方,我隐藏了一个重定向输入,但我希望能够按目录返回,以便找到/mobile 目录。

<input type="hidden" name="redir" value="../mobile/crew_center.php" />
<input type="hidden" name="action" value="login" />
<input class="login-btn" type="submit" name="submit" value="Log In" />

这应该将其重定向到 m.site_url/crew_center.php (“m”是/mobile 目录的路径),但它却像这样重定向,并且拒绝返回:

site_url/index.php/mobile/crew_center.php

如何让它正确重定向?我希望我没有让任何人感到困惑。

最佳答案

在 CMS 文件中,替换以下内容:

$this->post->redir = str_replace('index.php/', '', $this->post->redir);
header('Location: '.url('/'.$this->post->redir));

这样:

if (isset($_POST['mobileVersion'])) {
    header('Location: ' . $_SERVER['DOCUMENT_ROOT'] . '/crew_center.php');
} else {
    $this->post->redir = str_replace('index.php/', '', $this->post->redir);
    header('Location: '.url('/'.$this->post->redir));
}

并在登录表单的 HTML 中添加另一个 hidden input :

<input type="hidden" name="mobileVersion" value="True">

这是我能想到的唯一方法。

关于php - 重定向出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17865898/

相关文章:

php - 如何将计数器值从 javascript 发送到数据库

php - curl 服务器证书验证失败

javascript - 无法在文本字段中输入占位符和 ng-model(仅在 safari 中)

javascript - 从元素属性调用 Controller 函数

php - 在 while 循环中回显 css 类

php 发送带有 PDF 附件的电子邮件

php - 删除移动屏幕上的 'skrollr'

php - mysql -> fetch_all() 不工作

html - 将垂直菜单更改为水平菜单

html - 哪种 schema.org 类型应该用于论坛?