Forum Moderators: coopster

Message Too Old, No Replies

Send a cookie from server script to other server

Send a cookie from server script to other serve

         

beckj

2:35 pm on Feb 16, 2011 (gmt 0)

10+ Year Member



Hello all
I have a script on my site that needs to pick up some additional information from another web site where I have an account to have full access. I want to read the content of that page and search and extract some fields.
The problem is: How to provide the other site with the required cookie?
I have that cookie on my client and search for a possibility to dynamically create and send that cookie in a way that the other site treats me as being logged in.

TIA

Demaestro

3:36 pm on Feb 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What are using to make the connection to the other page? Curl?

beckj

4:44 pm on Feb 16, 2011 (gmt 0)

10+ Year Member



I'm a beginner in PHP programmind using the easy way with fopen, fread.
I am aware of the PHP setting allow_url_fileaccess. Except the cookie everything is working fine.

rocknbil

5:54 pm on Feb 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't set a cookie on one domain from another, this is a basic concept of cookie security. Cookies can only be set or read from a given domain.

beckj

6:00 pm on Feb 16, 2011 (gmt 0)

10+ Year Member



I just want to simulate being a client and provide the cookie information as my browser does when accessing this domain. I think of a "virtual" cookie that can be created at runtime in my script and then sent when the other domain asks for it.

beckj

6:01 pm on Feb 16, 2011 (gmt 0)

10+ Year Member



BTW:
Curl would be available on my ISP's server (If I only knew what to do with it):
cURL support enabled
cURL Information libcurl/7.20.1 OpenSSL/1.0.0a zlib/1.2.3 libidn/1.15 libssh2/1.2.6

Demaestro

11:12 pm on Feb 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



beckj

You can set a cookie using curl but as rnb pointed out your site can't set a cookie for another site.

Does the site in question have a API?

I know that sites like Facebook and Twitter allow you to login from other sites, not sure if the site you are trying to do this with has such a "connect" login feature.

There may be a way to use Curl to go through the login process on the site in question and the curl connection may allow the site to set the cookie to it.
Which if you keep open may allow you to make hits to pages behind a login wall, but I have never tried such a thing.

rocknbil

7:41 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The cookie is just what KEEPS you logged in when in a browser. Try it with cookies disabled. You'll be able to do things, but will have to log in with every page.

So there's your answer; with every query you curl you will have to pass the login name and password. That *should* work. If it doesn't, it means they are doing a cookie check to prevent automated requests and you won't be able to . . . because they don't want you to. :-)