Jump to content

Conditional redirect


freakus_maximus

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.
Link to comment
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]


Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.