Jump to content

PHP Header Quandary


davidfattore
Go to solution Solved by requinix,

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
Share on other sites

  • Solution

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) Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.