Jump to content


Photo

Conditional redirect


  • Please log in to reply
5 replies to this topic

#1 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 25 April 2006 - 08:49 PM

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.

$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
}

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.

#2 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 25 April 2006 - 11:04 PM

Use header() but it won't work if any output is sent before calling it.
<?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
}



Everything you want to know is here.

#3 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 26 April 2006 - 12:05 AM

[!--quoteo(post=368660:date=Apr 25 2006, 07:04 PM:name=Ferenc)--][div class=\'quotetop\']QUOTE(Ferenc @ Apr 25 2006, 07:04 PM) View Post[/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.


#4 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 26 April 2006 - 01:14 PM

*bump*



#5 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 26 April 2006 - 01:33 PM

Hello,

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

<?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
}
?>

Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#6 freakus_maximus

freakus_maximus
  • Members
  • PipPipPip
  • Advanced Member
  • 177 posts

Posted 26 April 2006 - 01:47 PM

Got it working! /cheer

Thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users