Newbie - Is there a PHP equivalent of Server.Transfer (in ASP.NET)

271 views
Skip to first unread message

Alan Silver

unread,
Aug 22, 2007, 5:38:38 AM8/22/07
to
Hello,

Sorry for the newbie question, but I've only been at PHP for a couple of
days, and I'm trying to get some stuff done as fast as possible. I'm an
experienced ASP.NET programmer, and am trying to find some equivalent
stuff in PHP.

In ASP.NET there is a method called Server.Transfer which transfers the
request to a different page from the one that the user requested, but
without doing a redirect. The user gets sent headers as though they were
seeing the page they requested.

Does PHP have such a function? I have seen the function...

header('Location: page.php');

...but these seems to be a redirect, which is not the same thing. I
don't want the headers altered as I want the search engines to see the
page with the original URL.

TIA for any help.

--
Alan Silver
(anything added below this line is nothing to do with me)

Jerry Stuckle

unread,
Aug 22, 2007, 7:49:29 AM8/22/07
to

No, it doesn't. But I wish it did.

You could emulate it with CURL, but that's about all.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

Alan Silver

unread,
Aug 22, 2007, 8:38:14 AM8/22/07
to
In article <W8WdnSD-aoCOvlHb...@comcast.com>, Jerry Stuckle
<jstu...@attglobal.net> writes

>Alan Silver wrote:
>> Hello,
>> Sorry for the newbie question, but I've only been at PHP for a
>>couple of days, and I'm trying to get some stuff done as fast as
>>possible. I'm an experienced ASP.NET programmer, and am trying to
>>find some equivalent stuff in PHP.
>> In ASP.NET there is a method called Server.Transfer which transfers
>>the request to a different page from the one that the user requested,
>>but without doing a redirect. The user gets sent headers as though
>>they were seeing the page they requested.
>> Does PHP have such a function? I have seen the function...
>> header('Location: page.php');
>> ...but these seems to be a redirect, which is not the same thing. I
>>don't want the headers altered as I want the search engines to see the
>>page with the original URL.
>> TIA for any help.
>
>No, it doesn't. But I wish it did.

Shame.

>You could emulate it with CURL, but that's about all.

Thanks, but it looks OTT for the simple use I have in mind.

Thanks for the reply

rf

unread,
Aug 22, 2007, 9:01:14 AM8/22/07
to

"Jerry Stuckle" <jstu...@attglobal.net> wrote in message
news:W8WdnSD-aoCOvlHb...@comcast.com...

> Alan Silver wrote:
>> Hello,
>>
>> Sorry for the newbie question, but I've only been at PHP for a couple of
>> days, and I'm trying to get some stuff done as fast as possible. I'm an
>> experienced ASP.NET programmer, and am trying to find some equivalent
>> stuff in PHP.
>>
>> In ASP.NET there is a method called Server.Transfer which transfers the
>> request to a different page from the one that the user requested, but
>> without doing a redirect. The user gets sent headers as though they were
>> seeing the page they requested.
>>
>> Does PHP have such a function? I have seen the function...
>>
>> header('Location: page.php');
>>
>> ...but these seems to be a redirect, which is not the same thing. I don't
>> want the headers altered as I want the search engines to see the page
>> with the original URL.
>>
>> TIA for any help.
>>
>
> No, it doesn't. But I wish it did.

Am I totally missing something simple here?

<?php>
// make sure no output has occurred, especially headers
if (whatever)
{
include 'the other page';
exit;
}
<?>

--
Richard.


gosha bine

unread,
Aug 22, 2007, 9:05:38 AM8/22/07
to

include()

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi

Alan Silver

unread,
Aug 22, 2007, 11:40:09 AM8/22/07
to
In article <46cc34d2$0$11217$6e1e...@read.cnntp.org>, gosha bine
<stere...@gmail.com> writes

>On 22.08.2007 11:38 Alan Silver wrote:
>> Hello,
>> Sorry for the newbie question, but I've only been at PHP for a
>>couple of days, and I'm trying to get some stuff done as fast as
>>possible. I'm an experienced ASP.NET programmer, and am trying to
>>find some equivalent stuff in PHP.
>> In ASP.NET there is a method called Server.Transfer which transfers
>>the request to a different page from the one that the user requested,
>>but without doing a redirect. The user gets sent headers as though
>>they were seeing the page they requested.
>> Does PHP have such a function? I have seen the function...
>> header('Location: page.php');
>> ...but these seems to be a redirect, which is not the same thing. I
>>don't want the headers altered as I want the search engines to see the
>>page with the original URL.
>> TIA for any help.
>
>include()

Didn't work. I'm using Wordpress on a Windows platform, and I want to
use a permalink structure that gives blog links like
http://www.fred.com/a-blog-post instead of http://www.fred.com/?p=3 as
the former is much more search engine friendly. As I'm on Windows, I
don't have the .htaccess file where I could add the code to do the URL
rewriting, so I'm looking for other ways to do this. As this "blog" (it
isn't really) is only going to have a small number of pages, I was
hoping I could just set up a file that would be called from
http://www.fred.com/a-blog-post and have it send out the content of
http://www.fred.com/?p=3 instead. I tried include() but it didn't work.

