How can i include a variable and make it part the string.
header('Location: http://www.' . '$_SESSION['domainname']');
The above code doesn’t work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The reason why your code didn’t work is due to how PHP handles indexed arrays inside strings. You had:
But what PHP wanted to see was:
No single quotes this time. You only omit those single quotes if you are referencing a variable directly inside a string.
Note that string interpolation, such as this, can work with simple arrays (
'$a[x]') but not with arrays of arrays ('$a[x][y]') unless you use curly braces ({$x},{$a['x']['y']}; note the single quotes in the curly braces–they aren’t exactly like PHP’s normal string interpolation, but rather more like referencing a variable elsewhere in PHP).