Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




How To Authenticate When Using SimpleXML


I've got an RSS feed I'd like to consume from our Sharepoint server.
When I try:

$xml = simplexml_load_file($url);

I get

failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

This is understandable as I need to specify a username and password to
access the RSS. How can I do this with SimpleXML, or, should I first
call the URL with cURL and work with the stream locally?

I thought there may be some global params I could set for the stream
handling library of PHP.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Use PHP To Authenticate To AD
We use Windows 2000 AD for everything. However, we are also running
XAMPP (basically Apache, MySQL, PHP for windows) on a Windows box for
our Intranet. I have a few applications that need to authenticate via
AD from PHP and every example I see uses the LDAP functions built into
PHP.

I cannot query our AD server via LDAP. If I type
ldap://domaincontroller it fails, so of course, when I try to use the
LDAP function in PHP they fail.

How do I get LDAP running on AD? I'm sure I'm missing something simple,
but I'm very frustrated.

BTW, I've started coding another app that queries AD using ASP and it
is soooo easy it hurts.

Authenticate
I'm setting up an account login: should I use a simple form (user name and password) "embeded" into html verified against a mysql database or should I use the challenge/response scheme (also verified against a mysql database?

Basically, is there any benefit to using challenge/response over merely submitting user name and password (like a search engine)?

Authenticate
Ive started recoding my login/authenticate pages for my game engine, because they were simple.

Upon testing what I have so far I have noticed something that confuses me.

Say these are my login details.

User - Me
Pass- letmein

Now it will log me in when i enter them exactly like that. BUT when i log in using the user me ( no capitol M), it gives me a blank screen and does nothing
The incorrect password or incorrect user name works, it seems to break with case sensitivity issues.

any ideas? Code:

Authenticate Google Accounts Pro
Did any of you ever tried to authenticate Google Accounts pro
grammatically? What I mean is that there are many google services
available which needs to authenticate user accounts first to fetch
data remotely. Now is there any of you who authenticated using PHP?

Http Authenticate Entire Site
we are validating users in several different sections (each section is in it's own directory..ex. the download section is in /downloads) using http authentication. when a user authenticates in one section they can roam freely in that directory without having to authenticate again.

for some reason however, when i change to a different directory and then run a phpinfo(), both $PHP_AUTH_USER and $PHP_AUTH_PW are gone, meaning the user will have to authenticate again.

the user can go back to the first directory again and they are still authenticated within that directory. i would like the users to only have to authenticate once for the entire site, but scince there are areas of the site that do not require validation i don't want to make them authenticate until they have to.

Intranet - Authenticate Using Windows Credentials?
I've just about finished an intranet app that allows users to sign in and out, track their time, show a calendar view of time worked, vacation days used, calculates overtime, etc. My backend is mysql and I'm currently authenticating against a users table that I threw together. The problem with that is another set of u/p's for users. I can import a list of everyone's windows login info, but then it's in two places and I have potential sync issues and maintenance that I'd like to avoid.

My question is this: are there any environment variables that capture the windows login info in PHP (the server will be running on windows, not *nix)? For example, if I login into my workstation as djf / password1, rather than having that information also stored in a mysql table, is there any way to access those values without the user typing them in again? I'm not that familiar with windows environments, but based on the research I've done, using LDAP and Active Directory might be a possibility? I have no idea how to do either.

Http Authenticate Auto Login?
you know the apache built in authenticate boxes? username+password. is it possible to run a php script that can log into that? do I send the username/pass as a post?
is this possible? I've searched everywhere and only found info on making one.

I don't want to make one, I want to log into one via  a php script. reason: dreamhost uses that for the login for the stats page, I want to read the data from the page in a php script, but first I need to log in.

PHP::Auth Requiring Valid Email Address To Authenticate
I am about to implement an authentication system on the site I am
building. I don't care much what users choose for their username and
password, but I want to verify that users have given a valid email
address before allowing them access to restricted content. Will Auth
facilitate the email validation process, or does it only deal with
usernames and passwords?

I don't need to be told in detail how to do all this, but I'd like to
know early if I'm barking up the wrong tree by trying to use Auth with
this intention in mind. If so, is there a better package to use for
authentication that requires a valid email address?

WWW-Authenticate: How To Force Password Login At Every Page Refresh ?
<!--
The following sample should authorize the user to log on the site.
This works once but after refreshing the browser, it does not prompt
again for login until all browser (IE 6) windows are closed and the
same page is opened.
I turned off all caching but still it does cache (as a refresh doen
not promt again).

How can I force the page to prompt for a password at every refresh

-->

<html>
<head>
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<?php

$showall = false;
error_reporting (E_ERROR);

if (($PHP_AUTH_USER != "myname") || ($PHP_AUTH_PW != "mypass"))
{
header('WWW-Authenticate: Basic realm="Secure Login"');
header('HTTP/1.0 401 Unauthorized');
$showall = false;
}
else
{
error_reporting (E_ALL ^ E_NOTICE);
$showall = true;
}

if (!showall) {
echo "access denied";
} else {
?>

................

</head>
<body>

.................

<? } ?>

</body>
</html>

SimpleXML
What, besides the new php 5.0 zip package, do I need to get SimpleXML to
work on my testing server? The docs say to copy libxml2.dll to the system32
directory but I can't find this dll anywhere in the binary package (or
anywhere else for that matter). I'm running IIS 6.0 fwiw.

