Php 如何将if(isset($authUrl))分配给div内的图像
我成功地修改了使用Google plus API登录的代码,并且在localhost上运行良好 我试图将Php 如何将if(isset($authUrl))分配给div内的图像,php,html,Php,Html,我成功地修改了使用Google plus API登录的代码,并且在localhost上运行良好 我试图将$authUrl(gplus login.php)值分配给另一个php文件“trackorder.php”图像(在div标记内) Trackorder.php文件,我要将$authUrl值放在其中 <div style="margin-left:50px;"> <a href=""> <img src="images/Google-bu
$authUrl
(gplus login.php)值分配给另一个php文件“trackorder.php”图像(在div标记内)
Trackorder.php文件,我要将$authUrl值放在其中
<div style="margin-left:50px;">
<a href="">
<img src="images/Google-button.png" style="width:200px; height:35px;"></a>
</div>
gplus login.php
<?php
require_once 'src/apiClient.php';
require_once 'src/contrib/apiPlusService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("My Project");
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
$plus = new apiPlusService($client);
if (isset($_REQUEST['logout']))
{
unset($_SESSION['access_token']);
}
if (isset($_GET['code']))
{
$client->authenticate();
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token']))
{
$client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken())
{
$me = $plus->people->get('me');
$optParams = array('maxResults' => 100);
$activities = $plus->activities->listActivities('me', 'public',$optParams);
// The access token may have been updated lazily.
$_SESSION['access_token'] = $client->getAccessToken();
}
else
{
$authUrl = $client->createAuthUrl();
}
?>
<div>
<?php if(isset($me))
{
$_SESSION['gplusdata']=$me;
header("location: home.php");
}
?>
<?php
if(isset($authUrl))
{
print "<a class='login' href="$authUrl">Google Login</a>";
}
else
{
print "<a class='logout' href='trackorder.php?logout'>Logout</a>";
}
?><br/>
</div>
您可以包含Trackorder.php,并在包含之前设置动态变量
<?php
if(!isset($authUrl)) {
$authUrl = 'trackorder.php?logout';
$authLabel = 'Logout';
$authClass = 'logout';
} else {
$authLabel = 'Google Login';
$authClass = 'login';
}
include('Trackorder.php');
?>
对于Trackorder.php
<div style="margin-left:50px;">
<a href="<?= $authUrl; ?>" class="<?= $authClass; ?>"><?= $authLabel; ?>
<img src="images/Google-button.png" style="width:200px; height:35px;"></a>
</div>
不确定要对链接中的图像执行什么操作
如果您只希望Trackorder.php文件用于登录,只需将include移到else中,并恢复初始If子句以弹出注销链接