473,406 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

PHP script as web client - Sessions and Cookies

Hi!

I've got an unusual problem here. I'm trying to write a PHP script that
behaves like a web client. Why? I want to automatically check specific
URLs for changes.

I'm using file_get_contents(URL) to read the pages and this seems to
work just fine as long as there are no logins, sessions or cookies.

But I'm getting a new PHPSESSID from the site whenever I get a new page
(or refresh the same page) even though I did a login through the URL
(...login.php?user=...&pass=...) and it seemed to work. So the login
does not really work.

So what do I have to do to make the login stick? Use a different way to
read the pages? Work with sessions? Cookies?

Don't forget that the script is not running on a server, it is the
client! I have not found any documentation for this rare case.

I'm curious if any of the PHP pros out there knows an answer to this
problem. If anyone does, an answer would be appreciated. Thanks in
advance.
Jul 17 '05 #1
6 3088
Anonymous <an*******@nowhere.invalid> wrote:
[php client]
So what do I have to do to make the login stick? Use a different way to
read the pages? Work with sessions? Cookies?


You should use a different way to request URLs. How are you requesting
them now? fopen? There are many intelligent ways to implement scripts
that pretend to be http clients. curl might be available on your
machine. Else there are classes like snoopy or the httpclient class in
PEAR. These will make handling cookies easier...

--

Daniel Tryba

Jul 17 '05 #2
Hi,

Are you passing the PHPSESSID back to the server in your URLs?

Kelvin

"Anonymous" <an*******@nowhere.invalid> wrote in message
news:41***************@nowhere.invalid:
Hi!

I've got an unusual problem here. I'm trying to write a PHP script that
behaves like a web client. Why? I want to automatically check specific
URLs for changes.

I'm using file_get_contents(URL) to read the pages and this seems to
work just fine as long as there are no logins, sessions or cookies.

But I'm getting a new PHPSESSID from the site whenever I get a new page
(or refresh the same page) even though I did a login through the URL
(...login.php?user=...&pass=...) and it seemed to work. So the login
does not really work.

So what do I have to do to make the login stick? Use a different way to
read the pages? Work with sessions? Cookies?

Don't forget that the script is not running on a server, it is the
client! I have not found any documentation for this rare case.

I'm curious if any of the PHP pros out there knows an answer to this
problem. If anyone does, an answer would be appreciated. Thanks in
advance.


---
Mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.773 / Virus Database: 520 - Release Date: 05/10/2004
Jul 17 '05 #3
Anonymous wrote:

I've got an unusual problem here. I'm trying to write a PHP script that
behaves like a web client. Why? I want to automatically check specific
URLs for changes.

I'm using file_get_contents(URL) to read the pages and this seems to
work just fine as long as there are no logins, sessions or cookies.

But I'm getting a new PHPSESSID from the site whenever I get a new page
(or refresh the same page) even though I did a login through the URL
(...login.php?user=...&pass=...) and it seemed to work. So the login
does not really work.

So what do I have to do to make the login stick? Use a different way to
read the pages? Work with sessions? Cookies?


I did this a couple times using fsockopen (though I hear CURL is good),
extracted the cookie information, and resent the cookie info with each request.
Read the manual and especially the comments for fsockopen. You may find you
need to send some other, custom headers (notably user agent) for some sites, as
the default settings may be interpreted as spambots.

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #4
Daniel Tryba wrote:

Anonymous <an*******@nowhere.invalid> wrote:
[php client]
So what do I have to do to make the login stick? Use a different way to
read the pages? Work with sessions? Cookies?
You should use a different way to request URLs. How are you requesting
them now? fopen? There are many intelligent ways to implement scripts


As I already wrote I'm using file_get_contents(URL).
that pretend to be http clients. curl might be available on your
machine. Else there are classes like snoopy or the httpclient class in
PEAR. These will make handling cookies easier...


What is PEAR?
Jul 17 '05 #5
Kelvin Mackay wrote:
Are you passing the PHPSESSID back to the server in your URLs?


No. I have already thought of that trick but it doesn't work.
Jul 17 '05 #6
Shawn Wilson wrote:
So what do I have to do to make the login stick? Use a different way to
read the pages? Work with sessions? Cookies?


I did this a couple times using fsockopen (though I hear CURL is good),
extracted the cookie information, and resent the cookie info with each request.
Read the manual and especially the comments for fsockopen. You may find you
need to send some other, custom headers (notably user agent) for some sites, as
the default settings may be interpreted as spambots.


Could you please elaborate on that?

What is CURL?

Could you give me some lines of sample code how to request and store a
page in a string variable with fsockopen? Which custom headers do you
think are required and how do I send them?

Thanks.
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: windandwaves | last post by:
Hi Gurus I am basically sorry that I have to bother you about this. I am a PHP beginner and I have been studying sessions and cookies over the last few weeks. I have learned lots, but I am...
2
by: Simon Faulkner | last post by:
I have written a small Python web database which was initially just used in house. Now we want people to be able to read some pages from outside so I need to implement some sort of security. ...
6
by: JJ | last post by:
Hi, I really need to use cookieless ASP sessions with ASP 3 (IIS5) Can I find out the session ID from the first page, then post it or send it with the url to the next page, then at the start...
7
by: Sidd | last post by:
Hi, I tried finding and example of multithreaded client-serve program in python. Can any one please tell me how to write a multithreaded client-server programn in python such that 1.It can handle...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
2
by: Chris Mahoney | last post by:
Hi I'm using several Sessions in my app. When the user has cookies enabled in their browser, everything works fine. But with cookies disabled, only IE seems to remember the sessions. In Firefox...
7
by: Atte André Jensen | last post by:
Hi I'm developing a site where I'd like to store information during a users visit. So far I've been using sessions, but as far as I can tell it's not possible to control for how long a session...
3
by: Marc Gravell | last post by:
Kind of an open question on best-practice for smart-client design. I'd really appreciate anyones views (preferably with reasoning, but I'll take what I get...). Or if anybody has any useful links...
14
by: Zorque | last post by:
Suppose I have an HTML form that sends data to a PHP script, "post" method. If this script generates a page with a link to another script, will the latter script get the former's $_POST data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.