Link to home
Start Free TrialLog in
Avatar of olivierarbez
olivierarbez

asked on

Script not working with Firefox but working ok with IE

Hi, the following work well with IE but not for Firefox.

When you select a link the following code get called and log the hit from the url then redirect to the url selected.
With firefox a black page with Redirecting show up with the url but you have to click on it to go there.

I would like go directly to the url with having to click on the link.

Thank You.



<html><body text=#ffffff bgcolor=000000 onLoad="javascript:document.links[0].click();">
<?
# pointer.php
# passed vars: g
# this page will redirect a user to the specified url
#
# NOTE: $g can only be accessed if register globals is turned on (not suggested)
$destination = base64_decode(urldecode($_GET['g'])); // $_GET['g']);

// find the link in the video table so we can log the hit...
// j require_once 'init/nom_var.php';
// j require_once 'init/init.php';
require_once ($DOCUMENT_ROOT . "/init/nom_var.php");
require_once ($DOCUMENT_ROOT . "/init/init.php");
$sql = 'SELECT
            VI_ID,
            VI_category
        FROM
            video
        WHERE
            VI_url = \'' . addslashes($destination) . '\'';
$query = mysql_query($sql);
$rowID = @mysql_result($query, 0, 0);
$category = @mysql_result($query, 0, 1);

if (preg_match('/^\d+$/', $rowID)) {
    // A valid record was found.  Now log the hit
    $sql = 'INSERT INTO video_access_log (
                VAL_VI_ID,
                VAL_category,
                VAL_lang,
                VAL_accessdate)
            VALUES(
                ' . $rowID . ',
                \'' . addslashes($category) . '\',
                \'eng\',
                NOW())';
    $query = mysql_query($sql);
}
?>
<a name=redirect href="<? echo $destination; ?>"> Redirecting...</a>
 </body></html>
Avatar of kamermans
kamermans

Try this:

<html><body text="#ffffff" bgcolor="000000">
<?php
# pointer.php
# passed vars: g
# this page will redirect a user to the specified url
#
# NOTE: $g can only be accessed if register globals is turned on (not suggested)
$destination = base64_decode(urldecode($_GET['g'])); // $_GET['g']);

// find the link in the video table so we can log the hit...
// j require_once 'init/nom_var.php';
// j require_once 'init/init.php';
require_once ($DOCUMENT_ROOT . "/init/nom_var.php");
require_once ($DOCUMENT_ROOT . "/init/init.php");
$sql = 'SELECT
            VI_ID,
            VI_category
        FROM
            video
        WHERE
            VI_url = \'' . addslashes($destination) . '\'';
$query = mysql_query($sql);
$rowID = @mysql_result($query, 0, 0);
$category = @mysql_result($query, 0, 1);

if (preg_match('/^\d+$/', $rowID)) {
    // A valid record was found.  Now log the hit
    $sql = 'INSERT INTO video_access_log (
                VAL_VI_ID,
                VAL_category,
                VAL_lang,
                VAL_accessdate)
            VALUES(
                ' . $rowID . ',
                \'' . addslashes($category) . '\',
                \'eng\',
                NOW())';
    $query = mysql_query($sql);
}
javascriptRedir($destination,2); //set the number to 0 to redirect immediately

function javascriptRedir($page, $seconds){
      $time = $seconds * 1000;
      echo "<br><br>You will be redirected to <a href='$page'>$page</a> in $seconds seconds...";
      echo '<script language="javascript">'."\n".'setTimeout('."'".'window.location.href = "'.$page.'"'."'".', '.$time.');'.'</script>';
}
?>
 </body></html>
Avatar of olivierarbez

ASKER

The script is working but could you please remove the time function  so it redirect right away (I am aware that 0 will redirect immediately).

Thank you
SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Both of the solution works. I will have to Split points.

Is it possible to add a referrer variable to a header? like $referrer that would be sent with the URL $destination.

Thank you.

-O-
$ref = urlencode($_SERVER['HTTP_REFERRER']);
header("Location: $destination?ref=$ref");

Then just use this to get the referrer back in the next script: $ref = urldecode($_GET['ref']);
Thank you for your great help.

-O-