2012-10-12 54 views
3

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

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 protected]'; 
    $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; 
?> 
+0

不,请参阅编辑。 – Colin747

+0

'Home.php'包含'Cal.php' – andrewsi

回答

3

它看起来像原因是

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

在home.php

你需要把一个条件在你的头重定向。

您可以使用:

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

HTML是Home.php PHP是Cal.php – Colin747

+0

这工作谢谢! – Colin747

2

通过包括Home.phpCal.php每次您发送的Redirect头中的用户访问Home.php

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