简体   繁体   English

如何创建动态链接?

[英]How to create a dynamic link?

I'm trying to create a link that takes the user to two different pages depending is the user logged or not. 我正在尝试创建一个链接,该链接将用户带到两个不同的页面,具体取决于用户是否登录。 Problem is I'm still new to programming and this is quite big bite for beginner like me but its something I have to do. 问题是我还是编程新手,对于像我这样的初学者来说,这是一个很大的挑战,但这是我必须要做的。 I created something like this so far but either way I suck at searching or there just isnt specific information for what I need 到目前为止,我已经创建了这样的内容,但是无论是通过搜索还是在获取我所需的特定信息方面,

<?php if($userLogged){ 
 echo '<a href="index.php" class="stylelink">';
 } 
 else 
 { 
 echo '<a href="index1.php" class="stylelink">';
 } 
 echo "Etusivu</a>";
?>

I'm also using Dreamweaver's login function that creates the MM_Username session and such, and Im not sure how to make the condition. 我还使用了Dreamweaver的登录功能,该功能创建了MM_Username会话等,我不确定如何设置条件。 userLogged is still an empty variable. userLogged仍然是一个空变量。 Id appreciate any advice. 我很感谢任何建议。

Thanks -John 谢谢-约翰

well, instead of using echo statements in the php tag you can write html and use php for outputting the value of the page like this 好吧,您可以编写html并使用php来输出页面值,而不是在php标签中使用echo语句,就像这样

<a href="<?php echo (isset($_SESSION['MM_Username']))?'index.php':'index1.php';?>" class="stylelink">Etusivu</a>

The $_SESSION['MM_Username'] works if you have included session_start(); 如果包含了session_start();$_SESSION['MM_Username']有效session_start(); at the beginning of the page and you can use the condition as above instead of $userLogged. 在页面的开头,您可以使用上述条件代替$ userLogged。

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

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