Problem with curl

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cdunde1
Forum Newbie
Posts: 6
Joined: Wed Aug 27, 2008 5:37 pm

Problem with curl

Post by cdunde1 »

I am trying to use this script and I am getting this error on the page "Parse error: parse error, unexpected T_GLOBAL in d:\websites\gatormaniacscom\test2.php on line 11" My host does have curl enabled and they think it's a coding error possible due to a missing colon or a space somewere? Any help would be appreciated. Here is the code

<? php
global $IPAddress,$_SERVER,$UserAgent,$PageURL,$URL;
$IPAddress = urlencode($_SERVER['REMOTE_ADDR']);
$UserAgent = urlencode($_SERVER['HTTP_USER_AGENT']);
$PageURL = urlencode($_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING ']);
$URL = "http://si.goldencan.com/GetData.aspx=1C ... 827381FF99;"
$URL = $URL.'&IPAddress='.$IPAddress;
$URL = $URL.'&UserAgent='.$UserAgent;
$URL = $URL.'&PageURL='.$PageURL;
readFile($URL);
$goldencanurl=$URL.'&PageURL='.$PageURL.'&IPAddress='.$IPAddress.'&UserAgent='.$UserAgent;

// create a new CURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "$goldencanurl");
curl_setopt($ch, CURLOPT_HEADER, false);
// grab URL and pass it to the browser
curl_exec($ch);
// close CURL resource, and free up system resources
curl_close($ch);
?>
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Problem with curl

Post by ghurtado »

Are you sure this is the code for test2.php and that it produces the error you posted? Is there another page that includes this one?

The error is a syntax error and your code contains no syntax errors that I could see.
cdunde1
Forum Newbie
Posts: 6
Joined: Wed Aug 27, 2008 5:37 pm

Re: Problem with curl

Post by cdunde1 »

Yes the gatormaniacs.com.test2.php is correct
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Problem with curl

Post by ghurtado »

Well, there's no syntax error on the code you posted line 11, so you are missing something.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Problem with curl

Post by susrisha »

here is your error in this line.. semi colon not present..

Code: Select all

 
$URL = "http://si.goldencan.com/GetData.aspx=1C107227-3713-4D0E-8B16-C0827381FF99;"
 
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Problem with curl

Post by susrisha »

please let me know if i am correct..
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Problem with curl

Post by ghurtado »

Sounds like you are probably right, I kept looking at "line 11", duh!
cdunde1
Forum Newbie
Posts: 6
Joined: Wed Aug 27, 2008 5:37 pm

Re: Problem with curl

Post by cdunde1 »

Where should the semi colon be in that line of code?
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Problem with curl

Post by ghurtado »

8O

... at the end
cdunde1
Forum Newbie
Posts: 6
Joined: Wed Aug 27, 2008 5:37 pm

Re: Problem with curl

Post by cdunde1 »

I put the semi colon at the end of the line and i still get this error on the page

<b>Parse error</b>: parse error, unexpected T_GLOBAL in <b>d:\websites\gatormaniacscom\test2.php</b> on line <b>11</b><br />

I changed the code to this - $URL = "http://si.goldencan.com/GetData.aspx=1C ... 827381FF99";
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Problem with curl

Post by ghurtado »

Could there be another test2.php page that is getting picked up instead?
cdunde1
Forum Newbie
Posts: 6
Joined: Wed Aug 27, 2008 5:37 pm

Re: Problem with curl

Post by cdunde1 »

Not sure if this will help. Below is the original code that I was trying to use on my web page. My host told me I cannot use the code because of the "include". I was then given the curl code that I posted in my earlier post. I was wondering if there was a different curl code that I could use to get this script to work? I appreciate all the help.

<?php
$SID="D74F59B9-C1B6-49F8-9734-97084DF29181";
$IPAddress = urlencode($_SERVER['REMOTE_ADDR']);
$UserAgent = urlencode($_SERVER['HTTP_USER_AGENT']);
$Host=urlencode($_SERVER['HTTP_HOST']);
$PageURL=urlencode($_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);
$URL="http://si.goldencan.com/GetData.aspx?ver=2.0&SID=".$SID;
$URL=$URL.'&Host='.$Host;
$URL = $URL.'&PageURL='.$PageURL;
$URL = $URL.'&IPAddress='.$IPAddress;
$URL = $URL.'&UserAgent='.$UserAgent;
include($URL);
?>
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Problem with curl

Post by ghurtado »

Let me see if I got this straight because its gotten pretty confusing: the code you originally posted was not the code that was producing the error.

Then I asked you, specifically:
ghurtado wrote: Are you sure this is the code for test2.php and that it produces the error you posted? Is there another page that includes this one?
Yesterday you said "yes, I'm sure"

Now in your latest post you say "Not sure if this will help. Below is the original code that I was trying to use on my web page...."

Is this finally the code I have been asking for all along, the one that produces the original error you posted?
cdunde1
Forum Newbie
Posts: 6
Joined: Wed Aug 27, 2008 5:37 pm

Re: Problem with curl

Post by cdunde1 »

Sorry for confusing you. Hopefully this will clear it up. I signed up with goldencan.com to have a product data feed displayed on my site. The code that I was given to display the data feed is this code -

<?php
$SID="D74F59B9-C1B6-49F8-9734-97084DF29181";
$IPAddress = urlencode($_SERVER['REMOTE_ADDR']);
$UserAgent = urlencode($_SERVER['HTTP_USER_AGENT']);
$Host=urlencode($_SERVER['HTTP_HOST']);
$PageURL=urlencode($_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);
$URL="http://si.goldencan.com/GetData.aspx?ver=2.0&SID=".$SID;
$URL=$URL.'&Host='.$Host;
$URL = $URL.'&PageURL='.$PageURL;
$URL = $URL.'&IPAddress='.$IPAddress;
$URL = $URL.'&UserAgent='.$UserAgent;
include($URL);
?>

This code has been placed on a web page currently at http://www.gatormaniacs.com/test1.php. That page displays a blank page. My host told me I cannot use the code because of the "include" in the code. They instructed me to use "Curl'. Goldencan.com gave me the following curl code which is curently on the web page at http://www.gatormaniacs.com/test2.php. That page gives the "Parse error: parse error, unexpected T_GLOBAL in d:\websites\gatormaniacscom\test2.php on line 11" error.

Curl Code - <?php global $IPAddress,$_SERVER;

$URL = "http://si.goldencan.com/GetData.aspx=1C ... 827381FF99";

$PageURL = urlencode($_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING']);

$IPAddress = urlencode($_SERVER['REMOTE_ADDR']);

$UserAgent = urlencode($_SERVER['HTTP_USER_AGENT']);

$goldencanurl=$URL.'&PageURL='.$PageURL.'&IPAddress='.$IPAddress.'&UserAgent='.$UserAgent;

// create a new CURL resource

$ch = curl_init();

// set URL and other appropriate options

curl_setopt($ch, CURLOPT_URL, "$goldencanurl");

curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser

curl_exec($ch);

// close CURL resource, and free up system resources

curl_close($ch);

?>

My webhost has no idea why the curl code wont work and Goldencan.com has not been much help either.
Post Reply