<script type="text/javascript"> <!--Invocation code--> var infobar=new informationbar() infobar.setContent('<?php if ($_SESSION['username']){ echo 'Welcome $_SESSION['username']'; }else{ echo 'Welcome to GameCrayz! Please log in. Need to register? Click <a href="register.php">Here</a>!'; } ?>') infobar.setfrequency('session') infobar.initialize() </script>
Session variable in string
Session variable in string
Hey, i want to do something like. for example. a popup bar appears and if i'm logged in, it would say welcome $_SESSION['username'] and if i'm not, then it will say some stuff bout signing up. anyways how am i able to make it say the username in the echo''; i've tried a lot of thins and now i'm out of ideas
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Quick help plz
<?php if(isset($_SESSION['username'])) { ?> <script type="text/javascript"> window.alert("Welcome <?php echo $_SESSION['username']; ?>!"); </script> <?php } else { ?> <script type="text/javascript"> window.alert("Welcome to GameCrayz! Please log in. Need to register? Go to the register page!"); </script> <?php } ?>Links don't work in popups.
<?php while(!$succeed = try()); ?>
Re: Quick help plz
[quote="ExtremeGaming"]
http://gyazo.com/5af6fcb2b2c7a1891132be25d36008a9
I Just need help with this... thanks...
echo 'Welcome '$_SESSION['username'];
<?php if(isset($_SESSION['username'])) { ?> <script type="text/javascript"> window.alert("Welcome <?php echo $_SESSION['username']; ?>!"); </script> <?php } else { ?> <script type="text/javascript"> window.alert("Welcome to GameCrayz! Please log in. Need to register? Go to the register page!"); </script> <?php } ?>Derp, oops i ment a sort of banner at the top, not a actual popup.
http://gyazo.com/5af6fcb2b2c7a1891132be25d36008a9
I Just need help with this... thanks...
echo 'Welcome '$_SESSION['username'];
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Quick help plz
Single quoted variables don't get parsed in php
<script type="text/javascript"> <!--Invocation code--> var infobar=new informationbar() infobar.setContent('<?php if ($_SESSION['username']){ echo "Welcome $_SESSION['username']"; }else{ echo 'Welcome to GameCrayz! Please log in. Need to register? Click <a href="register.php">Here</a>!'; } ?>') infobar.setfrequency('session') infobar.initialize() </script>
<?php while(!$succeed = try()); ?>
Re: Quick help plz
i did that and i got an errorExtremeGaming wrote:Single quoted variables don't get parsed in php
<script type="text/javascript"> <!--Invocation code--> var infobar=new informationbar() infobar.setContent('<?php if ($_SESSION['username']){ echo "Welcome $_SESSION['username']"; }else{ echo 'Welcome to GameCrayz! Please log in. Need to register? Click <a href="register.php">Here</a>!'; } ?>') infobar.setfrequency('session') infobar.initialize() </script>
http://gyazo.com/d1bed48f67f19381ae2fe71e0da917bf
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Quick help plz
My bad I should've expected that
This should be the error.
This should be the error.
echo "Welcome $_SESSION['username']";Change it to
echo "Welcome ".$_SESSION['username']." ";
<?php while(!$succeed = try()); ?>
Re: Quick help plz
Thanks, you are literally 'AWESOME'.
Re: Quick help plz
You can also avoid having to join two strings together by doing
echo "Welcome", $_SESSION['username'];which is generally a bit faster, not that you will notice it on a real site but worth mentioning