Page 1 of 1

[Solved] Anything Following .php?blah... Doesn't Work?!

Posted: Sun Feb 06, 2005 11:46 pm
by iamkoa
I have a weird problem.

It seems my PHP doesn't work when executing code following a question mark. Take for example, the following php code... as far as i can tell, it all looks fine.

Code: Select all

<?php
// links coded like this:
//<a href="out.php?site=http://juicystudio.com">Visit Juicy Studio</a>

### Define variables
$yoursite = "http://www.iamkoa.net/links/";

### Define database values
$dbhost = "localhost";          // database host
$dbuser = "----";          // database username
$dbpassword = "----";      // database password
$db2use = "----";          // name of database

function dbconnect() 
&#123;
    global $dbhost, $dbuser, $dbpassword, $db2use;
    $link = @mysql_connect($dbhost,$dbuser,$dbpassword) 
        or die("Connection failed: Please try later.");
    @mysql_select_db($db2use,$link) 
        or die("Connection to database refused: Please try later.");
    return $link;
&#125;
// Connect to database
dbconnect();
if (!empty($site)) 
&#123;
    $qry = "SELECT hits FROM links WHERE site = '$site'";
    $hitcounter = mysql_query($qry);
    $hitcount = mysql_fetch_array($hitcounter);
    $hits = $hitcount&#1111;0];
    // next check if URL is in database
    if ($hits == 0) 
    &#123;
        //  if not then add it!
        $newurl = "INSERT INTO links (site,hits) VALUES('$site',1)";
        // Site already exists so just update the hit count
        $newurl = "UPDATE links SET hits=$hits+1 WHERE site='$site'";
    mysql_query($newurl);
    mysql_close();
    // re-direct to the required site as defined in the "out.php?site=" link
    header ("Location: $site");
    exit;
&#125;
else 
&#123;
    // site variable not entered, so redirect back to "yoursite" as defined above
    header ("Location: $yoursite");
    exit;
&#125;
?>
The database connects fine. The URL is retreived from the database correctly, etc. Everything SHOULD work, but instead of directing the viewer to the given website ($site), he/she is directed to $yoursite.

Here's an example:
http://www.iamkoa.net/links/out.php?sit ... adplus.com

The website above is in the proper MySQL database and table. Everything should work...

Any ideas of what's happening? Is this a PHP.ini problem?

Posted: Sun Feb 06, 2005 11:50 pm
by feyd
looks like you wrote this with register_globals being on, and you don't have them on at your server. Not having register_globals on is a good thing, btw.

You can access the data via

Code: Select all

$site = (!empty($_GET&#1111;'site']) ? $_GET&#1111;'site'] : '');

Posted: Mon Feb 07, 2005 12:32 am
by iamkoa
You got it! Thanks a lot for your help feyd... you're a life-saver!