how to redirect?

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

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

how to redirect?

Post by m2babaey »

Hi
I need to redirect to the advertiser's website after some analysis. but header is not working
i use another tag that sometimes works and sometimes not:

Code: Select all

echo "<script> window.parent.ifrmTEXTFRNewWin('$url')</script>";
is there a solution? i'm still having problem. the original code is:
searchclicks.php:

Code: Select all

<?php
include 'global.php';
$keyword=$_SESSION['q'];
$publisher=clean($_GET['publisher']);
$advertiser=clean($_GET['advertiser']);
$listing=clean($_GET['listing']);

$price=getcost($keyword,$listing);

$sql2="SELECT * FROM advertiser WHERE id='$advertiser' ";
$result2=mysql_query($sql2) or die (mysql_error());
$row2=mysql_fetch_array($result2);
$advertiserbalance=$row2['balance'];
if ($advertiserbalance<$price) echo "The advertiser does not have enough balance in his/her account";
else{
$advertiserbalance-=$price;
$sql3="SELECT * FROM publisher WHERE id='$publisher' ";
$result3=mysql_query($sql3) or die (mysql_error());
$row3=mysql_fetch_array($result3);
$publisherbalance=$row3['balance'];
$price=$price*3/4 ;
$publisherbalance+=$price;
$sqlu1= "UPDATE advertiser SET balance='$advertiserbalance' WHERE id='$advertiser'";
$resultup1=mysql_query($sqlu1) or die(mysql_error()) ;
if (!$resultup1) echo "There was a problem during the analysis. Please contact us to inform aout the issue";
else{
$sqlu2= "UPDATE publisher SET balance='$publisherbalance' WHERE id='$publisher'";
$resultup2=mysql_query($sqlu2) or die(mysql_error()) ;
$sql4="SELECT * FROM listing WHERE id='$listing' ";
$result4=mysql_query($sql4) or die (mysql_error());
$row4=mysql_fetch_array($result4);
$url=$row4['url'];
//var_dump($row4);

//header("Location : $url");
//header('Location: '.$url); 
echo "<script> window.parent.ifrmTEXTFRNewWin('$url')</script>";
}
}
?>
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

why cant you use

Code: Select all

header('Location: '.$url);
Last edited by maliskoleather on Thu Sep 20, 2007 1:04 am, edited 1 time in total.
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post by ReDucTor »

maliskoleather, he said he was using that but it wouldnt work.

m2babaey, is the message you get headers already sent? if so look at where they are already sent, and fix it.
User avatar
kreoton
Forum Commoner
Posts: 42
Joined: Fri Mar 03, 2006 7:27 pm

Post by kreoton »

You should use

Code: Select all

header('location:' .$url);
if you get error that headers already sent move header up to the script, because code after header() function is not stopped ;)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Some things..

If you're using a closing php tag (?>) in your include file, make sure there's no space or new lines after it.
What's your URL look like that you're trying to go to?
Make sure to call exit or die after you send the header (otherwise your script tag will run and mess up the header() call)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

none of above worked
please visit this link tho see what happens and click on one of the ad links:
http://www.php.jothost.com/adsense/test.php
I need something to move the page out of the iframe. in that page i'm using header( 'Location: ' .$url ) ; other codes didn't work though
Zeyber
Forum Newbie
Posts: 16
Joined: Wed Sep 26, 2007 9:23 pm

Post by Zeyber »

Use this:

echo '<script> location.href = "location.html"; </script>';

Its a Java code
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Post by m2babaey »

Zeyber wrote:Use this:

echo '<script> location.href = "location.html"; </script>';

Its a Java code
that's loading the destination url in the iframe again. in addition, how do i write the code with $url instead of location.html to avoid parse errors?
how can i load the page in full screen?
Post Reply