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
[syntax=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>[/syntax]
Session variable in string
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Quick help plz
[syntax=php]<?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
}
?>[/syntax]
Links don't work in popups.
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
}
?>[/syntax]
Links don't work in popups.
<?php while(!$succeed = try()); ?>
Re: Quick help plz
[quote="ExtremeGaming"][syntax=php]<?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
}
?>[/syntax]
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'];
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
}
?>[/syntax]
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
[syntax=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>[/syntax]
[syntax=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>[/syntax]
<?php while(!$succeed = try()); ?>
Re: Quick help plz
ExtremeGaming wrote:Single quoted variables don't get parsed in php
[syntax=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>[/syntax]
i did that and i got an error
![Crying or Very Sad :cry:](./images/smilies/icon_cry.gif)
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.
[syntax=php]echo "Welcome $_SESSION['username']";[/syntax]
Change it to
[syntax=php]echo "Welcome ".$_SESSION['username']." ";[/syntax]
![Embarrassed :oops:](./images/smilies/icon_redface.gif)
This should be the error.
[syntax=php]echo "Welcome $_SESSION['username']";[/syntax]
Change it to
[syntax=php]echo "Welcome ".$_SESSION['username']." ";[/syntax]
<?php while(!$succeed = try()); ?>
Re: Quick help plz
Thanks, you are literally 'AWESOME'.
![Wink ;)](./images/smilies/icon_e_wink.gif)
![Wink ;)](./images/smilies/icon_e_wink.gif)
![Wink ;)](./images/smilies/icon_e_wink.gif)
![Wink ;)](./images/smilies/icon_e_wink.gif)
![Wink ;)](./images/smilies/icon_e_wink.gif)
![Wink ;)](./images/smilies/icon_e_wink.gif)
Re: Quick help plz
You can also avoid having to join two strings together by doing
[syntax=php]echo "Welcome", $_SESSION['username'];[/syntax]
which is generally a bit faster, not that you will notice it on a real site but worth mentioning![Razz :P](./images/smilies/icon_razz.gif)
[syntax=php]echo "Welcome", $_SESSION['username'];[/syntax]
which is generally a bit faster, not that you will notice it on a real site but worth mentioning
![Razz :P](./images/smilies/icon_razz.gif)