How can i execute a link in a php page
I have a test.php page
in this page , there is a url . i need to execute that url (here database updation is doing).This is my code
<?php
$username ='testUsername';
if($_GET['age']!=''){
header('location:www.test.com/update.php?age='.$_GET['age'].'&username='.$username); //need to updatethe age of this username
$show ='hello';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD开发者_如何学C/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php echo $show ?>
</body>
</html>
i know this code is not going to work properly.How can i write in a good way.I donot want to redirect the page.I just need to execute that link
Just call file_get_contents
on the url in question instead of setting the location header to that value.
Since the update.php
file is hosted on an external website, the only thing you can do is get the contents of the output of the file. (Use file_get_contents
to get that output.) That is, it will call the file (with your parameters) and you can fetch the HTML result of it—nothing more. It would be a major security problem if server files could be executed on external websites.
If you need to include the code in update.php without redirecting, you can do so with the include or require functions.
require() is identical to include() except upon failure it will ... halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue.
Use the IMG tag. <img widht=0 height=0 src="<?='location:www.test.com/update.php?age='.$_GET['age'].'&username='.$username ?>" />
精彩评论