FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to redirect with PHP





Satori
I have a "simple" email script that someone else wrote for me in PHP (because I have absolutely no knowledge of php.) Currently, the user fills out a form and clicks "submit" and the php script sends me the info in the form of an email. It then outputs "your email has been sent...Thanks." Or something like that. Here is the end of the script

Code:

        // Send mail
   if(!mail($to,$subject,$body,$headers)){
      echo "mail error";
   }
        // display mail sent message
   else {
        echo (" <title>SendMail Notice: mail was successfully sent</title><body><br><br><br><br>
      <p style=\"font:11pt arial\" align=center>Your mail has been successfully sent...<i>Thank you</i></p>
      </body></html>"); exit(0);
   }

// exit script
} exit(0);
?>


What I would like to do is have the script redirect the user to a page of my choosing instead. That way I can create a nicer looking html "thanks" page instead of the blank white page with one line of text.

Can someone help me please?
Hammy
I use:
Code:
redirect('index.php?site=contact','Your message was sent successfully.');


I too arnt very good at php, but i guess this would work:
Code:
redirect('pageofyourchoice.php');


So you would get:
Code:

        // Send mail
   if(!mail($to,$subject,$body,$headers)){
      echo "mail error";
   }
        // display mail sent message
   else {
     redirect('pageofyourchoice.php');
   }

// exit script
} exit(0);
?>


Sorry if it doesnt work =]
Hammy.
gerpg
Php has its own redirect funtion called a 'header' for example...
Code:

<?
header('Location: http://www.watever.com');
?>


or if you want to link to a folder in a directory...

Code:

<?
header('Location: folder/filename.php');
?>


hope this helps,

Louis.
rohan2kool
gerpg wrote:

Php has its own redirect funtion called a 'header' for example...


'header' is not a ''redirect'' function. It is used to send out HTTP headers. HTTP headers are pieces of information that precede an HTTP transaction. Basically, it's like the server tells the client how to handle the things it is sending and vice versa.

In this case, you are using a 'Location' HTTP header, which is used to 'redirect the recipient to a location other than the Request-URI for completion of the request or identification of a new resource' Rest all as gerpg said Very Happy

Refer:

Section 14.30 in: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Satori
Hammy - Thanks for trying, but I couldn't get your code to work Smile

gerpg - Thanks for a solution that does exactly what I want!

rohan2kool - If "header" is not a "redirect" function, would it be improper to use it for that reason? If so, can you please offer an alternative solution that works just as well?
rohan2kool
Satori wrote:

rohan2kool - If "header" is not a "redirect" function, would it be improper to use it for that reason? If so, can you please offer an alternative solution that works just as well?


No. It's not at all improper to use it, because there is no standard 'redirect' function. Redirection is a facility provided as a part of the HTTP/1.1 specification, which we can use via HTTP headers, which we send using the header() function. I was just pointing out a conceptual error of gerpg when he said that php has a 'redirect' function that... rest all is perfectly fine and that is what everybody uses Very Happy.
Satori
rohan2kool wrote:
Satori wrote:

rohan2kool - If "header" is not a "redirect" function, would it be improper to use it for that reason? If so, can you please offer an alternative solution that works just as well?


No. It's not at all improper to use it, because there is no standard 'redirect' function. Redirection is a facility provided as a part of the HTTP/1.1 specification, which we can use via HTTP headers, which we send using the header() function. I was just pointing out a conceptual error of gerpg when he said that php has a 'redirect' function that... rest all is perfectly fine and that is what everybody uses Very Happy.


I see now...thanks for clearing it up! And thanks again gerpg for the code! Now anyone who sends me email from my site gets a nice and pretty "thank you" page instead of a line of text on a white background Smile
Related topics
I'm going to try out linux
Mail Issued
how to prevent double post when user klik F5 *Refresh* ?
Forum Redirection Question
Mail account
SquirrelMail problem
MySQL software problems
Free Links Directory - submit your site or favorite site
Installing a new wiki
Problem with url redirecting
how i do pass users to different pages?
Redirection to URL
Help needed with HTTPS/HTTP links
Did You Click on a Link on My Site
Auto forward links template
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.