#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    29
    Rep Power
    0

    Exclamation File_get_contents does not execute php properly!


    Greetings everyone..

    I m facing a problem..
    I need to execute a remote php file and get the return value in variable or print that.

    but the problem is if I run the remote php file directly (in browser address bar) it works fine (it give new data based on cookies value each time)

    but if I try to get that remote php return value using php file_get_contents it does not works good and only return fixed data..

    please check out the attached file (source php files) that will help you to understand..

    opps! i didn't find way to attach..

    ok say this is the remote file:
    Code:
    http://www.exmple.com/sample.php
    here is the code for that remote file:
    Code:
    <?php
    
    	$strMainArray = array('01', '05', '06', '07', '09', '11', '12', '14');
    	$strSubArray = array('02', '03', '04', '08', '10', '13', '15', '16');
    	$strArray = array_merge($strMainArray, $strSubArray);
    	//Get App No
    	if (!isset($_COOKIE['bApp']))
    	{
    		$bApp ='0';
    	}
    	else
    	{
    		$bApp = $_COOKIE["bApp"];
    	}
    	
    	if (!is_numeric($bApp))
    	{
    		$bApp ='0';
    		setcookie('bApp', $bApp, time() + (86400 * 180));
    	}
    	else
    	{
    		if ($bApp == count($strArray))
    		{
    			$bApp ='0';
    		}		
    		setcookie('bApp', $bApp + 1, time() + (86400 * 180));	
    	}
    	
    	$strInfo = $strArray[$bApp];
    
    	echo $strInfo;
    ?>
    Now say this is the local file (on another domain/server):
    Code:
    <?php
    
    	echo file_get_contents("http://YourDomain.com/static-c.php");
    
    ?>
    so, for example if i run remote file directly on browser address bar:
    it returns
    01, 05, 06 etc (on each run)

    but if run the php file that call that remote file though file_get_contents function, it always return 01

    i hope i have gave enough information..

    please help me out

    thanks in advance..

    best regards
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,399
    Rep Power
    594
    The function 'get_file_contents' does exactly that. It does not execute the file, it merely gets it as text. Perhaps you should look at curl.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    29
    Rep Power
    0

    Exclamation


    Originally Posted by gw1500se
    The function 'get_file_contents' does exactly that. It does not execute the file, it merely gets it as text. Perhaps you should look at curl.
    1st, i must thank you for your kind reply

    but i can't use curl

    because that remote file returned value will be used as link location for example:
    Code:
    <a href="<?php echo file_get_contents( "http://example.com/example.php"); ?>" target="_blank">
    i hope i m clear..

    sir, is there any other way to accomplish that?

    thanks in advance for your next reply

    best regards
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,399
    Rep Power
    594
    Perhaps I am still not understanding but if it returns a link, extract the URL and use header to redirect to that location.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo