request page using curl

hello there,
I am using curl for my forum to verify download links from free hosting services..
i am having trouble trying to verify a site that has cookie in order to verify if the file
exists or has been deleted.. if you dont accept cookies you will get the same page
even though the file doesnt exist.. but if you accept cookies the page will show file
does not exist. im trying to fix this code and make it work..
function curl($link, $post='0')
{
    if($fgc == 1)
	{
        file_get_contents($link);        
	}
    else
	{
		$ch = curl_init($link);
		curl_setopt($ch, CURLOPT_HEADER, 0);
	    if(eregi("megashares\.com" , $link))
		{
        curl_setopt($ch, CURLOPT_COOKIE, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		}
				curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		if($post != '0')
		{
				curl_setopt($ch, CURLOPT_POST, 1);
				curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
		}
		$page = curl_exec($ch);
		echo $page;
		return($page);
				curl_close($ch);
	}
}

Open in new window

LVL 1
XK8ERAsked:
Who is Participating?
 
agamalConnect With a Mentor Commented:
seems like working code to me

i added to tries at the end try it your self ...

<?php
function curl($link, $post='0')
{
    if($fgc == 1)
        {
        file_get_contents($link);
        }
    else
        {
                $ch = curl_init($link);
                curl_setopt($ch, CURLOPT_HEADER, 0);
            if(eregi("megashares\.com" , $link))
                {
        curl_setopt($ch, CURLOPT_COOKIE, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 1);
        curl_setopt($ch, CURLOPT_COOKIEFILE, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                }
                                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                if($post != '0')
                {
                                curl_setopt($ch, CURLOPT_POST, 1);
                                curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
                }
                $page = curl_exec($ch);
                echo $page;
                return($page);
                                curl_close($ch);
        }
}
//not working
curl('http://d01.megashares.com/?d01=41614f7');
//working
//curl('http://d01.megashares.com/?d01=b652976');
 
 
?>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.