Re: [PHP] Redirecting in a PHP script

2007-03-15 Thread clive

Larry Bradley wrote:
I need to goto  different PHP pages in my web site depending on what 
happens within some PHP code.


For example, if the user is not logged in when he goes to a page, I want 
to send him to a LOGIN page.


I've have everything working fine, using the following Javascript code:
$location = 'login.php';
echo script language='javascript'\n;
echo document.location.href = ' . $location . ';\n;
echo /script\n;

I also played around with using the header(location: ...) function.

I understand that the header() function must be issued before any HMTL 
is output.


But I'm not sure about the Javascript code. In every instance in my 
code, I use the Javascript before any HTML - this type of action 
normally occurs in PHP code called via a form POST.


I presume that the Javascript code really does the same as the PHP 
stuff, and thus must obey the same rules, but I'm not sure.

Comments?

Larry Bradley
Orleans (Ottawa), Ontario, CANADA


You could just put the bit of code that does the redirect above the HTML,

or use ob_start() at the beginning of your php file and
ob_end_flush() at the end, if you need to do a redirect then call 
ob_end_clean() before the header() function.


and as some one else mentioned with clever use of a switch-case and 
includes you can avoid header() redirects entirely.



Clive

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-15 Thread tedd

At 11:28 PM -0500 3/14/07, Richard Lynch wrote:

On Tue, March 13, 2007 11:54 pm, Chris Shiflett wrote:

 Tijnema wrote:

 Did you guys ever noted that little arrow down just right of
 the back button, where you can go back 2 steps at once, so you
 don't have to click very fast?


 I think we both remember browsing before that feature was invented.


I remember the fire-storm when the IMG tag was introduced.

Death of the Internet. Film at 11

Various news posts went like this:

I mean, my God, man, you're going to include a FIFTEEN KILOBYTE file
on your web page?!!!

What, are you crazy???!

That's going to melt-down the entire Internet!

:-) :-) :-)


Yeah, I remember similar comments about using a mouse -- hey, things change.

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-15 Thread Satyam
- Original Message - 
From: tedd [EMAIL PROTECTED]




At 11:28 PM -0500 3/14/07, Richard Lynch wrote:

On Tue, March 13, 2007 11:54 pm, Chris Shiflett wrote:

 Tijnema wrote:

 Did you guys ever noted that little arrow down just right of
 the back button, where you can go back 2 steps at once, so you
 don't have to click very fast?


 I think we both remember browsing before that feature was invented.


I remember the fire-storm when the IMG tag was introduced.

Death of the Internet. Film at 11

Various news posts went like this:

I mean, my God, man, you're going to include a FIFTEEN KILOBYTE file
on your web page?!!!

What, are you crazy???!

That's going to melt-down the entire Internet!

:-) :-) :-)


Yeah, I remember similar comments about using a mouse -- hey, things 
change.


tedd
--


And this nonsense of a glass-tty! how are you supposed to really make sense 
of a program staring at that thing, seeing just 24 lines at a time?  It 
can't compare with browsing through fanfold paper in the confort of your 
desk, or even at home! Whenever, wherever an idea hits you, paper and pencil 
is just so handy.


Satyam

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-14 Thread Tijnema !

On 3/14/07, Chris Shiflett [EMAIL PROTECTED] wrote:

Tijnema wrote:
 Did you guys ever noted that little arrow down just right of
 the back button, where you can go back 2 steps at once, so you
 don't have to click very fast?

I think we both remember browsing before that feature was invented.

Chris


How long ago is that? Was it before i came to earth? ... LOL
It was in Win95 right?

I never worked on Win3.x so maybe it was there :)

Tijnema


--
Chris Shiflett
http://shiflett.org/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-14 Thread Ben Ramsey

On 3/13/07 4:50 PM, Tijnema ! wrote:

Did you guys ever noted that little arrow down just right of the back
button, where you can go back 2 steps at once, so you don't have to
click very fast??


Browsers have buttons in them? Next thing, you'll be telling me I can 
see images and color in my browser! What craziness! ;-)


--
Ben Ramsey
http://benramsey.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-14 Thread Richard Lynch
On Tue, March 13, 2007 3:41 pm, Chris Shiflett wrote:
 Robert Cummings wrote:
 I've found clicking really fast can get you back :)

 I, too, have successfully used this technique. :-)

+1

Sometimes back button followed at just the right time by top so I
get the HTML, but no JS runs.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-14 Thread Richard Lynch
On Tue, March 13, 2007 3:50 pm, Tijnema ! wrote:
 On 3/13/07, Chris Shiflett [EMAIL PROTECTED] wrote:
 Robert Cummings wrote:
  I've found clicking really fast can get you back :)

 I, too, have successfully used this technique. :-)

 Chris
 Did you guys ever noted that little arrow down just right of the back
 button, where you can go back 2 steps at once, so you don't have to
 click very fast??

Yes, but 2 pages back is not where I want to be.

I want to be on the page with the stupid JS or META re-direct, without
getting bounced forward.

Quick-draw McGraw says back + stop == DWIM

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-14 Thread Richard Lynch
On Tue, March 13, 2007 11:54 pm, Chris Shiflett wrote:
 Tijnema wrote:
 Did you guys ever noted that little arrow down just right of
 the back button, where you can go back 2 steps at once, so you
 don't have to click very fast?

 I think we both remember browsing before that feature was invented.

