简体   繁体   English

使用PHP Codeigniter时如何将用户重定向到homepage.php

[英]How to redirect user to homepage.php when using PHP Codeigniter

First of all, let me explain how my system works. 首先,让我解释一下我的系统如何工作。 I create the homepage of system using standard php. 我使用标准php创建系统主页。 But, to display the online quiz, i am using a framework which is PHP CI. 但是,为了显示在线测验,我使用的是PHP CI框架。 I've problems when the user completely answer the online question, i need to redirect them to homepage. 当用户完全回答在线问题时,我遇到了问题,我需要将其重定向到首页。 However, i can't do that because of different medium used which is between standard PHP and PHP CI. 但是,由于标准PHP和PHP CI之间使用的媒体不同,我无法做到这一点。

Let me show you what I currently doing. 让我告诉你我现在在做什么。 result_display.php result_display.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<body>
<div id="container">
<h1>Welcome to Online Examination</h1>

<?php $score =0; ?>

<?php $array1 = array(); ?>
<?php $array2 = array(); ?>
<?php $array3 = array(); ?>
<?php $array4 = array(); ?>
<?php $array5 = array(); ?>
<?php $array6 = array(); ?>
<?php $array7 = array(); ?>
<?php $array8 = array(); ?>
<?php $array9 = array(); ?>

<?php foreach($checks as $checkans) { ?>
    <?php array_push($array1, $checkans); } ?>

<?php foreach($results as $res) { ?>
    <?php array_push($array2, $res->answer);
          array_push($array3, $res->quizID);
          array_push($array4, $res->question1);
          array_push($array5, $res->choice1);
          array_push($array6, $res->choice2);
          array_push($array7, $res->choice3);
          array_push($array8, $res->choice4);
          array_push($array9, $res->answer);
    } ?>


<?php 
    for ($x=0; $x <11; $x++) { ?>

<form method="post" action="<?php echo base_url();?>index.php/Questions/resultdisplay">

<p><?=$array3[$x]?>.<?=$array4[$x]?></p>

<?php if ($array2[$x]!= $array1[$x]) { ?>

    <p><span style="background-color: #FF9C9E"><?=$array1[$x]?></span></p>
    <p><span style="background-color: #ADFF84"><?=$array2[$x]?></span></p>

<?php } else { ?>   


    <p><span style="background-color: #FF9C9E"><?=$array1[$x]?></span></p>

    <?php $score = $score + 1; ?>


    <?php } } ?>

<br>

<h2>Your Result: </h2>
<h1><?=$score?>/11</h1>
<br><br>
 <a href="homepage.php">Back to Homepage

</form>
</div>
</body>
</html>

The link which is Back to Homepage could not redirect user back to homepage. 返回首页的链接无法将用户重定向回首页。 Is anybody knows how to code it well ? 有人知道如何编写好代码吗? Thanks in advance. 提前致谢。

Close the anchor tag like this 像这样关闭锚标签

<a href="homepage.php">Back to Homepage</a>
                       The missing bit ^^^^

Or in Codeigniter code I would expect to see something like this, 或者在Codeigniter代码中,我希望看到这样的内容,

<a href='<?php echo base_url('<controllername>'); ?>'>Back to Homepage</a>

Homepage 主页

Problem : Back to Homepage 问题:返回首页

In your piece of code You can't close anchor tag so it's can't be redirected. 在您的代码段中,您无法关闭锚标记,因此无法对其进行重定向。

For simply back to previous page use this 要简单地返回上一页,请使用此

  1. First load this library 首先加载该库

     $this->load->library('user_agent'); 
  2. And then use this 然后用这个

     redirect($this->agent->referrer()); 

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

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