Thanks anyway. I think it's going to be easier to copy the resulting
HTML into a static page and have that instead!

gosha bine

unread,
Aug 22, 2007, 11:50:00 AM8/22/07
to

.htaccess and mod_rewrite work just fine in windows version of apache.
Are you using apache?

Jerry Stuckle

unread,
Aug 22, 2007, 2:18:53 PM8/22/07
to

That doesn't redirect - as the op requested.

NC

unread,
Aug 22, 2007, 8:25:20 PM8/22/07
to
On Aug 22, 2:38 am, Alan Silver <alan-sil...@nospam.thanx.invalid>
wrote:

>
> Sorry for the newbie question, but I've only been at PHP for a couple of
> days, and I'm trying to get some stuff done as fast as possible. I'm an
> experienced ASP.NET programmer, and am trying to find some equivalent
> stuff in PHP.
>
> In ASP.NET there is a method called Server.Transfer which transfers the
> request to a different page from the one that the user requested, but
> without doing a redirect. The user gets sent headers as though they were
> seeing the page they requested.
>
> Does PHP have such a function?

No. Server.Transfer is IIS' way of doing URL rewriting. PHP, being
originally developed for Apache, leaves URL rewriting to the HTTP
server. So what you need to do is to set up a rewrite rule. If you
are using Apache, you already have everything you need for that. If
you are using IIS, there are add-on modules that allow you to do URL
rewriting. I use ISAPI_Rewrite on one of my development servers:

http://www.isapirewrite.com/

>From your later message, I understand you are using WordPress.
WordPress' .htaccess file is not very complicated; it basically boils
down to this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

and the above in all likelihood can be ported over to ISAPI_Rewrite.

Cheers,
NC

Alan Silver

unread,
Aug 23, 2007, 4:52:05 AM8/23/07
to
In article <1187828720.6...@m37g2000prh.googlegroups.com>, NC
<n...@iname.com> writes
<snip>

>and the above in all likelihood can be ported over to ISAPI_Rewrite.

Thanks for the reply. Given the simple nature of what I'm trying to do,
this is going to be OTT for the job. Useful to know in case I need it
for others though.

Ta ra

Alan Silver

unread,
Aug 23, 2007, 4:42:20 AM8/23/07
to
In article <46cc5b59$0$11218$6e1e...@read.cnntp.org>, gosha bine
<stere...@gmail.com> writes

>.htaccess and mod_rewrite work just fine in windows version of apache.
>Are you using apache?

Nope, using IIS, and there are loads of ASP.NET sites already there, so
I wouldn't even think of switching servers now.

Thanks anyway

Jerry Stuckle

unread,
Aug 23, 2007, 9:11:41 AM8/23/07
to
Alan Silver wrote:
> In article <46cc5b59$0$11218$6e1e...@read.cnntp.org>, gosha bine
> <stere...@gmail.com> writes
>> .htaccess and mod_rewrite work just fine in windows version of apache.
>> Are you using apache?
>
> Nope, using IIS, and there are loads of ASP.NET sites already there, so
> I wouldn't even think of switching servers now.
>
> Thanks anyway
>

That's the difference. I've got one vps on Windows. All the rest are
Linux. The Windows VPS requires 4x the memory, 50% faster CPU - and
over twice the monthly cost of the Linux servers to do the same job.
And even then it's slower.

We're in the process of converting the last customer from ASP to PHP
now. Then even that one will be gone.

Alan Silver

unread,
Aug 23, 2007, 10:59:46 AM8/23/07
to
In article <4-2dnbqiVO9FGlDb...@comcast.com>, Jerry Stuckle
<jstu...@attglobal.net> writes

>Alan Silver wrote:
>> In article <46cc5b59$0$11218$6e1e...@read.cnntp.org>, gosha bine
>><stere...@gmail.com> writes
>>> .htaccess and mod_rewrite work just fine in windows version of
>>>apache. Are you using apache?
>> Nope, using IIS, and there are loads of ASP.NET sites already there,
>>so I wouldn't even think of switching servers now.
>> Thanks anyway
>>
>
>That's the difference. I've got one vps on Windows. All the rest are
>Linux. The Windows VPS requires 4x the memory, 50% faster CPU - and
>over twice the monthly cost of the Linux servers to do the same job.
>And even then it's slower.
>
>We're in the process of converting the last customer from ASP to PHP
>now. Then even that one will be gone.

Horses for course I suppose. I'm very happy with my current set up. I
run my own server, so cost isn't an issue, and I'm very happy with IIS
and ASP.NET. I haven't used PHP enough to compare, so I'm not saying
ASP.NET is better, just that I'm very happy with it.

Thanks for the reply.

Reply all
Reply to author
Forward
0 new messages