php-general Digest 28 May 2008 06:16:12 -0000 Issue 5483
Topics (messages 274749 through 274757):
Re: Header Redirect
274749 by: Robert Cummings
274750 by: Stut
274752 by: Stut
looking a regular expresion
274751 by: Manuel Pérez López
Re: scanned in & manipulate to a pdf
274753 by: Christian Flickinger
274754 by: Christian Flickinger
PEAR_Exception & PEAR_Error
274755 by: Al
read xml files with namespaces
274756 by: Selwyn Polit
Restricting access to a file
274757 by: John Comerford
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 Tue, 2008-05-27 at 18:04 +0100, Stut wrote:
> On 27 May 2008, at 17:54, Robert Cummings wrote:
> > On Tue, 2008-05-27 at 17:10 +0100, Stut wrote:
> >> On 27 May 2008, at 17:06, Yui Hiroaki wrote:
> >>> I would like to have some question.
> >>>
> >>> For example,
> >>> I am in http://example.com/?12324242
> >>>
> >>> I would like to REDIRECT from http://example.com/?1312323232
> >>> to http://example.com/
> >>>
> >>> I can REDIRECT from http://example.com/index.php to http://example.com
> >>>
> >>>
> >>> Please do tell me how I can redirect!
> >>>
> >>>
> >>> This is the sample what I test below!
> >>>
> >>> <?php
> >>> if ($_SERVER['REQUEST_URI'] == '/index.php') {
> >>> header("HTTP/1.1 301 Moved Permanently");
> >>> header("Location: http:///example.com/");
> >>> exit();
> >>> }
> >>> ?>
> >>
> >> 1) Why? Redirects should be avoided where possible for performance
> >> reasons.
> >
> > Didn't this topic get covered several months back. I always do
> > redirects
> > so as not to bugger browser history, titles, indexing, etc. If someone
> > requests a page and they need to be logged in, I redirect to the login
> > page, I never just present the login page... that's just incorrect
> > from
>
> Personally I tend to only use redirects when a form handler has done
> it's job to avoid evil messages when the user hits back. However, I
> have used both redirected and non-redirected login workflows in the
> past for various reasons, and I don't believe there is a "standard"
> way to do it. It depends on how the site will be used and by whom.
>
> > a hierarchical and semantic point of view. Similarly, if I'm doing 404
> > handling with fuzzy request sniffing to determine what was actually
> > requested, I again perform a redirect once I've ascertained what was
> > probably desired. If you don't, then Google and other search engines
> > will index these malformed URLs instead of the correct URL.
>
> The correct response to a 404 page is 404. No arguments. If you
> redirect missing pages then your site effectively contains an infinite
> number of pages. By all means display a useful page when you return
> your 404 but not marking it as a missing page does little if anything
> for your SEO rank and absolutely nothing for your users.
404 "Not Found", but it was found, but it's not where you asked for it,
it's over there... we've permanently moved it from here to there (even
if only virtually)... let's redirect you to the correct location. Since
you perform a redirect to the correct location, the content is
appropriately indexed where it actually exists. If you return a 404
status I'm pretty sure Google discards the content.
> IMHO if you're going to use a semantic argument to defend one point
> you need to carry that attitude throughout.
My semantic argument is still intact. If I found it, then it's not
deserving of "404 Not Found" status. Sure it may not be at the requested
location, but that's what the moved status is for.
Here's a physical world analogy. Walk into a hardware store ask for
object X. If they have it they will tell you. If they don't then either
they will say, "Sorry, we don't have that. I don't have a clue where you
can get it", or if they do know (and want to help) they'll say "It's
over there at Rob's Hardware Store". What they almost certainly won't
say is hang on, then run over to Rob's hardware Store, buy item X, come
back and try to sell it to you. Almost certainly, but who knows, people
do weird things sometimes :)
So here's something else since you played the performance card. Click on
the following link and tell me where you end up when not already logged
in:
http://mail.google.com/mail/
I'm sure Google had a good reason for that behaviour, as in it's follows
more correctly the standard expected request behaviour, and I'm sure
they get a LOT of hits ;)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
On 27 May 2008, at 18:58, elk dolk wrote:
What about using .htaccess for redirection for example, to redirect
a single page:
Redirect 301 /oldpage.html http://www.example.com/newpage.html
I'm assuming the OP is actually doing something with that number
before throwing it away. If not then the whole thing becomes a bit
pointless.
-Stut
--
http://stut.net/
Stut <[EMAIL PROTECTED]> wrote: CC: PHP General List <[EMAIL PROTECTED]
>
From: Stut <[EMAIL PROTECTED]>
To: Robert Cummings <[EMAIL PROTECTED]>
Date: Tue, 27 May 2008 18:04:02 +0100
Subject: Re: [PHP] Header Redirect
On 27 May 2008, at 17:54, Robert Cummings wrote:
On Tue, 2008-05-27 at 17:10 +0100, Stut wrote:
On 27 May 2008, at 17:06, Yui Hiroaki wrote:
I would like to have some question.
For example,
I am in http://example.com/?12324242
I would like to REDIRECT from http://example.com/?1312323232
to http://example.com/
I can REDIRECT from http://example.com/index.php to http://example.com
Please do tell me how I can redirect!
This is the sample what I test below!
if ($_SERVER['REQUEST_URI'] == '/index.php') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http:///example.com/");
exit();
}
?>
1) Why? Redirects should be avoided where possible for performance
reasons.
Didn't this topic get covered several months back. I always do
redirects
so as not to bugger browser history, titles, indexing, etc. If
someone
requests a page and they need to be logged in, I redirect to the
login
page, I never just present the login page... that's just incorrect
from
Personally I tend to only use redirects when a form handler has done
it's job to avoid evil messages when the user hits back. However, I
have used both redirected and non-redirected login workflows in the
past for various reasons, and I don't believe there is a "standard"
way to do it. It depends on how the site will be used and by whom.
a hierarchical and semantic point of view. Similarly, if I'm doing
404
handling with fuzzy request sniffing to determine what was actually
requested, I again perform a redirect once I've ascertained what was
probably desired. If you don't, then Google and other search engines
will index these malformed URLs instead of the correct URL.
The correct response to a 404 page is 404. No arguments. If you
redirect missing pages then your site effectively contains an infinite
number of pages. By all means display a useful page when you return
your 404 but not marking it as a missing page does little if anything
for your SEO rank and absolutely nothing for your users.
IMHO if you're going to use a semantic argument to defend one point
you need to carry that attitude throughout.
-Stut
--
http://stut.net/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
On 27 May 2008, at 19:18, Robert Cummings wrote:
On Tue, 2008-05-27 at 18:04 +0100, Stut wrote:
On 27 May 2008, at 17:54, Robert Cummings wrote:
On Tue, 2008-05-27 at 17:10 +0100, Stut wrote:
On 27 May 2008, at 17:06, Yui Hiroaki wrote:
I would like to have some question.
For example,
I am in http://example.com/?12324242
I would like to REDIRECT from http://example.com/?1312323232
to http://example.com/
I can REDIRECT from http://example.com/index.php to http://example.com
Please do tell me how I can redirect!
This is the sample what I test below!
<?php
if ($_SERVER['REQUEST_URI'] == '/index.php') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http:///example.com/");
exit();
}
?>
1) Why? Redirects should be avoided where possible for performance
reasons.
Didn't this topic get covered several months back. I always do
redirects
so as not to bugger browser history, titles, indexing, etc. If
someone
requests a page and they need to be logged in, I redirect to the
login
page, I never just present the login page... that's just incorrect
from
Personally I tend to only use redirects when a form handler has done
it's job to avoid evil messages when the user hits back. However, I
have used both redirected and non-redirected login workflows in the
past for various reasons, and I don't believe there is a "standard"
way to do it. It depends on how the site will be used and by whom.
a hierarchical and semantic point of view. Similarly, if I'm doing
404
handling with fuzzy request sniffing to determine what was actually
requested, I again perform a redirect once I've ascertained what was
probably desired. If you don't, then Google and other search engines
will index these malformed URLs instead of the correct URL.
The correct response to a 404 page is 404. No arguments. If you
redirect missing pages then your site effectively contains an
infinite
number of pages. By all means display a useful page when you return
your 404 but not marking it as a missing page does little if anything
for your SEO rank and absolutely nothing for your users.
404 "Not Found", but it was found, but it's not where you asked for
it,
it's over there... we've permanently moved it from here to there (even
if only virtually)... let's redirect you to the correct location.
Since
you perform a redirect to the correct location, the content is
appropriately indexed where it actually exists. If you return a 404
status I'm pretty sure Google discards the content.
If you can successfully fulfil the request then it's not a 404, but I
would question why you're getting requests for URLs that don't exist
but that you can accurately service. If you're using the URL as a
search field then your site truly has no missing pages.
However, in that case it's unlikely you'll be redirecting since for a
lot of queries you'll end up with multiple results meaning you're not
accurately fulfilling the request unless there's only one result from
the search. In that case I would agree that a redirect is the done
thing - except where the user got there by doing a search, which is
where things get cloudy as some would say it's appropriate to show
search results since that's the reasonable user expectation, and
others would say it should redirect to the single result - where I'd
come down on that would depend on the content and average user profile.
*breath!*
If you return a 404 Google does indeed discard the content - that's
the logical thing for it to do. 301's allow it to reduce the URLs
used to access your site to a core set of "real" content. Given that,
I agree to your premise that if you can successfully fulfil the
request by redirecting then you should, but only if it's an accurate
response to the request and not a "best guess". Best guesses should be
presented to the user (and Google) as a page suggesting content and
providing other ways to find it if your suggestion is not correct.
I'm starting to ramble so I'll stop here. I hope the point I'm making
is clear in there somewhere.
IMHO if you're going to use a semantic argument to defend one point
you need to carry that attitude throughout.
My semantic argument is still intact. If I found it, then it's not
deserving of "404 Not Found" status. Sure it may not be at the
requested
location, but that's what the moved status is for.
The 301 status code was created so web developers can re-organise
their websites without adversely affecting the user experience. A side
effect of this is that search engines also use them to keep their
index up to date without affecting the sites ranking.
Here's a physical world analogy. Walk into a hardware store ask for
object X. If they have it they will tell you. If they don't then
either
they will say, "Sorry, we don't have that. I don't have a clue where
you
can get it", or if they do know (and want to help) they'll say "It's
over there at Rob's Hardware Store". What they almost certainly won't
say is hang on, then run over to Rob's hardware Store, buy item X,
come
back and try to sell it to you. Almost certainly, but who knows,
people
do weird things sometimes :)
Taking that analogy a step further, the original hardware store is
unlikely to pick you up and physically take you to Rob's Hardware
Store. In fact you said it... [they'll say "It's over there]... which
in web terms would be a page saying "we couldn't find what you were
looking for where you were looking, but we found it over there".
That's what I'm advocating.
So here's something else since you played the performance card.
Click on
the following link and tell me where you end up when not already
logged
in:
http://mail.google.com/mail/
I'm sure Google had a good reason for that behaviour, as in it's
follows
more correctly the standard expected request behaviour, and I'm sure
they get a LOT of hits ;)
First off I really do wish people would get it out of their heads that
just because a company such as Google does something it's the best or
right way to do it. Secondly there are two separate scenario's that
are being mixed up.
Scenario 1 is redirecting when someone comes into your site from an
incorrect URL. Whether that incorrect URL is incorrect by design or
not is beside the point. For the purposes of bookmarking and search
engine friendliness the logical thing to do here is to redirect to the
correct URL with a 301 status code. As for the Gmail example you cite,
Google uses a single sign-on for all of its services, which is a
different kettle of fish. IOW it was a bad example. They redirect
because the sign-on functionality does not exist within the Gmail app,
it's external (ok, same root domain but you know what I mean).
Scenario 2 is redirecting within the same website. In the case of the
OP he's getting a request for the index page with some info in the
query string. He then wants to redirect to the same page but without
the query string. Let's assume the ID is an affiliate ID and he wants
to get rid of it to have a clean URL for people to bookmark. I can
kinda understand that, and it would come under Scenario 1.
However, the scenario in question is login which land squarely in
scenario 2. I mainly work on a site where 90% of it is accessible
anonymously. When you hit something that requires you to login it
redirects you to the login page. It does this because session handling
is done on a separate cluster. If that was not the case then I'd be
showing the login form inline because it saves the server an HTTP
request, PHP processing and potentially DB access... IOW server-side
resources. That may not be a big deal on small sites but on large busy
sites it could be fatal.
Let's take a step back and look at the HTTP spec. In the good old days
all authenticated access was done through HTTP authentication. If a
resource requiring a login was accessed anonymously the server returns
a status code indicating that a username and password was required.
Note no redirects, just a login form being displayed (albeit by the
browser rather than via HTML).
Ok, having typed that I'm not sure it's relevant, but I can't be arsed
to delete it. My main point is that internal redirects are a waste of
resources if they can be avoided and don't, as far as I can tell,
provide any tangible benefit to anyone.
Feel free to correct me if you think I'm wrong.
-Stut
--
http://stut.net/
--- End Message ---
--- Begin Message ---
Hello:
I need to include a pair of negations with two complete word into a regular
expresion for preg_replace. How to do this?
I want to replace "I want to be a SUN and a SIR" with "FRIKI FRIKI FRIKI
FRIKI FRIKI SUN FRIKI FRIKI SIR"
ie. the words are: SUN and SIR. And the replacement word is: FRIKI
$st = preg_replace ("\b([^S][^U][^N])|([^S][^I][^R]\b)", "FRIKI",$st);
This does not match
Anyone hep me?
Thanks
--- End Message ---
--- Begin Message ---
If that is the case, then the task is admittedly harder, but not impossible
;)
As for PDF manipulation & merging directly in PHP (with the help of imagick
extension), I will be posting the code to my blog (the website associated
with my email address) as per Scott MacVicar's suggestion, within the week.
- spoon
""Bastien Koert"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
On Tue, May 27, 2008 at 11:46 AM, Christian Flickinger <[EMAIL PROTECTED]>
wrote:
It can certainly be done. It can easily be done using the Imagick
extension
(Image Magick extension for PHP), as I have just done something similar
(taking multiple PDFs and combining into flattened multi-page PDFs)
Is PHP the best language for this? Depends on your knowledge and confort
level with PHP. The best language is the language you know best and can
easily accomodate your requirements.
- spoon
Christian,
Interesting to know, however the OP's question was about using PHP to run
the scanner, not on the already present PDFs in the FS. Can your solution
handle the scanning? Could / Would you be willing to share you solution on
merging the PDFs? That is something that I am interested in...
Thanks,
--
Bastien
Cat, the other other white meat
--- End Message ---
--- Begin Message ---
PDFTK is a great tool, but if you want to keep everything inside PHP, using
imagick is great.
I use PDFTK to populate form fields in PDF files before I do other things
using imagick.
- spoon
"Brady Mitchell" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
On May 27, 2008, at 923AM, Bastien Koert wrote:
Interesting to know, however the OP's question was about using PHP to
run
the scanner, not on the already present PDFs in the FS.
That's not how I read the question, but clearly I could be wrong...
Could / Would you be willing to share you solution on
merging the PDFs? That is something that I am interested in...
I've been meaning to suggest that the OP look at pdftk
(http://www.accesspdf.com/pdftk/ ) - though it's not a PHP solution, it's
a great tool for working with PDFs. It can make otherwise tedious, time
consuming tasks with PDFs quick and easy.
Brady
--- End Message ---
--- Begin Message ---
I'm using the pear class Mail_RFC822::parseAddressList() which apparently only throws an
error_object for PEAR_Error.
The manual says that PEAR_Error is deprecated, so I'd like to use PEAR_Exception; but; am having
trouble getting it to recognize the error.
Can anyone help me with this?
--- End Message ---
--- Begin Message ---
I am writing code to read a bunch of xml files which describe
pharmaceutical drugs. They have namespace references at the top of each
file that look like this:
<document xmlns:voc="http://www.hl7.org/v3/voc" xmlns="urn:hl7-org:v3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:hl7-org:v3
http://www.fda.gov/oc/datacouncil/schemas/spl/spl.xsd">
I am having a challenging time coming up with an xpath query that works
even after registering a namespace like this:
$xpath->registerNamespace("voc","http://www.hl7.org/v3/voc" );
I am trying a query like this:
$qry = '//component' ;
$nodeList = $xpath->query($qry);
I can't seem to make it work. Could someone please advise?
thanks
Selwyn
The whole program looks like this:
$dom=new DOMDocument;
$dom->load('./828C40F4-5969-4254-9008-36AF15CC601B.xml') ;
$qry = '//component' ;
$nodeList = $xpath->query($qry);
header('Content-Type: text/plain');
foreach ($nodeList as $node)
{
echo $dom->saveXML($node) . "\r\n";
}
--
Selwyn Polit
Computer Consulting, programming, web sites
512-696-0410
www.AustinProgressiveCalendar.com
--- End Message ---
--- Begin Message ---
Hi Folks,
This may not be strictly a PHP question but there may be something in
PHP to do what I want. I am in the process of putting together a pretty
basic website using MySql and PHP on a third party host. One of the
function is to allow known stockist download a catalogue (.pdf). I am
fine to do login etc. but I am not sure how to approach restricting
the catalogue. I can do it so that the link is only visible if the user
logins in, but that doesn't stop the link being downloadable even if it
is not visible. I was thinking I could put it in a location not visible
to the public and transfer it to a location that is when the user logs
in, something with a cryptic name etc... but that doesn't really sit
right with me and at very least gives me some house keeping issues....
Anybody got a suggestion as to the best way to handle this ?
TIA,
JC
--- End Message ---