Jump to content

Archived

This topic is now archived and is closed to further replies.

freakus_maximus

Conditional redirect

Recommended Posts

This a snippet of code that allows me to determine if a record is locked in the table. All that works fine. But what I need to do is redirect if the record is locked to a page that tells the user it is locked, etc...otherwise continue with the code if not locked.

FYI - I am open to suggestions if I am going about this the wrong way...lol.

[code]$time_now = time();
$allowed_time = $time_now-30000;
    if($is_locked>$allowed_time) {
    echo ("Record is locked");//Need to redirect to a page with a record locked notice.
    

} else {
    echo ("Editing is allowed");//Editing form is in html/php mix below this
}[/code]

The rest of the code is a large mix of html and php w/ mysql queries where needed for dropdowns, etc...which all ends in a form to submit the edited information. Trying to avoid having to "echo" all the various html pieces out and figured if I could redirect conditionally this would solve the problem real quick.

Thanks for any help.

Share this post


Link to post
Share on other sites
Use header() but it won't work if any output is sent before calling it.
[code]
<?php
$time_now = time();
$allowed_time = $time_now-30000;
if($is_locked>$allowed_time) {
    header("Location: locked.php");//Need to redirect to a page with a record locked notice.
    exit;  // no more code should be executed
} else {
    echo ("Editing is allowed");//Editing form is in html/php mix below this
}[/code]


Share this post


Link to post
Share on other sites
[!--quoteo(post=368660:date=Apr 25 2006, 07:04 PM:name=Ferenc)--][div class=\'quotetop\']QUOTE(Ferenc @ Apr 25 2006, 07:04 PM) [snapback]368660[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Use header() but it won't work if any output is sent before calling it
[/quote]

Well that will not work then. The whole page is rendered within the index.php page.

Any other solutions or ideas for for doing this? I'm stumped.

Share this post


Link to post
Share on other sites
Hello,

First try the header function. if it does not work then i think another alternative is using javascript to redirect:

[code]
<?php
$time_now = time();
$allowed_time = $time_now-30000;
if($is_locked>$allowed_time) {
   echo "<script language=javascript>document.location.href='locked.php';</script>";
   exit;
} else {
    echo ("Editing is allowed");//Editing form is in html/php mix below this
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.