davidfattore Posted November 1, 2013 Share Posted November 1, 2013 Hey guys, No this may very well be a silly question and if it is, I'm certain to have a decent bit of embarrassment, as I'm somewhat of a veteran when it comes to PHP but I've only just started to look for a viable solution to this particular hiccup. Is there a way in the PHP Header file to include "print $_SESSION ['username']", without it causing a syntax error? I'll provide more context by embedding my code! <?php if ((isset($_SESSION['user_id']))&&(!strpos($_SERVER['PHP_SELF'],'logout.php'))) { print '<span> <a href="login/" id="link-login">Log in</a> <span class="pre-login-or">or</span> <a href="register/" id="link-register">Register</a></span>'; } else{ print 'Benvenutti $_SESSION ['username'], al Torneo di Briscola due mila tredici'; }?> That in itself will cause an unexpected T_STRING syntax error... the only option I can see is by employing the use of an iframe and linking the source to a separate PHP document with the "Welcome" text, but I was hoping there was another was to achieve this with the iframe. Link to comment https://forums.phpfreaks.com/topic/283490-php-header-quandary/ Share on other sites More sharing options...
requinix Posted November 1, 2013 Share Posted November 1, 2013 Three ways of putting an array into a string: "before " . $_SESSION["username"] . " after" // no surprise here "before $_SESSION[username] after" // no quotes for the array key "before {$_SESSION["username"]} after" // with quotes. ' or ", {$ or ${(forum's highlighting is wrong for the third but the syntax is correct) Link to comment https://forums.phpfreaks.com/topic/283490-php-header-quandary/#findComment-1456453 Share on other sites More sharing options...
davidfattore Posted November 1, 2013 Author Share Posted November 1, 2013 Thanks so much, that worked perfectly, I'm kicking myself and the obviousness of the solution lolI knew it would be something silly like that. Link to comment https://forums.phpfreaks.com/topic/283490-php-header-quandary/#findComment-1456459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.