简体   繁体   English

在 php 中使用 javascript function

[英]Use a javascript function in php

I have a nav bar on my site that has dynamic links.我的网站上有一个导航栏,其中包含动态链接。 When the user is logged out, I want these links to say "Register | Log in" and when they are signed in, I want those same links to change to "$userName | Account".当用户注销时,我希望这些链接显示“注册|登录”,当他们登录时,我希望这些相同的链接更改为“$userName | Account”。 I have a script to handle this, but there is one problem.我有一个脚本来处理这个问题,但是有一个问题。

When the user is signed out, I want the "Register" link to open a popup div with the registration page on it, instead of forwarding them to a different page.当用户退出时,我希望“注册”链接打开一个带有注册页面的弹出 div,而不是将它们转发到不同的页面。 The only problem is, the way I am handling this is in a link like唯一的问题是,我处理这个的方式是在一个链接中

<a href="#" onClick="popup('popUpDiv')">Register</a>

But I need to call this in a php script.但我需要在 php 脚本中调用它。

Any Help is appreciated.任何帮助表示赞赏。

This is from the php script.这是来自 php 脚本。

 if (!isset($_COOKIE['idCookie'])) {
 $logOptions = ' <a href="http://' . $dyn_www . '/register.php">Register</a>
 &nbsp;&nbsp; | &nbsp;&nbsp; 
 <a href="http://' . $dyn_www . '/login.php">Log In</a>';

} }

But instead of having the whole register.php, i just want it to go to但不是拥有整个寄存器。php,我只希望它到 go 到

<a href="#" onClick="popup('popUpDiv')">Register</a>

I think what you want to use if you are looking to do it in php is this...我想如果你想在 php 中使用,你想使用的是这个......

header('location: http://yoururl.com/page.php')

Sorry if I don't understand the question completely.对不起,如果我不完全理解这个问题。 Posting some code would help.发布一些代码会有所帮助。

Hope this helps:)希望这可以帮助:)

Simply do a server-side check around the HTML you want to output.只需围绕您想要 output 的 HTML 进行服务器端检查。 PHP is parser based. PHP 是基于解析器的。

Try something like this:尝试这样的事情:

<?php
if ($ID = '') {
echo "<script language=javascript>alert('Please enter a valid username.')</script>";
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM