如何为 php 设置<href>样式


<?php
echo "<a href='".$client->createAuthUrl()."'><button>Login with Google</button></a>";
?>

我试图在php echo中添加<a href>类,但我不能做任何我想做的样式

<?php
echo "<a href='".$client->createAuthUrl()."'><button>Login with Google</button></a>";
?>

你可以试试这样做,希望对你有帮助。

<a href="<?=createAuthUrl()?>" class="your-class-name">Login with Google"</a>

你对单引号和双引号的使用有点混乱。我还应该补充一点,标签内的按钮并不正确。我建议去掉按钮,用a标签代替。考虑到这一点,以下是选项:

常规CSS方法

echo '<a class="mylink" href="'.$client->createAuthUrl().'">Login with Google</a>';

a.mylink{
styles here
}

内联样式方法

echo '<a style="styles here" href="'.$client->createAuthUrl().'">Login with Google</a>';

从google开发的角度来看,我想问你们为什么要这样做?如果你能检测到用户没有登录,就用location头重定向用户。

<标题>index . php h1> login。
$Auth = new Oauth2Authentication();
$client = $Auth->GetClient();
$client = $Auth->initializeClient($client);

我的Oauth2Authentication类的相关代码。

function initializeClient($client)
{
try {
// Set the refresh token on the client.
if (isset($_SESSION['refresh_token']) && $_SESSION['refresh_token']) {
$client->refreshToken($_SESSION['refresh_token']);
}
// If the user has already authorized this app then get an access token
// else redirect to ask the user to authorize access to Google Analytics.
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
// Set the access token on the client.
$client->setAccessToken($_SESSION['access_token']);
// Refresh the access token if it's expired.
if ($client->isAccessTokenExpired()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
$client->setAccessToken($client->getAccessToken());
$_SESSION['access_token'] = $client->getAccessToken();
}
return $client;
} else {
// We do not have access request access.
header('Location: ' . filter_var( $client->getRedirectUri(), FILTER_SANITIZE_URL));
}
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}
<标题>oauthcallback.php h1> /html>

最新更新