Page 1 of 2
how to go to another php page after ifelse....
Posted: Wed Oct 29, 2003 3:13 am
by jolan_lars
how do I go to another php page after a condition?
My original problem was: there is this page that was originally inside an ifelse condition. In the end I realized that i need this "page" to refresh once in a while. Putting a meta-refresh won't work coz it's inside a number of ifelses.
So i decided to transfer that page to another php file and i dont kow how...
thanks in advance...

Posted: Wed Oct 29, 2003 3:25 am
by Fredix
try sth. like this:
Code: Select all
<?php
if (your_condition == TRUE)
{
header("Location: http://www.example.com/"); // redirection
exit; //stop executing the rest of this script
}
?>
further reading on php.net

Posted: Wed Oct 29, 2003 3:34 am
by jolan_lars
im having errors with that command.
Warning: Cannot add header information - headers already sent by (output started at ......)

Posted: Wed Oct 29, 2003 3:37 am
by mudkicker
you use this function after some headers are sent you can use ob_start() function!
Posted: Wed Oct 29, 2003 3:40 am
by Fredix
using headers you may not make any output. Look at this example:
Code: Select all
<html>
<?php
/* This will give an error. Note the output
* above, which is before the header() call */
header('Location: http://www.example.com/');
?>
Posted: Wed Oct 29, 2003 3:56 am
by jolan_lars
oh i see...
well, i'm in the deep part of the code already. finding and removing the html headers might affect the whole page.
if there is any other command for the purpose, 'twud be apprec8ed.
meanwhile, ill try to see if i can work it out using this command....

Posted: Wed Oct 29, 2003 4:00 am
by igoy
Try this
one :
Code: Select all
<?php
if ($this==$that) {
echo "<script language='javascript'>location.href='page.php'</script>";
}
?>
two:
Code: Select all
<?php
if ($this==$that) {
echo "<meta http-equiv='refresh' content='0;URL=page.php'>";
}
?>
not so long back I have also been <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> by Headers thingie...
this is way around I found..

Posted: Wed Oct 29, 2003 4:05 am
by igoy
You can do Lot of things that way....
like :
Code: Select all
<?php
if ($this==$that) {
echo "<script language='javascript'>location.reload()</script>";
}
?>
Code: Select all
<?php
if ($this==$that) {
echo "<meta http-equiv='refresh' content='0;URL='>";
}
?>
Posted: Wed Oct 29, 2003 4:07 am
by jolan_lars
heheheh...both of 'em worked out....
nice n easy..
thanks for that igoy.....

Posted: Wed Oct 29, 2003 4:13 am
by jolan_lars
hmm... what specifically is this script for? i think ill be needing it...
is this kinda like the meta-refresh of html?
echo "<script language='javascript'>location.reload()</script>";
Posted: Wed Oct 29, 2003 4:24 am
by jolan_lars
please forgive if im starting to sway from the topic.
How do i carry some of my variables from the original page to the new page?
thanks....
Posted: Wed Oct 29, 2003 4:42 am
by igoy
what kind of variables....... ????
$_POST, $_GET or some other..... ?
you can simply create a querystring probably for that....
like :
Code: Select all
<?php
$question = "jolan_lars";
$answer = "igoy";
$medium = "phpforums";
$page = "page.php?q=$question&a=$answer&m=$medium";
?>
<?php
if ($this==$that) {
echo "<script language='javascript'> location.href='$page' </script>";
}
?>
// or
<?php
if ($this==$that) {
echo "<meta http-equiv='refresh' content='0;URL=$page'>";
}
?>
then in "page.php" you can retrive these values using $_GET[].. eg
$_GET['q'], $_GET['a'] and so on and so on.
????
Posted: Wed Oct 29, 2003 4:55 am
by itsmani1
Code: Select all
<?php
if(a>b)
{
header(Location:abc.php?)
}
else
{
header(Location:xyz.php?)
}
?>
Posted: Wed Oct 29, 2003 5:04 am
by jolan_lars
perfect.....
i didnt know that!
i owe u a big one there buddy....
thanks!!!!
Posted: Wed Oct 29, 2003 5:05 am
by igoy
what kind of variables....... ????
$_POST, $_GET or some other..... ?
you can simply create a querystring probably for that....
like :
Code: Select all
<?php
$question = "jolan_lars";
$answer = "igoy";
$medium = "phpforums";
$page = "page.php?q=$question&a=$answer&m=$medium";
?>
<?php
if ($this==$that) {
echo "<script language='javascript'> location.href='$page' </script>";
}
?>
// or
<?php
if ($this==$that) {
echo "<meta http-equiv='refresh' content='0;URL=$page'>";
}
?>
then in "page.php" you can retrive these values using $_GET[].. eg
$_GET['q'], $_GET['a'] and so on and so on.