Hi all, can someone tell me why I am unable to concatinate the variable $id to the members.php ?

Its driving me mad. . .

$id = $row["id"];

        	        $_SESSION['SESS_MEMBER_ID'] = $id;		   
		   	setcookie("id", $id, time()+86400);
							
			$securecode = $row["securecode"];
			$_SESSION['SESS_SECURE_CODE'] = $securecode;
			setcookie("securecode", $securecode, time()+86400);
			
			$creff = $row["creff"];
			$_SESSION['SESS_CREFF'] = $creff;
			setcookie("creff", $creff, time()+86400);
			
		/*
		Login and go to members area											
		*/
		//header("location: members.php?id=" ' .$_SESSION['id']. ');
		//header("Location: members.php?id=$id");
		//  
		//header("Location: members.php?id= ' .$_SESSION['SESS_MEMBER_ID']. '")
		//securecode.php?id=
		//header("Location: members.php?id='.id.'");
		//header("Location: members.php?id=$id");
		header("Location: members.php?id=<? print '.$id ?>");

Recommended Answers

All 2 Replies

header("Location: members.php?id={$id}");
//or
header("Location: members.php?id=".$id);

header is a php command and is already inside php tags so there is no need to use php tags again, it's like playing with a string such as echo "members.php?id=$myvar";

String help:

strings in php are opened with a single or double quote, once opened they need to be ended with the same type quote and can be concatenated with a .

eg.

echo "hello ".$name."!";
echo 'hello '.$name."!";
echo 'hello '.$name.'!';
echo "hello {$name}!";
//all output
//hello Biiim!

note single quotes do not get special processing:

echo 'hello {$name}!\r\n';
//will print out exactly
//hello {$name}!\r\n

where as

echo "hello {$name}!\r\n";
//will print out hello Biiim!
// <- newline

you can escape characters in a string using a backslash eg.

echo "hello \"{$name}\"!";
//will print out 
//hello "Biiim"!

Infact your second header commented out should of worked:

//header("Location: members.php?id=$id");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.