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
Post
by jolan_lars » Wed Oct 29, 2003 3:13 am
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...
Fredix
Forum Contributor
Posts: 101 Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:
Post
by Fredix » Wed Oct 29, 2003 3:25 am
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
jolan_lars
Forum Newbie
Posts: 19 Joined: Thu Oct 23, 2003 12:15 pm
Post
by jolan_lars » Wed Oct 29, 2003 3:34 am
im having errors with that command.
Warning: Cannot add header information - headers already sent by (output started at ......)
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Oct 29, 2003 3:37 am
you use this function after some headers are sent you can use ob_start() function!
Fredix
Forum Contributor
Posts: 101 Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:
Post
by Fredix » Wed Oct 29, 2003 3:40 am
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 » Wed Oct 29, 2003 3:56 am
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....
igoy
Forum Contributor
Posts: 203 Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:
Post
by igoy » Wed Oct 29, 2003 4:00 am
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..
igoy
Forum Contributor
Posts: 203 Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:
Post
by igoy » Wed Oct 29, 2003 4:05 am
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 » Wed Oct 29, 2003 4:07 am
heheheh...both of 'em worked out....
nice n easy..
thanks for that igoy.....
jolan_lars
Forum Newbie
Posts: 19 Joined: Thu Oct 23, 2003 12:15 pm
Post
by jolan_lars » Wed Oct 29, 2003 4:13 am
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 » Wed Oct 29, 2003 4:24 am
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....
igoy
Forum Contributor
Posts: 203 Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:
Post
by igoy » Wed Oct 29, 2003 4:42 am
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.
itsmani1
Forum Regular
Posts: 791 Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:
Post
by itsmani1 » Wed Oct 29, 2003 4:55 am
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 » Wed Oct 29, 2003 5:04 am
perfect.....
i didnt know that!
i owe u a big one there buddy....
thanks!!!!
igoy
Forum Contributor
Posts: 203 Joined: Fri May 02, 2003 11:57 pm
Location: India
Contact:
Post
by igoy » Wed Oct 29, 2003 5:05 am
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.