FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PHP Sessions and XML
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
PHP Sessions and XML [message #178342] Thu, 07 June 2012 19:27 Go to next message
Jim Higgins is currently offline  Jim Higgins
Messages: 20
Registered: November 2010
Karma: 0
Junior Member
Could someone point me toward a very simple bare bones example of a
PHP script for connecting to a server external to the one running the
PHP script and accepting the small XML file that server will return?
And maybe give me a few PHP keywords I can study for parsing that XML
file?

The XML file will contain a Session ID. So a few PHP keywords related
to initiating a PHP session using that Session ID would be really
helpful.

Thank you.
Re: PHP Sessions and XML [message #178343 is a reply to message #178342] Thu, 07 June 2012 20:04 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/7/2012 3:27 PM, Jim Higgins wrote:
>
> Could someone point me toward a very simple bare bones example of a
> PHP script for connecting to a server external to the one running the
> PHP script and accepting the small XML file that server will return?
> And maybe give me a few PHP keywords I can study for parsing that XML
> file?
>
> The XML file will contain a Session ID. So a few PHP keywords related
> to initiating a PHP session using that Session ID would be really
> helpful.
>
> Thank you.

These are pretty broad questions, so it's almost impossible to answer
them exactly.

Some hints - for fetching the page, the simplest way is to just fetch
the URL using the file functions. However, your server would have to be
configured to allow this (allow_url_fopen set to ON). Also, while this
is a simple interface, it is pretty much limited to opening a file for
read only - no cookies, etc.

A more versatile (but a bit more complicated) way is to fetch the url
with the curl functions. Not hard once you've done it a couple of
times, but there are a number of options.

Once you have the file, if it's a well-formed XML file you can probably
use the SimpleXML functions to process it. Again, this is somewhat
limited, but relatively easy to use. Another way which is more
versatile (and handles non-well-formed documents better) is the DOM
classes.

For handling the session - impossible to tell from what you're asking.
It depends a lot on whether the session id is passed in the file or the
URL (and you have to pass it back) or in a cookie (in which case you
must use the cURL function). But if you're only fetching one file, you
shouldn't have to worry about a session id - it's a single request.

Any more detail would be pure conjecture, and would very probably steer
you along the wrong path.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PHP Sessions and XML [message #178344 is a reply to message #178343] Fri, 08 June 2012 01:33 Go to previous messageGo to next message
Jim Higgins is currently offline  Jim Higgins
Messages: 20
Registered: November 2010
Karma: 0
Junior Member
On Thu, 07 Jun 2012 16:04:04 -0400, Jerry Stuckle
<jstucklex(at)attglobal(dot)net> wrote:

> On 6/7/2012 3:27 PM, Jim Higgins wrote:
>>
>> Could someone point me toward a very simple bare bones example of a
>> PHP script for connecting to a server external to the one running the
>> PHP script and accepting the small XML file that server will return?
>> And maybe give me a few PHP keywords I can study for parsing that XML
>> file?
>>
>> The XML file will contain a Session ID. So a few PHP keywords related
>> to initiating a PHP session using that Session ID would be really
>> helpful.
>>
>> Thank you.
>
> These are pretty broad questions, so it's almost impossible to answer
> them exactly.
>
> Some hints - for fetching the page, the simplest way is to just fetch
> the URL using the file functions. However, your server would have to be
> configured to allow this (allow_url_fopen set to ON). Also, while this
> is a simple interface, it is pretty much limited to opening a file for
> read only - no cookies, etc.
>
> A more versatile (but a bit more complicated) way is to fetch the url
> with the curl functions. Not hard once you've done it a couple of
> times, but there are a number of options.
>
> Once you have the file, if it's a well-formed XML file you can probably
> use the SimpleXML functions to process it. Again, this is somewhat
> limited, but relatively easy to use. Another way which is more
> versatile (and handles non-well-formed documents better) is the DOM
> classes.
>
> For handling the session - impossible to tell from what you're asking.
> It depends a lot on whether the session id is passed in the file or the
> URL (and you have to pass it back) or in a cookie (in which case you
> must use the cURL function). But if you're only fetching one file, you
> shouldn't have to worry about a session id - it's a single request.
>
> Any more detail would be pure conjecture, and would very probably steer
> you along the wrong path.

Thank you Jerry. It's supposedly a well formed XML file. And just
the words "DOM classes" scares me. ;-)

But in any case you've given me some things to look into and after
that if I haven't figured it out I'll at least be able to ask a more
focused question.

Thanks again.
Re: PHP Sessions and XML [message #178345 is a reply to message #178344] Fri, 08 June 2012 01:38 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/7/2012 9:33 PM, Jim Higgins wrote:
> On Thu, 07 Jun 2012 16:04:04 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)net> wrote:
>
>> On 6/7/2012 3:27 PM, Jim Higgins wrote:
>>>
>>> Could someone point me toward a very simple bare bones example of a
>>> PHP script for connecting to a server external to the one running the
>>> PHP script and accepting the small XML file that server will return?
>>> And maybe give me a few PHP keywords I can study for parsing that XML
>>> file?
>>>
>>> The XML file will contain a Session ID. So a few PHP keywords related
>>> to initiating a PHP session using that Session ID would be really
>>> helpful.
>>>
>>> Thank you.
>>
>> These are pretty broad questions, so it's almost impossible to answer
>> them exactly.
>>
>> Some hints - for fetching the page, the simplest way is to just fetch
>> the URL using the file functions. However, your server would have to be
>> configured to allow this (allow_url_fopen set to ON). Also, while this
>> is a simple interface, it is pretty much limited to opening a file for
>> read only - no cookies, etc.
>>
>> A more versatile (but a bit more complicated) way is to fetch the url
>> with the curl functions. Not hard once you've done it a couple of
>> times, but there are a number of options.
>>
>> Once you have the file, if it's a well-formed XML file you can probably
>> use the SimpleXML functions to process it. Again, this is somewhat
>> limited, but relatively easy to use. Another way which is more
>> versatile (and handles non-well-formed documents better) is the DOM
>> classes.
>>
>> For handling the session - impossible to tell from what you're asking.
>> It depends a lot on whether the session id is passed in the file or the
>> URL (and you have to pass it back) or in a cookie (in which case you
>> must use the cURL function). But if you're only fetching one file, you
>> shouldn't have to worry about a session id - it's a single request.
>>
>> Any more detail would be pure conjecture, and would very probably steer
>> you along the wrong path.
>
> Thank you Jerry. It's supposedly a well formed XML file. And just
> the words "DOM classes" scares me. ;-)
>
> But in any case you've given me some things to look into and after
> that if I haven't figured it out I'll at least be able to ask a more
> focused question.
>
> Thanks again.

Ah, the DOM Classes aren't THAT bad! They are just a bit more
complicated than SimpleXML - but provide more functionality.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: PHP Sessions and XML [message #178346 is a reply to message #178345] Fri, 08 June 2012 04:10 Go to previous messageGo to next message
Mr. B-o-B is currently offline  Mr. B-o-B
Messages: 42
Registered: April 2011
Karma: 0
Member
Jerry Stuckle cried from the depths of the abyss...

>> Thank you Jerry. It's supposedly a well formed XML file. And just
>> the words "DOM classes" scares me. ;-)
>>
>
> Ah, the DOM Classes aren't THAT bad! They are just a bit more complicated
> than SimpleXML - but provide more functionality.

I completely agree with Jerry one this one. DOM is the way to go.
Re: PHP Sessions and XML [message #178347 is a reply to message #178342] Fri, 08 June 2012 09:49 Go to previous messageGo to next message
Jonathan Stein is currently offline  Jonathan Stein
Messages: 43
Registered: September 2010
Karma: 0
Member
Den 07-06-2012 21:27, Jim Higgins skrev:

> The XML file will contain a Session ID. So a few PHP keywords related
> to initiating a PHP session using that Session ID would be really
> helpful.

You must pass the session ID in a cookie (normally the cookie name is
PHPSESSID).

Take a look at
http://www.php.net/manual/en/function.file-get-contents.php - especially
the "context" parameter.

You can find an example of a context with a cookie at
http://www.php.net/manual/en/function.stream-context-create.php

Your code could be something like this:

$context = array(/* set the cookie here */);
$xml = file_get_contents('http://example.com/path/to/file', false,
$context);
$data = new SimpleXMLElement($xml);
print_r($data); // Look what we got...

Regards

Jonathan
Re: PHP Sessions and XML [message #178348 is a reply to message #178347] Fri, 08 June 2012 11:32 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/8/2012 5:49 AM, Jonathan Stein wrote:
> Den 07-06-2012 21:27, Jim Higgins skrev:
>
>> The XML file will contain a Session ID. So a few PHP keywords related
>> to initiating a PHP session using that Session ID would be really
>> helpful.
>
> You must pass the session ID in a cookie (normally the cookie name is
> PHPSESSID).
>
> Take a look at
> http://www.php.net/manual/en/function.file-get-contents.php - especially
> the "context" parameter.
>
> You can find an example of a context with a cookie at
> http://www.php.net/manual/en/function.stream-context-create.php
>
> Your code could be something like this:
>
> $context = array(/* set the cookie here */);
> $xml = file_get_contents('http://example.com/path/to/file', false,
> $context);
> $data = new SimpleXMLElement($xml);
> print_r($data); // Look what we got...
>
> Regards
>
> Jonathan

Not necessarily. It all depends on how the server is configured. I've
seen some which only pass it as a $_POST value in an XML form, and not
call it PHPSESSID.

It all depends on what's on the other end.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: sessions causing refreshing not to work
Next Topic: Query about WWW-Authenticate: Basic and bad UserID/Password recovery
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 12 20:33:06 GMT 2024

Total time taken to generate the page: 0.16380 seconds