-1

I have got PHP code to show a JavaScript button to the logged in users and it wont display anything if they are not logged in. But it only gives me a white page? The code itself is working because I've used it before but not with javascript.

<div align="center">
    <?php
        session_start();
        if (!isset($_SESSION['user'])) 
        { 
           echo "<a href=\"" target=\"_blank\"></a>"; 

        }else{
           echo"<div align="right">
                   <input type="button" onclick="document.title = 'Google';" value="Change Title to Google">";
        }
    ?>
3
  • 3
    You need to escape the double quotes in your echo. Or put the echoed string between single quotes. After that it might work. Commented Dec 9, 2013 at 10:15
  • set error_reporting to E_ALL and display_errors to true to see when things go wrong. Commented Dec 9, 2013 at 10:16
  • echo "<div align=\"right\"><input type=\"button\" onclick=\"document.title = 'Google';\" value=\"Change Title to Google\">"; Commented Dec 9, 2013 at 10:17

2 Answers 2

3

YOUR CODE HAving ERROS with quotes, added \,

<?php
session_start();
if (!isset($_SESSION['user'])) 
{ 
   echo "<a href=\"\" target=\"_blank\"></a>"; 

}else{
        echo "<div align=\"right\">
           <input type=\"button\" onclick=\"document.title = 'Google';\" value=\"Change Title to Google\">";
   }
?>
Sign up to request clarification or add additional context in comments.

Comments

1

Another solution would be to close your php when you don't need it :

<?php
session_start();
if (!isset($_SESSION['user'])) 
{ 
?>
<a href="" target="_blank"></a>
<?php
}else{
?>
 <div align="right"> ....
<?php
}
?>

1 Comment

I suggest more convenient method by using another syntax: <?php if(...): ?> <!--html goes here --> <?php else: ?><!-- Another html --> <?php endif; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.