0

I'm working within the XAMPP environment on a windows 7 64-bit machine. I have Apache 2.4 service installed. The issue I'm having has baffled me for about a day now.

My php files have all executed as expected up to this point. Recently, I've created a file which begins with the following:

    function get_web_page($url,$attempt=1){
        if($attempt <4){
            $options = array(
                CURLOPT_RETURNTRANSFER => true,     // return web page
                CURLOPT_HEADER         => false,    // don't return headers
                CURLOPT_FOLLOWLOCATION => true,     // follow redirects
                CURLOPT_ENCODING       => "",       // handle all encodings
                CURLOPT_USERAGENT      => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120427 Firefox/15.0a1", // who am i
                CURLOPT_AUTOREFERER    => true,     // set referer on redirect
                CURLOPT_CONNECTTIMEOUT => 30,      // timeout on connect
                CURLOPT_TIMEOUT        => 30,      // timeout on response
                CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
            );
            $ch      = curl_init( $url );
            curl_setopt_array( $ch, $options );
            $content = curl_exec( $ch );
            $err     = curl_errno( $ch );
            $errmsg  = curl_error( $ch );
            $header  = curl_getinfo( $ch );
            curl_close( $ch );

            if($err == 0){
                return $content;
            }else{
                return get_web_page( $url, $attempt + 1 );
            }
        }else{
            return FALSE;
        }
    }

A simple function to retrieve a web page, and it doesn't echo anything, either. But when I visit this page in a browser (which at this point ONLY defines a function and nothing else), it prints to the page everything following the first instance of "=>" (without quotes). I don't understand why this is. All of my other php files in the same directory behave as expected.

Please help me understand why this is happening and what steps I should take to resolve it.

3
  • 3
    Are you sure you added the php tags ? <?php code here ?> Commented Dec 7, 2012 at 17:19
  • I have tried both <?php and the shorthand <? . But thank you for the suggestion; it may help someone in the future who has overlooked this issue. Commented Dec 7, 2012 at 17:23
  • 1
    you sure thats all in the file? coz i can't really find anything that might cause the issue that you mentioned.. Commented Dec 7, 2012 at 17:24

1 Answer 1

2

Look at the source of the page given to your browser and you'll probably see the entire php source in plaintext. It's only rendering what's after the first => because that's likely the first closing > it finds after the opening < in <?php. The first part doesn't render because your browser thinks it's inside some strange HTML tag.

Check your apache config, because it's not routing requests for *.php pages through the PHP interpreter.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it was in fact interpreting it as a tag. I should've looked a the source code immediately. It's strange that other files in the same directory are functioning normally, but at least this gives me something to go on. Many thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.