草庐IT

PHP header 重定向循环

coder 2024-05-01 原文

我遇到了一个问题,用户可以向日历提交一个事件,但我无法将他们重定向回原始页面。我试过使用:

  header("Location: http://localhost/Project/View/Home.php");
  exit;

但我收到一条消息 This webpage has a redirect loop

HTML - Home.php

<!DOCTYPE html> 
<html lang="en"> 
  <head> 
    <meta charset="utf-8" /> 
    <link rel="stylesheet" href="Common.css" />
    <script src="jquery.js"></script>
    <script type="text/javascript" src="functions.js"></script>
    <!--Includes HTML5 Shiv for all versions of IE to solve compatability issues--> 
    <!-- <title></title>-->
<?php include '../Controller/Cal.php'?>
  </head>
  <body>
    <form action="../Controller/Cal.php" method="post">
      Content: <input type="text" name="Content" />
      <input type="submit" />
    </form>
    <header>
    <iframe src="https://www.google.com/calendar/embed?src=dnavechicleservices%40gmail.com&ctz=Europe/London" 
    style="border: 0" width="1000" height="600" frameborder="0" scrolling="no"></iframe>
    </header>
  </body>
</html>

PHP - Cal.php

<?php 
  $path = '/opt/lampp/htdocs/Project/ZendGdata-1.12.0/library';
  $oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $path);
  require_once 'Zend/Loader.php';
  Zend_Loader::loadClass('Zend_Gdata');
  Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  Zend_Loader::loadClass('Zend_Gdata_Calendar');
  // User whose calendars you want to access
  $user = 'email@gmail.com';
  $pass = 'password';
  $serviceName = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar
  $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $serviceName);
  $service = new Zend_Gdata_Calendar($client);
  // Create a new event object using calendar service's factory method.
  // We will then set different attributes of event in this object.
  $event= $service->newEventEntry();
  // Create a new title instance and set it in the event
  $event->title = $service->newTitle("Service");
  $event->content = $service->newContent(isset($_POST["Content"]));
  // Create an object of When and set start and end datetime for the event
  $when = $service->newWhen();
  // Set start and end times in RFC3339 (http://www.ietf.org/rfc/rfc3339.txt)
  $when->startTime = "2012-10-20T16:30:00.000+05:30"; // 8th July 2010, 4:30 pm (+5:30 GMT)
  $when->endTime = "2012-10-20T17:30:00.000+05:30"; // 8th July 2010, 5:30 pm (+5:30 GMT)
  // Set the when attribute for the event
  $event->when = array($when);
  // Create the event on google server
  $newEvent = $service->insertEvent($event);
  // URI of the new event which can be saved locally for later use
  $eventUri = $newEvent->id->text;
  header("Location: http://localhost/Project/View/Home.php");
  exit;
?>

最佳答案

看来原因是

<?php include '../Controller/Cal.php'?>

在你的 home.php 中

您需要在 header 重定向周围放置一个条件。

您可以使用:

if(isset($_POST['Content']))
    header("Location: http://localhost/Project/View/Home.php");

关于PHP header 重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12862589/