Using SimpleXML
I have started using SimpleXML and can do most things, but there are a
couple of things that I can't seem to figure out.

Currently, I can:

1. Open & load an XML file
2. Manually parse the XML file
3. Search the XML file using XPath
4. Make changes to existing nodes (values)

However, I can't seem to be able to:

1. Add a new node / element.
2. Save my changes back to the XML file

Am I missing something, or are these things that currently cannot be
done with SimpleXML?

Valid XML For SimpleXML
I'm trying to use SimpleXML but I've run into a conundrum. Every day
an XML file is generated that this script grabs and manipulates. How
can I check that the XML has no problems before creating my
SimpleXMLelement object. Here's what I mean:

// this is the code in question:
$file_topstory = /some/xml/file.xml
$top_story_xml = new SimpleXMLElement($file_topstory, NULL, TRUE);

If the XML doc contains (for example) a URL with an '&' in it then the
script fails. I'd like to do something like this:

if(is_valid_xml($file_topstory)){
$top_story_xml = new SimpleXMLElement($file_topstory, NULL, TRUE);
}else{
// ERROR
}

PHP5 Simplexml
I'm trying to output from an XML string and am having no luck. I'm
using PHP5 here.

If I print_r the array I get all the results plus extra text, but am unable
to extract the individual response. Any pointers appreciated.

Here's the code that shows the results...

$get_all_value = $xmlrpc_resp->value();
$albums_array = php_xmlrpc_decode($get_all_value);
print $albums_array['string'];

Here's the result string that I want to break up ...

xmlrpcval Object
(
[me] => Array
(
[string] =>
<photos page="1" pages="1" perpage="500" total="155">
<photo id="114766115" owner="xxxxxx" secret="xxxxxx" server="50"
title="Water Pump, Bushy Park" ispublic="1" isfriend="0" isfamily="0" />
<photo id="114765757" owner="xxxxxx" secret="xxxxxx" server="36"
title="Deer, Bushy Park" ispublic="1" isfriend="0" isfamily="0" /></photos>

)

[mytype] => 1
[_php_class] =>
)Many thanks

SimpleXML Question
I'm running in to a little issue with SimpleXML, and wondered if
anyone knew if it was normal implementation for SimpleXML, or I'm not
using a correct flag, or even it's a an issue that should be
resolved. I'm actually only just starting to use SimpleXML with any
vigor, so I may well be mistaken about what I think it should do...

Basically, if you take this simple chunk of XML:

Merging XML In PHP Using SimpleXML And DOM
I'm having trouble trying to merge two SimpleXML objects (user preference settings) in PHP.  It should be simple enough - the objects have the same root element, and I simply want to merge at the top child level.  However, the code I'm providing here, while it executes, does not work. At the end of the merge() function, the merged preferences are empty. Code:

