/    Sign up×
Community /Pin to ProfileBookmark

problem with redirect

hi, I am having a problem with a page redirecting.

I would like the page to show for say, 5 seconds or so then redirect to another page.

Here is the code:

[code=php]<?php

// Checks to make sure that user is logged in
session_start();
if ( $_SESSION[‘user’] == null || $_SESSION[‘user’] < 1 )
{
header( ” Location: index.php” );
exit;
}

require_once( “DB.php” );
$dsn = ‘mysql://hrpjeff_root:password@localhost/hrpjeff_time’;
$db =& DB::Connect( $dsn, array() );
if (PEAR::isError($db)) { die($db->getMessage()); }

$res = $db->query( “SELECT name FROM users WHERE id=?”,
array( $_SESSION[‘user’] ) );
$res->fetchInto( $row );

// filename: upload.success.php

?><!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>

<html lang=”en”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″>

<link rel=”stylesheet” type=”text/css” href=”stylesheet.css”>

<title>Successful upload</title>

</head>

<body>

<div id=”Upload”>
<h1>File upload</h1>
<p>Congratulations! Your file upload was successful!</p>
<?php header( ” Location: ../main.page.php” );?>
</div>

</body>

</html>[/code]

Any suggestions?

Thanks in advance.

Warning: Cannot modify header information – headers already sent by (output started at /home/hrpjeff/public_html/uploader/upload.success.php:41) in /home/hrpjeff/public_html/uploader/upload.success.php on line 42

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@scragarJan 10.2008 — [code=html] <head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<link rel="stylesheet" type="text/css" href="stylesheet.css">
<meta http-equiv="refresh" content="5;url=../main.page.php">
<title>Successful upload</title>

</head>

<body>

<div id="Upload">
<h1>File upload</h1>
<p>Congratulations! Your file upload was successful!</p>
</div>

</body>[/code]


the header function will not work if you have echoed or otherwise put any output other than other headers. this uses the meta refresh to load the page after a delay, some very old browsers don't accept it, so best offer a link as a fall back just in case.
Copy linkTweet thisAlerts:
@graphical_forceauthorJan 10.2008 — Thanks that worked!
Copy linkTweet thisAlerts:
@MrCoderJan 10.2008 — Or just use output buffering.

[code=php]
<?php
ob_start();

echo "This never gets displayed";

ob_end_clean();

header("Location: whereever.php");
die();
?>
[/code]
×

Success!

Help @graphical_force spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...