3

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

  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;
?>
4

2 回答 2

3

看起来原因是

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

在你的 home.php

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

您可以使用:

if(isset($_POST['Content']))
    header("Location: http://localhost/Project/View/Home.php");
于 2012-10-12T15:42:39.097 回答
2

通过包含Cal.phpfrom您每次用户访问时Home.php都发送标头。RedirectHome.php

另一种方法是从您的网站中删除重定向,然后将其Home.php发布到Cal.php。乍一看,您不需要将其包含Cal.php在您的主页中。

于 2012-10-12T15:44:40.730 回答