有关PHP header 重定向循环的更多相关文章

  1. ruby - 树顶语法无限循环 - 2

    我脑子里浮现出一些关于一种新编程语言的想法,所以我想我会尝试实现它。一位friend建议我尝试使用Treetop(Rubygem)来创建一个解析器。Treetop的文档很少,我以前从未做过这种事情。我的解析器表现得好像有一个无限循环,但没有堆栈跟踪;事实证明很难追踪到。有人可以指出入门级解析/AST指南的方向吗?我真的需要一些列出规则、常见用法等的东西来使用像Treetop这样的工具。我的语法分析器在GitHub上,以防有人希望帮助我改进它。class{initialize=lambda(name){receiver.name=name}greet=lambda{IO.puts("He

  2. ruby-on-rails - 在 Ruby 中循环遍历多个数组 - 2

    我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代

  3. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  4. ruby - 将 spawn() 的标准输出/标准错误重定向到 Ruby 中的字符串 - 2

    我想使用spawn(针对多个并发子进程)在Ruby中执行一个外部进程,并将标准输出或标准错误收集到一个字符串中,其方式类似于使用Python的子进程Popen.communicate()可以完成的操作。我尝试将:out/:err重定向到一个新的StringIO对象,但这会生成一个ArgumentError,并且临时重新定义$stdxxx会混淆子进程的输出。 最佳答案 如果你不喜欢popen,这是我的方法:r,w=IO.pipepid=Process.spawn(command,:out=>w,:err=>[:child,:out])

  5. ruby - Ruby 中的闭包和 for 循环 - 2

    我是Ruby的新手,有些闭包逻辑让我感到困惑。考虑这段代码:array=[]foriin(1..5)array[5,5,5,5,5]这对我来说很有意义,因为i被绑定(bind)在循环之外,所以每次循环都会捕获相同的变量。使用每个block可以解决这个问题对我来说也很有意义:array=[](1..5).each{|i|array[1,2,3,4,5]...因为现在每次通过时都单独声明i。但现在我迷路了:为什么我不能通过引入一个中间变量来修复它?array=[]foriin1..5j=iarray[5,5,5,5,5]因为j每次循环都是新的,我认为每次循环都会捕获不同的变量。例如,这绝对

  6. Ruby:数组中的下一个/上一个值,循环数组,数组位置 - 2

    假设我有一个没有特定顺序的随机数数组。假设这些是参加马拉松比赛的人的ID#,他们按照完成的顺序添加到数组中,例如:race1=[8,102,67,58,91,16,27]race2=[51,31,7,15,99,58,22]这是一个简化且有些做作的示例,但我认为它传达了基本思想。现在有几个问题:首先,我如何获得特定条目之前和之后的ID?假设我正在查看运行者58,我想知道谁在他之前和之后完成了比赛。race1,runner58:previousfinisher=67,nextfinisher=91race2,runner58:previousfinisher=99,nextfinishe

  7. ruby - 奇怪的 ruby​​ for 循环行为(为什么这样做有效) - 2

    defreverse(ary)result=[]forresult[0,0]inaryendresultendassert_equal["baz","bar","foo"],reverse(["foo","bar","baz"])这行得通,我想了解原因。有什么解释吗? 最佳答案 如果我使用each而不是for/in重写它,它看起来像这样:defreverse(ary)result=[]#forresult[0,0]inaryary.eachdo|item|result[0,0]=itemendresultendforainb基本上就

  8. ruby - 如何证明 Ruby `for` 循环实际上是使用 `each` 方法实现的? - 2

    在EloquentRuby(第21页,第一版,第六次打印)一书中,作者(RussOlsen)提倡使用each方法而不是for循环,这与我在其他地方读到的所有内容一致。但是作者还继续说,这样做的一个原因是for循环实际上调用了each方法,所以为什么不直接删掉中间人并使用each?所以我想知道这实际上是如何工作的。为了调查,我确实在github上的Ruby存储库上进行了搜索,但发现很难确定我在哪里/如何看到它的实际效果。重述问题:我如何证明Rubyfor循环实际上是使用each方法实现的? 最佳答案 您可以通过编写一个实现每个的类来展

  9. ruby - 循环遍历数组的元素 - 2

    我想从0到2循环@a:0,1,2,0,1,2。defset_aif@a==2@a=0else@a=@a+1endend也许有更好的方法? 最佳答案 (0..2).cycle(3){|x|putsx}#=>0,1,2,0,1,2,0,1,2item=[0,1,2].cycle.eachitem.next#=>0item.next#=>1item.next#=>2item.next#=>0... 关于ruby-循环遍历数组的元素,我们在StackOverflow上找到一个类似的问题:

  10. ruby - Ruby 中优雅的循环 Elsing - 2

    我必须编写一个Ruby方法:遍历数组,如果其中一个元素符合特定条件则执行Foo。如果没有数组元素符合条件,则执行Bar操作。在任何其他语言中,我会在进入循环之前设置一个bool变量,并在执行Foo时切换它。该变量的值会告诉我是否需要Bar。但这感觉不像Rubyish那样不优雅。谁能提出更好的方法?编辑一些非常好的答案,但由于我本应提及的细节,它们不太有效。Foo所做的事情是对符合条件的数组元素完成的。此外,保证最多有一个元素匹配条件。 最佳答案 是否有任何项目匹配?如果是,则做一些不涉及匹配项目的事情。ifitems.any?{|i

随机推荐