Click to See Complete Forum and Search --> : php redirect


psn
06-07-2005, 02:51 AM
I have 2 programs called prog1.php and prog2.php.

------------------------------------------------------------------------
prog1.php

<form name="form1" action="prog2.php">
<input type="text" name"txtname"><br>
<input type="submit" value="submit">
</form>

Clicking submit button in prog1.php should redirect the browser
to prog2.php
--------------------------------------------------------------------------
But my question is, If I directly run prog2.php without coming from prog1.php, then the browser should redirect me to prog1.php.
So how to do this.

Note: this is not a login page.

Regards

NogDog
06-07-2005, 02:56 AM
prog1.php:

<form name="form1" action="prog2.php">
<input type="text" name"txtname"><br>
<input type="submit" value="submit" name="prog1"> # <-- added name here
</form>

prog2.php:

<?php
if(!isset($_POST['prog1']))
{
header("Location: http://www.yoursite.com/prog1.php");
exit;
}
# form processing follows...
?>

psn
06-07-2005, 03:17 AM
thank you for your reply.

But if there was no submit button in prog1.php and it was
< a href="prog2.php">Click</a>
So how to do it.


So my question is no matter wheter there is submit button or a href in prog1.php

That is my browser should not allow prog2.php to execute without coming from prog1.php.

hammerslane
06-07-2005, 03:43 AM
On prog2:
<? if($_SERVER['HTTP_REFERER']!="http://path-to-script/prog2.php") { header("Location: prog1.php"); } ?>
{prog2 content}

Is that what you meant?

psn
06-07-2005, 04:49 AM
On prog2:
<? if($_SERVER['HTTP_REFERER']!="http://path-to-script/prog2.php") { header("Location: prog1.php"); } ?>
{prog2 content}

Is that what you meant?

I tried your code and opened directly prog2.php and got following errors in prog2.php.

Notice: Undefined index: HTTP_REFERER in c:\inetpub\wwwroot\testing\prog2.php on line 12

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\testing\prog2.php:12) in c:\inetpub\wwwroot\testing\prog2.php on line 14