I remember the fire-storm when the IMG tag was introduced.

Death of the Internet. Film at 11

Various news posts went like this:

I mean, my God, man, you're going to include a FIFTEEN KILOBYTE file
on your web page?!!!

What, are you crazy???!

That's going to melt-down the entire Internet!

:-) :-) :-)

And boy that blink tag was fun... For about 5 minutes. :-v

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-13 Thread Eric Butera

On 3/12/07, Larry Bradley [EMAIL PROTECTED] wrote:

I need to goto  different PHP pages in my web site depending on what
happens within some PHP code.

For example, if the user is not logged in when he goes to a page, I want to
send him to a LOGIN page.

I've have everything working fine, using the following Javascript code:
 $location = 'login.php';
 echo script language='javascript'\n;
 echo document.location.href = ' . $location . ';\n;
 echo /script\n;

I also played around with using the header(location: ...) function.

I understand that the header() function must be issued before any HMTL is
output.

But I'm not sure about the Javascript code. In every instance in my code, I
use the Javascript before any HTML - this type of action normally occurs in
PHP code called via a form POST.

I presume that the Javascript code really does the same as the PHP stuff,
and thus must obey the same rules, but I'm not sure.
Comments?

Larry Bradley
Orleans (Ottawa), Ontario, CANADA


Just to throw my two cents into this...

I set my scripts up so they run something like this:
class SomePage {
function process($controller) {
if (! logged in)
  return $controller-foward('Login', 'Form');
[page code]
}
}

This way I don't have to issue header redirects to make a user see a
totally different part of the script.  I just tell the controller to
foward the request to another controller action.  You could use this
method on saving records where the post page can redisplay the form on
an error.

The only time I use header redirects is when I don't want the user to
accidentally resubmit the form when they click the back button or if I
need to change the url to remove a variable from it.

On any of my pages that accept POST data I issue a redirect to a page
that thanks the user.  This way they can hit refresh all day and I
don't get extra posts or that nasty page has expired message in IE.

One thing you might also want to consider is the fact people can turn
off JavaScript.  Spam bots also do not have JavaScript.  Anything that
is important such as making sure a user is logged in should have a
server side check otherwise they will blaze right past your JS
redirect.

To do something like the controller above in procedural code it would
be easy enough:

---page.php---
if (! logged in) {
   require 'templates/login_form.php';
} else {
   echo 'user is logged in and okay!';
}
---

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-13 Thread Dave Goodchild

If you do want to use the header function after html has been output, you
can always look at using output buffering (ob_start()).


Re: [PHP] Redirecting in a PHP script

2007-03-13 Thread Robert Cummings
On Tue, 2007-03-13 at 21:50 +0100, Tijnema ! wrote:
 On 3/13/07, Chris Shiflett [EMAIL PROTECTED] wrote:
  Robert Cummings wrote:
   I've found clicking really fast can get you back :)
 
  I, too, have successfully used this technique. :-)
 
  Chris

 Did you guys ever noted that little arrow down just right of the back
 button, where you can go back 2 steps at once, so you don't have to
 click very fast??

Sure have... but where's the fun in it? ;)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-13 Thread Chris Shiflett
Tijnema wrote:
 Did you guys ever noted that little arrow down just right of
 the back button, where you can go back 2 steps at once, so you
 don't have to click very fast?

I think we both remember browsing before that feature was invented.

Chris

-- 
Chris Shiflett
http://shiflett.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Redirecting in a PHP script

2007-03-12 Thread Tijnema !

On 3/12/07, Larry Bradley [EMAIL PROTECTED] wrote:


I need to goto  different PHP pages in my web site depending on what
happens within some PHP code.

For example, if the user is not logged in when he goes to a page, I want
to
send him to a LOGIN page.

I've have everything working fine, using the following Javascript code:
$location = 'login.php';
echo script language='javascript'\n;
echo document.location.href = ' . $location . ';\n;
echo /script\n;

I also played around with using the header(location: ...) function.

I understand that the header() function must be issued before any HMTL is
output.

But I'm not sure about the Javascript code. In every instance in my code,
I
use the Javascript before any HTML - this type of action normally occurs
in
PHP code called via a form POST.

I presume that the Javascript code really does the same as the PHP stuff,
and thus must obey the same rules, but I'm not sure.
Comments?

Larry Bradley
Orleans (Ottawa), Ontario, CANADA



There's a difference in them, as the php header function defines the
redirect in the header, meaning that all body is not even parsed. And it
works also if javascript is disabled.
I prefer the header function, but if you already have data parsed, the
javascript could to the job, but even then it needs to be inside the head
tags i believe, or else it won't get automatically executed.

Tijnema


Re: [PHP] Redirecting in a PHP script

2007-03-12 Thread Robert Cummings
On Mon, 2007-03-12 at 22:43 +0100, Satyam wrote:
 The only way to actually go back in 
 those is to open the dropdown list for the back button and skip over one 
 item.

I've found clicking really fast can get you back :)

 That does not happen when using the header() PHP function.

That is my recommendation also despite the success of frantic clicking
*grin*

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php