Jump to content

PHP Header Quandary


davidfattore

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.