Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Redirecting using PHP


  • Please log in to reply
6 replies to this topic

#1 JUICYboy

JUICYboy

  • Members
  • 537 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Anaheim, Ca
  • Local time:08:17 AM

Posted 05 March 2011 - 10:11 PM

I have learned how to redirect using PHP, but I wanted to have a timer on it(like a countdown).

It redirects without a countdown in my page. I pasted a example of my code, I researched it and some links recommend to use Javascript. But I am using a Contact Me Page and I want it to use PHP.

I know it can be done.... :mellow: SCRIPT IS BELOW... :lol:

<!--
JUICYboy
Edited on 2/2/11 13:35:24
-->

<!-- PHP form for contact_us.html page -->
<?php
$to = "Me@hotmail.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = "=====Customer Inquiry=====" . "\n" ."\n" ;
$message .= "First name: " .$_POST['name'] ."\n" ;
$message .= "Phone: " .$_POST['phone'] ."\n" ;
$message .= "e-mail: " .$_POST['email'] ."\n" ;
$message .= "Regarding: " .$_POST['regarding'] ."\n";
$message .= "Message: " .$_POST['message'] . "\n" ;
$headers = "From: $email"; $sent = mail($to, $subject, $message, $headers) ;
if($sent) {print "Your mail was sent successfully"; }
else {print "We encountered an error sending your mail"; }


header( 'Location: http://www.yoursite.com/new_page.html' ) ;

?>

Edited by JUICYboy, 05 March 2011 - 10:14 PM.


BC AdBot (Login to Remove)

 


#2 Andrew

Andrew

    Bleepin' Night Watchman


  • Moderator
  • 8,260 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Right behind you
  • Local time:04:17 AM

Posted 05 March 2011 - 11:47 PM

I am by no means a PHP guru, but I don't think you can do a timeout in PHP alone since it's basically a server-side preprocessor. You can, however, use PHP to put some Javascript in there and it's pretty easy to do a Javascript timer.

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:17 AM

Posted 06 March 2011 - 08:56 AM

I'm not sure what you even want to do.

#4 Andrew

Andrew

    Bleepin' Night Watchman


  • Moderator
  • 8,260 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Right behind you
  • Local time:04:17 AM

Posted 06 March 2011 - 07:27 PM

Looks to me like a "Message Received" page after submitting a form.

#5 JUICYboy

JUICYboy
  • Topic Starter

  • Members
  • 537 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Anaheim, Ca
  • Local time:08:17 AM

Posted 08 March 2011 - 08:26 PM

Yes exactly

Once someone goes to my contact form and clicks "send".

The message is send threw php. How ever php does not redirect back to the previous page, unless I add the:

header( 'Location: http://www.yoursite.com/new_page.html' ) ;

The problem: When I add the syntax above it redirects so fast that the person would not know that the message has been sent.


I been busy :mellow:

#6 Andrew

Andrew

    Bleepin' Night Watchman


  • Moderator
  • 8,260 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:Right behind you
  • Local time:04:17 AM

Posted 08 March 2011 - 08:45 PM

Why not:

if($sent) {
header( 'Location: http://www.yoursite.com/message_received.html' );
} else {
header( 'Location: http://www.yoursite.com/OMG_WTF_BBQ!.html' );
}


#7 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:07:17 AM

Posted 09 March 2011 - 11:28 AM

As Andrew has already said, JavaScript is the way to go.

send message page (php header()) -----> Thank you page (JavaScript timeout) ----------> previous page.

For those who have disabled JavaScript, give a link at bottom that says : "If you do not want to wait 5 seconds, click here to go back to previous page"

You can also use meta refresh method which works in most browsers. The usual code is like this.
<meta http-equiv="refresh" content="5; url=/index.php">

The header(Location) method in php would not show any page and redirect immediately. Problem wih PHP in this case is that timer ticks on the server and not on the client's browser.

Edited by Romeo29, 09 March 2011 - 11:30 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users