Page 1 of 1

Redirect with mysql query

Posted: Sun Nov 16, 2008 3:43 pm
by kobitriki
Hi!
i want to create short url service website. (4url dot net)
currently unindexed IDs redirect to the main page except if the ID contains numbers only then its redirect to blank page.

the PHP code is(this is independent file which receive the ID from typed url):

Code: Select all

<?
 
 
ob_start();
include("config.php"); 
if(isset($_GET['id'])) {
    $gid = mysql_real_escape_string($_GET['id']);
    $qs = mysql_query("SELECT url FROM $table WHERE tag = '$gid';") or die('MySQL error: '.mysql_error());
    if (mysql_num_rows($qs) == 0) {
        $qs = mysql_query("SELECT url FROM $table WHERE `id` = $gid;") or die(header("Location: /"));
        mysql_query("UPDATE url SET count=(count + 1) WHERE `id` = $gid;") or die('MySQL error: '.mysql_error());
    } else
        mysql_query("UPDATE url SET count=(count + 1) WHERE `tag` = '$gid';") or die('MySQL error: '.mysql_error());
    while($data = mysql_fetch_array($qs)) {
        if ($frame == 1) {
            include("frame.php");
            echo "<iframe name=\"pagetext\" height=\"100%\" frameborder=\"no\" width=\"100%\" src=\"$data[0]\"></iframe>";
        } else if ($frame == 0) {
 
            if ( !preg_match( "/^http/", $data[0] ) ) {
                header("Location: http://$data[0]");
            } else {
                echo header("Location: $data[0]");
            }
        }
    }
}
 
ob_flush();
?>
hope some one can help on this,

Thanks
Kobi

Re: Redirect with mysql query

Posted: Sun Nov 16, 2008 3:54 pm
by Eran
You can't put array indexes inside double quotes. Use concatenation instead:

Code: Select all

 
if ( !preg_match( "/^http/", $data[0] ) ) {
        header("Location: http://" . $data[0]);
} else {
       header("Location: " . $data[0]);
}
 

Re: Redirect with mysql query

Posted: Sun Nov 16, 2008 4:10 pm
by Syntac
pytrin wrote:You can't put array indexes inside double quotes.
Yes you can. This may not be the case with string indexes, however.

Re: Redirect with mysql query

Posted: Sun Nov 16, 2008 4:20 pm
by Eran
This may not be the case with string indexes, however.
Yes, you are correct, my bad.

Try and dump the contents $data to see what it contains.