I’m using PHP’s file_get_contents in a way that makes it an API without XML. I’ve done this several times before, but today, it’s outputting the file’s ACTUAL PHP as opposed to the output HTML which is what I’m trying to get!
Here’s the code:
File I’m getting, udp.php
<?php
session_start();
$user = $_SESSION['xxxxxx'];
require("connect.php");
$data = mysql_query("SELECT * FROM xxx WHERE xxx='$xx'");
$row = mysql_fetch_assoc($data);
/* Fetch Array */
$email = $row['email'];
$name = $row['firstname'].' '.$row['lastname'];
$location = $row['location'];
$dob = $row['dob'];
$gender = $row['gender'];
$dp = $row['dp'];
$joindate = $row['joindate'];
$var = $email.'@@@@'.$name.'@@@@'.$location.'@@@@'.$dob.'@@@@'.$gender.'@@@@'.$dp.'@@@@'.$joindate;
echo $var;
?>
And I’m using this:
<?
$getdata = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/udp.php');
echo $getdata;
?>
To get the file contents from udp.php, but the problem is, I’m not getting $var, I’m getting the ACTUAL PHP! The return data is the exact PHP file contents. The actual udp.php file renders $var the way I want it to, but when getting the file, it renders the exact PHP.
That is kind of confusing to me :S
Any Ideas?
Thanks! 🙂
$_SERVER['DOCUMENT_ROOT']contains a local filesystem path. The PHP interpreter is never being invoked, so you just get the file contents.You either need to
file_get_contents()it via a URL, or capture the output frominclude()with some buffering and store the value that way.