how to go to another php page after ifelse....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

how to go to another php page after ifelse....

Post 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...
:roll:
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

Post 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 :wink:
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

Post by jolan_lars »

im having errors with that command.

Warning: Cannot add header information - headers already sent by (output started at ......)

:roll:
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

you use this function after some headers are sent you can use ob_start() function!
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

Post 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/');
?>
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

Post 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....

:roll:
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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.. :)
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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='>"; 
} 

?>
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

Post by jolan_lars »

heheheh...both of 'em worked out....

nice n easy..

thanks for that igoy..... :D
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

Post 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>";
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

Post 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....
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

????

Post by itsmani1 »

Code: Select all

<?php
if(a>b)
{
header(Location:abc.php?)
}
else
{
header(Location:xyz.php?)
}

?>
jolan_lars
Forum Newbie
Posts: 19
Joined: Thu Oct 23, 2003 12:15 pm

Post by jolan_lars »

perfect.....

i didnt know that! :D

i owe u a big one there buddy....


thanks!!!!
User avatar
igoy
Forum Contributor
Posts: 203
Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:

Post 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.
Post Reply