Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send parameters using php file_get_content function

Tags:

php

Dear all,
How i send parameters using php file_get_content function.

$id='123';
$name='blah';
$response=file_get_contents('http://localhost/abc/abc.php?id=$id&name=$name');  
echo $response;

I need to send the $id and name value to abc.php page.Here the value passing does not working.also i chk ?id="$id"&name="$name" value.It's also not working. But the straite parameter works.say-

$response=file_get_contents('http://localhost/abc/abc.php?id=123&name=blah');

Now is their any Kind heart who can help me to send the 2 parameters $id and $name to abc.php?

Thanks
riad

like image 228
riad Avatar asked Dec 22 '22 20:12

riad


2 Answers

If you want to enable variable substitution in a string, you have to use double quotes:

$response=file_get_contents("http://localhost/abc/abc.php?id=$id&name=$name"); 
like image 39
Simon Avatar answered Jan 13 '23 18:01

Simon


Single quotes inhibit variable substitution.

$response=file_get_contents("http://localhost/abc/abc.php?id=$id&name=$name");

Don't forget to URL-encode all parameters though.

like image 141
Ignacio Vazquez-Abrams Avatar answered Jan 13 '23 16:01

Ignacio Vazquez-Abrams