Deepak Chaudhary Deepak Chaudhary - 3 months ago 7
PHP Question

Change Text and href of a tag after login

<li><a href="login.php" class="changelogin" title="Log In">Log In</a></li>


This link will go to the login page and there I will login but after login it should change the text to "profile" and and href= "userwork.php".

<?php
session_start();
if (isset($_SESSION['email']))
{
echo "<script type='text/javascript'>";
echo "$('.changelogin').text('Profile')";
echo "$('.changelogin').attr('href', 'userwork.php')";
echo "</script>";
}
?>

Answer

Why not doing something like this ?

<?php 
if (isset($_SESSION['email'])) {
    echo '<li><a href="userwork.php" title="Profile">Profile</a></li>';
} else {
    echo '<li><a href="login.php" title="Log In">Log In</a></li>';
}
?>
Comments