php-general Digest 28 Apr 2011 21:12:52 -0000 Issue 7287
Topics (messages 312534 through 312544):
Re: Destroying cookies... not working
312534 by: Geoff Lane
Re: Javascript detection
312535 by: Per Jessen
312542 by: tedd
312544 by: Ashley Sheridan
Nested XInclude in XML
312536 by: nimruhil
Re: Detecting Javascript (was Re: Newsgroup status)
312537 by: Jay Blanchard
Re: Flattery will get you nowhere
312538 by: Marc Guay
312540 by: tedd
Re: refreshing pages in the cache
312539 by: Jim Giner
312541 by: Ross Hansen
Re: How to write a PHP coding to list out all files and directories aslinks to
them?
312543 by: Mitch
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
On Thursday, April 28, 2011, Sean Greenslade wrote:
> On Wed, Apr 27, 2011 at 8:52 PM, Rick Dwyer <[email protected]>
> wrote:
>> The following did the trick... is there any reason I should not use it?
>>
>> $name="mysession";
>> setcookie($name);
>>
>> --Rick
> Only if you're OCD, since the cookie is still technically there, just empty.
> Without setting the expire arg, the browser will keep it until closed.
What happens if you then use isset($_COOKIE['mysession'])? TBH, I
don't know and don't have the time to experiment just now. However,
this should return false if the cookie has been destroyed but if just
set to null or an empty string via Rick's code I suspect it'd return
true.
--
Geoff
--- End Message ---
--- Begin Message ---
tedd wrote:
> As Yogi Berra once said; "It's always hard to predict things
> especially when it deals with the future."
>
He was quoting Niels Bohr:
http://www.quotationspage.com/quote/26159.html
--
Per Jessen, Zürich (10.2°C)
--- End Message ---
--- Begin Message ---
At 9:02 AM +0100 4/28/11, Geoff Lane wrote:
FWIW, it's possible to detect whether or not Javascript is available,
but not AFAICT at 'first contact' because you need the 'first contact'
page to do something to prove that JS is available, from which you can
assume that JS is not should that something not be done. For example,
you can make the link to a page into a form submission - e.g:
<form name='jstest' action='myscript.php' method='post'>
<input type='hidden' name='wehavejs' value=1>
</form>
<a href='myscript.php'
onClick="document.forms['jstest'].submit();return(false);">
Click Here</a>
The form is submitted if the browser has JS and so the hidden input
field is posted. However, if the browser doesn't have JS the default
behaviour occurs when the link is clicked and so the field is not
posted. Hence we can use isset($_POST['wehavejs']) to determine
whether or not the browser has JS capability.
Thanks again,
--
Geoff
Geoff:
You are correct about "first contact" -- you need to launch the
browser to check to see if the browser has javascript enabled.
There's currently no way for the server to see what the user has
selected for their browser before the browser launches.
It is true that the $_SERVER global provides all sorts of information
about the requester and I suppose it could also contain the browser's
javascript configuration, but it doesn't.
However, JavaScript detection doesn't require a user's response, as
you have proposed via a form.
Instead, you can simply add an "onload()" operation to the page and
detect javascript, such as:
http://www.webbytedd.com/b1/ajax-js-dection/
Or do it unobtrusively as I have shown before.
Cheers,
tedd
--
-------
http://sperling.com/
--- End Message ---
--- Begin Message ---
On Thu, 2011-04-28 at 10:17 -0400, tedd wrote:
> At 9:02 AM +0100 4/28/11, Geoff Lane wrote:
> >
> >FWIW, it's possible to detect whether or not Javascript is available,
> >but not AFAICT at 'first contact' because you need the 'first contact'
> >page to do something to prove that JS is available, from which you can
> >assume that JS is not should that something not be done. For example,
> >you can make the link to a page into a form submission - e.g:
> >
> > <form name='jstest' action='myscript.php' method='post'>
> > <input type='hidden' name='wehavejs' value=1>
> > </form>
> > <a href='myscript.php'
> >onClick="document.forms['jstest'].submit();return(false);">
> > Click Here</a>
> >
> >The form is submitted if the browser has JS and so the hidden input
> >field is posted. However, if the browser doesn't have JS the default
> >behaviour occurs when the link is clicked and so the field is not
> >posted. Hence we can use isset($_POST['wehavejs']) to determine
> >whether or not the browser has JS capability.
> >
> >Thanks again,
> >
> >--
> >Geoff
>
> Geoff:
>
> You are correct about "first contact" -- you need to launch the
> browser to check to see if the browser has javascript enabled.
> There's currently no way for the server to see what the user has
> selected for their browser before the browser launches.
>
> It is true that the $_SERVER global provides all sorts of information
> about the requester and I suppose it could also contain the browser's
> javascript configuration, but it doesn't.
>
> However, JavaScript detection doesn't require a user's response, as
> you have proposed via a form.
>
> Instead, you can simply add an "onload()" operation to the page and
> detect javascript, such as:
>
> http://www.webbytedd.com/b1/ajax-js-dection/
>
> Or do it unobtrusively as I have shown before.
>
> Cheers,
>
> tedd
>
>
> --
> -------
> http://sperling.com/
>
I'm not sure if my earlier reply got through, but here it is again (or
at least the general gist of it)
There are ways you can detect if a browser is *capable* of running
Javascript using $_SERVER['HTTP_USER_AGENT'] and an up-to-date
browscap.ini file. This will allow you to check if the browser indicated
by the user agent. However, there are caveats to this approach:
* A browser might be sending the wrong user agent string, there
are plenty of plugins which do this
* A browser might be capable of running Javascript but might have
it turned off or otherwise blocked
* Filtering may be going on by a proxy server or firewall that
strips out Javascript (sounds stupid but happens in paranoid
businesses)
Like everyone has mentioned thus far, it's better to use progressive
enhancement or try to avoid relying on Javascript at all. Even a website
as complex as Facebook allows users to go on it without needing a
browser that runs Javascript. Something as complex as Google Docs has a
very clear need for Javascript though, so you wouldn't expect that to
work without it.
Lastly, if you're creating the website for a government or business, you
really need to make it work without Javascript, as a lot of countries
make it illegal to discriminate against a disability, which you would be
doing if you made a site that was unusable without Javascript. After
all, there are many speech and Braille browsers out there that can't
take advantage of Javascript, and a lot of Javascript apps which require
mouse interaction to run (mouseover/hover events, etc)
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
I need to insert a content of an XML node into text of another XML element in
the same document. I use XInclude for this purpose. For example:
<?xml version="1.0" encoding="UTF-8"?>
<pool xmlns:xi="http://www.w3.org/2001/XInclude">
<query name="foo">
<sql db="oracle">Lorem ipsum</sql>
<sql db="mysql">sed do eiusmod tempor</sql>
</query>
<query name="bar">
<sql db="oracle"><xi:include
xpointer="xpointer(//query[@name='foo']/sql[@db='oracle']/text( ))" /> dolor
sit amet,</sql>
<sql db="mysql"><xi:include
xpointer="xpointer(//query[@name='bar']/sql[@db='oracle']/text( ))" />
consectetur adipisicing elit</sql>
</query>
</pool>
It works well when a node what content is inserted from contains only text
(e.g., first sql node in the "foo" query in example above). So I have "Lorem
ipsum dolor sit amet," in the first sql node in the "bar" query after parsing.
That's what I want.
But I have a problem when I try to insert a content of a node containing
xi:include. For example I have " dolor sit amet, consectetur adipisicing elit"
instead of "Lorem ipsum dolor sit amet, consectetur adipisicing elit" in the
second sql node within the "bar" query. When I use xpointer without text( ) at
end I have the following as content of the second sql node within the "bar"
query:
<sql xmlns:xi="http://www.w3.org/2001/XInclude" db="oracle">Lorem ipsum dolor
sit amet,</sql> consectetur adipisicing elit
It's almost correct, but here are undesirable sql tags. I've tried to use
range-inside() function of xpointer in this way:
..
<sql db="mysql"><xi:include
xpointer="xpointer(range-inside(//query[@name='bar']/sql[@db='oracle']))" />
consectetur adipisicing elit</sql>
..
Content of the second sql node in the "bar" query has been changed to this:
<sql db="oracle"/> consectetur adipisicing elit
As you can see content of included sql node entirely gone.
What's wrong? Am I using XInclude or XPointer in the wrong way? Or may be PHP
XML parser (I use DOMDocument for working with this XML document) isn't
entirely conformed with XInclude or XPointer standard?
--- End Message ---
--- Begin Message ---
[snip]
this isn't possible
[/snip]
Welcome to the world of progressive enhancement!
http://www.alistapart.com/articles/understandingprogressiveenhancement/
--- End Message ---
--- Begin Message ---
> What are you are looking for?
I'm working on a new form and after reading a few threads on this list
since I've subscribed I realized that validating input is a weakness
of mine. I figured you would have an example online somewhere covered
some of the main security concerns.
Marc
--- End Message ---
--- Begin Message ---
At 9:11 AM -0400 4/28/11, Marc Guay wrote:
> What are you are looking for?
I'm working on a new form and after reading a few threads on this list
since I've subscribed I realized that validating input is a weakness
of mine. I figured you would have an example online somewhere covered
some of the main security concerns.
Marc
Marc:
It's a larger concern than an on-line example somewhere would show.
I did a presentation on PHP security for my students, which much of
it I took from "Essential PHP Security" by Chris Shiflett -- see:
http://phpsecurity.org/
The book is inexpensive enough -- I suggest that IF you are
interested (as you should be if you're a developer), then buy it,
read it, and practice it.
Cheers,
tedd
--
-------
http://sperling.com/
--- End Message ---
--- Begin Message ---
Yes - that seems to be the trick! Thank you very much for your tip AND
your patience. :)
You've made an old programmer's day!
--- End Message ---
--- Begin Message ---
Your welcome,
I am glad that it works and is doing what your after.
----------------------------------------
> To: [email protected]
> From: [email protected]
> Date: Thu, 28 Apr 2011 09:19:58 -0400
> Subject: Re: [PHP] refreshing pages in the cache
>
> Yes - that seems to be the trick! Thank you very much for your tip AND
> your patience. :)
>
> You've made an old programmer's day!
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
On 4/14/2011 6:16 PM, Mikhail S wrote:
How to write a PHP coding to list out all files and directories as links to
them?
This is somewhat similar to some index pages. When new file or folder is
added to the directory, HTML page should display the newly created
file/folder together with previous ones after it is being refreshed. (prefer
in alphabatical order)
How to achieve this sort of functionality in PHP? Please provide sample
coding as well. (and any references)
Thanks.
--
Mike
http://jp.shopsloop.com/
OK, maybe not the most elegant ... but it works for my purposes ... and
it was my first attempt at these directory functions. You can navigate
up and down the directory hierarchy. It flags files older than 1 year
for potential cleanup.
Hope it gives you some ideas and a place to start...
Mitch
#! /usr/bin/php4
<html>
<head>
<title>Diskspace Analyzer</title>
<?php
foreach ($_REQUEST as $key=>$value){
$$key = $value;
}
?>
</head>
<body>
<form name="form1" method="POST" action="<?php $PHP_SELF ?>">
<p align="center"><font color="#FF0000" size="+2">Enter Directory Name
Here</font></p>
<p align="center">
<input name="dName" type="text" id="dName" value="<?php $dName ?>"
size="50" maxlength="256">
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<br>
<?php
if (isset($dName) && is_dir($dName)){
print("<hr>\n");
print("<font size=\"+2\"><strong>$dName Directory
Information</strong></font><br> \n");
print("<font color=\"yellow\"><strong>Highlighted</strong></font> files
are older than 1 year and candidates for cleanup<br> \n");
print("<table border=\"1\" bordercolor=\"gray\" cellspacing=\"0\"
cellpadding=\"5\">\n");
print("<th bgcolor=\"black\"><font color=\"white\">File
Name</font></th><th bgcolor=\"black\"><font color=\"white\">File
Size</font></th><th bgcolor=\"black\"><font color=\"white\">File
Date</font></th>\n");
$d = @dir(trim($dName));
while ($entry = @$d->read()){
$total++;
$fileExt = explode(".", $entry);
if(is_dir($d->path . "/" . $entry)){
if($fileExt[0] ==""){
$fileExt[1] = "SysDirectories";
} else {
$fileExt[1] = "Directories";
}
$dirSize = filesize($d->path . "/" . $entry);
$totaldirSize += $dirSize;
$dirList[$entry] = $dirSize;
} else {
$fileExt[1] = "Files";
$fileStats = @stat($d->path . "/" . $entry);
$fileSize = $fileStats[7];
$totalSize += $fileSize;
$currDate = getdate();
$fdDay = date("z", $fileStats[10]);
$fdYear = date("Y", $fileStats[10]);
$ckDay = $currDate["yday"];
$ckYear = ($currDate["year"] - 1);
if (($fdYear < $ckYear) || (($fdYear == $ckYear) &&
($fdDay <= $ckDay))){
$highlight = "yellow";
$totalSavings += $fileStats[7];
} else {
$highlight = "white";
}
print("\t<tr>\n");
print("\t\t<td bgcolor=\"$highlight\">$entry</td><td
bgcolor=\"$highlight\" align=\"right\">$fileSize</td><td align=\"right\"
bgcolor=\"$highlight\">");
printf("%s", date("m/d/Y", $fileStats[10]));
print("</td>\n");
print("\t</tr>\n");
}
$fileTypes[$fileExt[1]]++;
}
print("\t<tr>\n");
print("\t\t<td bgcolor=\"gray\"><strong>Total Bytes in
Files</strong></td><td align=\"right\"
bgcolor=\"gray\"><strong>$totalSize</strong></td><td align=\"right\"
bgcolor=\"gray\">");
if ($totalSavings > 0){
print("<strong>Potential Savings: $totalSavings</strong>");
}
print("</td>\n");
print("\t</tr>\n");
print("</table><br> \n");
if(count($dirList) > 1){
ksort($dirList);
print("<table border=\"1\" bordercolor=\"gray\"
cellspacing=\"0\" cellpadding=\"5\">\n");
print("<th bgcolor=\"black\"><font
color=\"white\">Directories</font></th>\n");
foreach ($dirList as $key=>$value){
print("\t<tr>\n");
if ($key == "."){
print("\t\t<td>$key (Current)</td>\n");
} elseif ($key == ".."){
$truncPoint = strrpos($dName, "/");
$parentDir = substr($dName, 0, $truncPoint);
if ($parentDir == ""){
$parentDir = "/";
}
print("\t\t<td><a href=\"" . $PHP_SELF .
"?dName=" . $parentDir . "&Submit=Submit\">$key</a> (Parent)</td>\n");
} else {
print("\t\t<td><a href=\"" . $PHP_SELF .
"?dName=" . $dName . "/" . $key . "&Submit=Submit\">$key</a></td>\n");
}
print("\t</tr>\n");
}
print("\t<tr>\n");
print("\t\t<td bgcolor=\"gray\"><strong>Total Bytes
($totaldirSize)</strong></td>\n");
print("\t</tr>\n");
print("</table><br> \n");
}
ksort($fileTypes);
arsort($fileTypes);
print("<ul>\n");
foreach ($fileTypes as $key=>$value){
print("<li>$key ($value)\n");
};
print("</ul>\n");
print("Total Objects in $filespec branch: $total<br>\n");
print("Total Bytes in $filespec branch: " . ($totalSize +
$totaldirSize) . "<br> \n");
} else {
Print ("<hr><br><h2><font color=\"#ff0000\">Requested Directory (
$dName ) was not found</font></h2>\n");
} // end if (isset(...
print ("<br><hr>\n");
?>
</body>
</html>
--- End Message ---