Writing To XML Using Either DOM Or SimpleXML
I've been having quite some trouble figuring out specific XML coding in PHP5. I'm trying to edit and remove specific tags in a specific way using DOM (I'd rather use SimpleXML but it seems rather limited on this area). Code:

Parse Xml-rpc Using SimpleXML
I am trying to parse through a XML document...a XML-rpc response to be exact...the good thing is the code is doing as its told. Code:

SimpleXML Catching 404
I'm building a script with the last.fm datafeeds. When a incorrect username is given to the script, the last fm site throws a 404, and results in this PHP error:

Warning: simplexml_load_file(http://ws.audioscrobbler.com/1.0/user/RichardJohn/tasteometer.xml?with=) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /home/richardm/public_html/lastfmcompatibility.php on line 12

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://ws.audioscrobbler.com/1.0/user/RichardJohn/tasteometer.xml?with=" in /home/richardm/public_html/lastfmcompatibility.php on line 12

There was a problem loading the data feed. Is there a way to catch this error and just present a friendly error?

SimpleXML & Google Images
I'm writing a script that would (hopefully) search google images
for whatever, and then return a list of URLs for the image. Right now I
have:

$dom = new DomDocument();

$url = "http://images.google.com/images?q=hello";

$dom->loadHTMLFile($url);

$sxe = simplexml_import_dom($dom);
foreach($sxe->xpath('//img') as $node)
{
echo $node->src;
}

What this is supposed to do (line by line):
Make a new DomDocument
Define $url
load the HTML file from $url
make a simpleXML object from the loaded DOM
go through all the image tags (using a DomNodeList w/ xpath) and print
out the src attribute of the node.

Simplexml + Namespace +attributes
I have an XML file with some elements like those below

<core:District Id="AB01">
<core:Name>NORTH EAST</core:Name>
<core:Association Type="type1">VALUE 1a</core:Association>
<core:Association Type="type2">VALUE 1b</core:Association>
<core:Association Type="type3">VALUE 1c</core:Association>
</core:District>
<core:District Id="AB02">
<core:Name>NORTH WEST</core:Name>
<core:Association Type="type1">VALUE 2a</core:Association>
<core:Association Type="type2">VALUE 2b</core:Association>
<core:Association Type="type3">VALUE 2c</core:Association>
</core:District>

I'm trying to parse it using simplexml

I have:

$districts = $xmlfile->children($core);

foreach ($districts as $key => $value)
{
echo "Name = " . $value->Name . "
";
echo "Region1 = " . $value->Association[0] . "
";
echo "Region2 = " . $value->Association[1] . "
";
echo "Region3 = " . $value->Association[2] . "
";

}

This works fine, but I am unable to access the Id attribute in the
opening District element, i.e. AB01 or AB02.

Would anyone be able to suggest how I might get that value with
simplexml?

SimpleXML Parsing By Attribute Value
I have an existing XML data set and would like to parse it with PHP5 based on the value of an attribute (any attribute!). I don't want to convert all my data from an attribute-heavy structure to a more proper element-based structure if I don't have to because of the javascript I am using on the client side. Listed below is the XML structure and PHP code I have been testing.

My existing data structure looks like this:
<gallery>
<photos>
<photo
path = "sunflower01.jpg"
width = "500"
height = "375"
thumbpath = "sunflower01.jpg"
thumbwidth = "125"
thumbheight = "94">
</photo>
</photos>
</gallery>

The script is here:

<?php
$xml = simplexml_load_file("pictures.xml");
$image = $xml->xpath("/gallery/photos/photo[@path='sunflower01.jpg']");
echo $image[0]->photo@thumbpath;
?>

How To Search Xml W/simplexml Using Xpath()
I've been lookin over some simplexml notes/docs and i havent really found a way to search and return results

example:

<?xml ...?>
<products>
<cat1>
<item>
<name>product 1</name>
<color>blue</color>
</item>
</cat1>
<cat2>
<item>
<name>product 2</name>
<color>blue</color>
</item>
</cat2>
</products>

if the user searches "blue", then i should be able to step through and process the valid <item> structures... same for if they search for "product 1", then just process the one valid structure (including its category)...

Editting XML Attributes With SimpleXML?
Ive been trying to figure out how to edit XML Node Attributes, Can someone point me in the right direction? ....

Unexpected T_OBJECT_OPERATOR -- SimpleXML Error
I'm creating an MLB pool, and I'm making a standings table in my database. I'm grabbing the standings via RSS feed. PHP Code:

Weird Chars When Parsing With SimpleXML
I'm using php-5.0.5-pl3; I've created a collector class which
populates itself with DOM's nodes from every object which needs to
output data. So, at the end of the process, the collector has every
piece of the result in a XML document.

After this, I need to process the XML document according to the user
document request (HTML, XML, Excel, etc.); to accomplish this, I'm
using a SimpleXML to parse every node and reinterpret it.

I've successfully accomplish HTML transformation, but I've trouble
with Excel because some numeric entities aren't translated properly.
For example:

Importación (Importación) is translated to Importación
Acuática (Acuática) is translated to Acuática
España (España) is translated to España
....
and so on.

Is there any function to translate properly the accuted vocals ?



Remove Duplicate Items From A Simplexml Object
$foos = simplexml_load_file("bar.xml");

Lets say bar.xml has 50 entries and lets say 25-50% of those are duplicates. How would I get rid of those. Here is how I'm using it

foreach($foos as $foo){
 echo $foo->entry;}

I don't think that $foos or $foos->entry is an array so array_unique won't work.

Problems Using PEAR HTTP_Request In Combination With SimpleXML
I'm just beginning with PHP and I'm trying to figure out how to handle HTTP Requests/Response with web services such as eBay and PayPal.  In my research I've come across HTTP_Request included with PEAR.  I've gotted it installed and tested successfully with the following:

<?php
require_once "HTTP/Request.php";
$req =& new HTTP_Request("http://www.ebay.com/");
if (!PEAR::isError($req->sendRequest()))
      {
            echo $req->getResponseBody();
      }
?>

That displays ebay's web site when I load the page so it seems that PEAR is working correctly.

I'm trying now to move on and do an actual call to their API.  It's the easiest call you can make with their API and it simply returns the official eBay time.  Here is what I've got:

<?php require_once "HTTP/Request.php";?>

<?php
$eBayAPICallName = "GeteBayOfficialTime";
$APIURL = "https://api.ebay.com/ws/api.dll";
$DevID = "My_Dev_ID_Here";
$AppID = "My_App_ID_Here";
$Cert = "My_Cert_Here";
$AuthToken = "My_Auth_Token_Here";

//eBay GetOfficialTime request
$requestXMLBody = "<?xml version=""1.0"" encoding=""utf-8""?>";
$requestXMLBody .= "<GeteBayOfficialTimeRequest xmlns=""urn:ebay:apis:eBLBaseComponents"">";
$requestXMLBody .= "<RequesterCredentials>";
$requestXMLBody .= "<eBayAuthToken>" . $AuthToken . "</eBayAuthToken>";
$requestXMLBody .= "</RequesterCredentials>";
$requestXMLBody .= "</GeteBayOfficialTimeRequest>";

$req =& new HTTP_Request();
$req -> setURL($APIURL);
$req -> setMethod(HTTP_REQUEST_METHOD_POST);
$req -> addPostData($requestXMLBody);
$req -> addHeader("X-EBAY-API-COMPATIBILITY-LEVEL", "511");
$req -> addHeader("X-EBAY-API-SESSION-CERTIFICATE", $DevID . ";" . $AppID . ";" . $Cert);
$req -> addHeader("X-EBAY-API-DEV-NAME", $DevID);
$req -> addHeader("X-EBAY-API-APP-NAME", $AppID);
$req -> addHeader("X-EBAY-API-CERT-NAME", $Cert);
$req -> addHeader("X-EBAY-API-CALL-NAME", $eBayAPICallName);
$req -> addHeader("X-EBAY-API-SITEID", "0");
$req -> addHeader("X-EBAY-API-DETAIL-LEVEL", "0");
$XMLResponse = simplexml_load_string($req -> sendRequest());
echo $XMLResponse -> asXML();
?>

The idea behind this (from what i can piece together from tutorials and everything I've been studying) is that it constructs the basic XML string to use and uses PEAR's HTTP_Request to send it off.  I'm storing the response in $XMLResponse with the SimpleXML PHP function hoping I could display the XML response in the browser to ensure things are working....but they're not.

When I run this page I get a blank white browser back.  View source has nothing but the empty basic html tags.  All of the headers I've added were taken from working ASP scripts so know those are good (unless I've just done something wrong with syntax there or something). 

I've tested the simplexml stuff successfully using basic XML files located on my disk so I thought I had that setup correctly too.  Obviously something is wrong somewhere, though.

XML File, Character Entities And SimpleXML Parser
I have the following XML file:

<?xml version=1.0'?>
<!DOCTYPE names [
<!ENTITY eacute "(ampersand)#233;">
]>
<site>

<section id='about' name='about'>
</section>

<section id='portfolio' name='portfolio'>
</section>

<section id='resume' name='r&eacute;sum&eacute;'>
</section>

</site>


I parse it with simpleXML, but by the time "resume" (you know-- the kind with e-acute characters) gets to the browser, the entities get mangled. Note that I *am* using the proper "DOCTYPE names" directive at top of the XML file, and I am saving my files as UTF8.

Also note that in the code above, I replaced the ampersand with the word "ampersand" so it wouldn't parse on this message board.

I think I'm missing a part of the big picture here. Any ideas?

Special Characters In XML Files Parsed With SimpleXML
I got a problem; when using php4 parsing xml files i get special characters displayed good. When using the simpleXML class, the special characters stay.

example:

’ shows as ’ insteeds of '

Does anyone know how to fix this?

SimpleXML And Load Php File (Content-type: Text/xml)
I'm taking my first steps with xml and SimpleXML functions.
xml.php (It could be made dynamically with a mysql result I post this snippet for example)

PHP Code xml.php:

<?php
$xmlstr = "<?xml version="1.0" standalone="yes"?>";
$xmlstr .= "<movies>
<movie>Behind the Parser</movie>
</movies>";
header('Content-type: text/xml; charset=utf-8');
echo $xmlstr;
?>

PHP Code loadXml.php:

I've got this nasty error :
Warning: xml.php:2: parser error : Start tag expected, '<' not found in
c:xxxwwwxmlexamplemioplot.php on line 3

Warning: $xmlstr = ""; in c:xxxwwwxmlexampleloadXml.php on line 3

Warning: ^ in c:xxxwwwxmlexampleloadXml.php on line 3
bool(false)

I've got the same error in my web site .

xml.php is a valid xml file, isn't it ?
Therefore I'm wondering why the snippet
doesn't work ?

Simplexml And Attributes With A Namespace In Front. How Do You Getthe Attribute?
Here's a bit of xml code that works.

<?php

$string =
"<?xml version="1.0" standalone="yes"?>
<world>
<people xmlns:ss="http://crap">
<person id="5">John Doe</person>
<person id="2">Susie Q. Public</person>
</people>
</world>";

$xml = simplexml_load_string($string);
print "<pre>";
print_r($xml);
print "</pre>";

foreach($xml->people->person as $p)
foreach($p->attributes() as $a =$b)
{
print "$a =$b<br />";
}

// prints out
// id =5
// id =2
?>

Now what if I change the first person to this
<person ss:id="5">John Doe</person>

Anyone know how to get the id?

This is a question that is pertinent to an excel .xml file as
you'll get lines like this
<Cell ss:Index="3">stuff</Cell>

btw: there is a guide on ibm that tells you how to do this with php
and dom. I'm just wondering if there's a way to do it with simplexml.

Warning: Simplexml_load_file() [function.simplexml-load-file]:
heres the errors:

Warning: simplexml_load_file() [function.simplexml-load-file]: core/combat/magic/Spark.const.xml:4: parser error : Extra content at the end of the document in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481

Warning: simplexml_load_file() [function.simplexml-load-file]: <mastery>Death</mastery> in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481

and heres the .xml document: Code:

[SimpleXML] Assigning Values To Elements Found With XPath
I want to find all elements named "field" in an XML doc and assign a new value to each one. I'd tried something like this:

foreach ($xml->xpath('//field') as &$field)
    $field = $value;

But that doesn't work, because (I think) XPath returns a temporary array, not a reference to an actual element. ("PHP Fatal error:  Cannot create references to elements of a temporary array expression")

Is there a way to assign values to elements located with XPath, or do I just have to iterate over the whole document?

Mail() Won't Work; Server Says "Unable To Authenticate User..."
I am working on a sendmail script using the PHP mail() function.

If I click on the HTML form page from within my hosting control panel (while I'm logged into my hosting account), fill out the form, and then click on the "submit" button the mail sends just fine.

However, if I log out of my control panel and approach the form page, just like a visitor or stranger would do, the PHP mail() function will not send the mail.

If I look inside the "./tmp/mailError.log" file there is the following message:

"Unable to authenticate user. Message not sent."

It appears that the server will not send the mail because there is not any identification for the outgoing mail. I have tried inserting a fourth variable in the PHP mail() function a couple of different ways like so:

Authenticate A User Using Same Password As Linux Password
We're working on an intranet site where we will require user's to only
be able to access their own page in some instances. Rather than
introducing another password to the mix, we were thinking about seeing
if we could use the same credentials (username and password) as their
linux credentials. The web site will be running off of the same machine
that we want to access the credentials on.


Copyright © 2005-08 www.BigResource.com, All rights reserved