Reputation: 51
I have one problem to redirect my page with email id.My page is redirect properly but not showing email id at the time of redirect.
not working code
$email2='[email protected]';
$var = 'location:';
$var .= 'https://www.ymlp.com/api/Contacts.Add?Key=5ESTZPSGT8AFJV5Y2Y4Q&Username=38bf&Email=$email2&GroupID=5';
header ($var);
It's showing variable name.
working code:
$var = 'location:';
$var .= 'https://www.ymlp.com/api/Contacts.Add?Key=5ESTZPSGT8AFJV5Y2Y4Q&Username=38bf&[email protected]&GroupID=5';
header ($var);
It's not showing variable name.
Thanks for your great help
Upvotes: 0
Views: 98
Reputation: 269
I have tried it out and works well with single quotes.
$email2='[email protected]';
$var = 'location:';
$var .= 'https://www.ymlp.com/api/Contacts.Add?Key=5ESTZPSGT8AFJV5Y2Y4Q&Username=38bf&Email='.$email2.'&GroupID=5';
header ($var);
Here is the result:
<Result>
<Code>0</Code>
<Output>[email protected] has been added</Output>
</Result>
and is showing the email on the url as this:
https://www.ymlp.com/api/Contacts.Add?Key=5ESTZPSGT8AFJV5Y2Y4Q&Username=38bf&[email protected]&GroupID=5
Upvotes: 0
Reputation: 2149
Use
$var .= 'https://www.ymlp.com/api/Contacts.Add?Key=5ESTZPSGT8AFJV5Y2Y4Q&Username=38bf&Email='.$email2.'&GroupID=5';
Or you could use
$var .= "https://www.ymlp.com/api/Contacts.Add?Key=5ESTZPSGT8AFJV5Y2Y4Q&Username=38bf&Email=$email2&GroupID=5";
Note the double quotes.
Edit: Single quotes string do not evaluate variables so if you are using single quotes do proper concatenation otherwise use double quotes for strings wrapping.
Upvotes: 0
Reputation: 453
As far as I know, variables in php are not parsed inside single quotes.
Close the string and append the variable inside using "." to concatenate.
This way: 'first part of a string '.$variable.' second part of a string';
So what you need is:
$var .= 'https://www.ymlp.com/api/Contacts.Add?Key=5ESTZPSGT8AFJV5Y2Y4Q&Username=38bf&Email='.$email2.'&GroupID=5';
Another solution would be to use double quotes instead -> "Text with $variable inside".
Upvotes: 1