PHP autoredirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sloppyjoe
Forum Newbie
Posts: 20
Joined: Thu Jul 09, 2009 3:43 pm

PHP autoredirect

Post by sloppyjoe »

Hi there.

I have this code

Code: Select all

 
<?php
 
// Take info from form
$username = $_POST['username'];
$password = $_POST['password'];
// The tweet
$message = $_POST['tweet'];
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
// check for success or failure
if (empty($buffer)) {
    echo 'message';
} else {
    echo 'success' ;
}
?>
 
What i want is whether it fails or success is the page to go back to index.html after 6 secods. what needs to be added to the code, and where?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP autoredirect

Post by AbraCadaver »

Code: Select all

sleep(6);
header('Location: http://www.example.com/index.html');
exit;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
sloppyjoe
Forum Newbie
Posts: 20
Joined: Thu Jul 09, 2009 3:43 pm

Re: PHP autoredirect

Post by sloppyjoe »

Thanks alot. I appreciate the help.

does it matter where this code goes?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP autoredirect

Post by AbraCadaver »

sloppyjoe wrote:Thanks alot. I appreciate the help.

does it matter where this code goes?
Well, I would do it at the end after everything else has completed or else it will break your script.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply