Forum Moderators: coopster

Message Too Old, No Replies

Ad Rotator Script

Fatal error: Call to a member function on a non-object

         

Jeigh

7:16 am on Jul 7, 2007 (gmt 0)

10+ Year Member



I found this script on the net for an ad rotator, aswell as displaying the banners it also records clicks, views etc.

I've been trying things for weeks now, searched thoroughly in google many times but can not find the answer. Here is the script:

// Check to see if the banner ID flag is set
if(isset($_bannerID)) {

// Create an instance of the Database Layer

$DB = new DB_BANNER;

// Get info about banner from DB

$DB->query("SELECT * FROM banner
WHERE(uniqueid=$_bannerID)");

// Check to see if Banner ID is valid before doing
// anything else

if($DB->num_rows()!= 0) {

// Increment Click Counter

dbIncClks($_bannerID);

// Redirect user to new location, $_query_extra
// is the Extra parameters that were given to the
// script back in dbShowBan(). This feature is
// for if you want a banner on your own site, to
// your own site, but use sessions and don't want
// the user to lose their session when they
// click.

$url = $DB->f("URL"). $_query_extra;
Header("Location: $url");

}


}

function Display_Banner($bannerID = "none",
$query_extra = "") {

// Grab the Database Layer and the Config options

global $DB, $_bannercfg, $PHP_SELF;

// Did we pass a BannerID?

if($bannerID == "none") {

// If Not, Grab the next in rotation

// First, make sure that there is something to select

$DB->query("SELECT * FROM banner WHERE pos=''
LIMIT 1"); /* L I N E 8 2*/

// If there is nothing, then everything has
// been displayed
// Time to start from square 1

if($DB->num_rows() == 0) {

$DB->query("UPDATE banner SET pos='' WHERE(pos='A')");

}

// Finally, select the next banner

$DB->query("SELECT * FROM banner WHERE(pos='')
ORDER BY b_order LIMIT 1");


} else {

// If so, Grab the requested Banner

$DB->query("SELECT * FROM banner
WHERE(ID='$bannerID')");


}

// Make sure we grabbed something

if($DB->num_rows() == 0) {

return false;
}

$DB->next_record();

// Saved the data we got in a separate array

$ban_data = $DB->Record;

// Construct the HTML for the GET

$get = "?_bannerid=".urlencode($ban_data['ID']);

// Make the extra query string

if(is_array($query_extra)) {

foreach($query_extra as $key => $val) {

$get .= "&$key=".urlencode($val);

}

}

// Construct the HTML for the banner and include the GET // we constructed previously.

$html = "<a href='$PHP_SELF$get' target=\"_blank\">"
. "<img src='$_bannercfg[srcpath]$ban_data[SRC]' "
. "alt='$ban_data[ALT] "
. "border='$_bannercfg[border]'>"
. "</A>";

// Increment the hits
dbIncHits($ban_data['ID']);

// Flag the banner used as displayed (if it was selected
// by rotation) In special cases, we're not going to flag
// anything

if($bannerID == "none") {

$DB->query("UPDATE banner SET pos='A'
WHERE(ID='".$ban_data['ID']."')");

}

// Finally, echo the HTML

echo $html;

// Return True

return true;

}

function dbIncClks($_bannerID) {

global $DB;

$DB->query("SELECT clicks FROM banner
WHERE(ID='$_bannerID')");

if($DB->num_rows() == 0) {

return false;

}

$DB->query("UPDATE banner SET clicks=".($DB->f('clicks')+1)." WHERE(ID='$_bannerID')");

}

function dbIncHits($_bannerID) {

global $DB;

$DB->query("SELECT hits FROM banner
WHERE(ID='$_bannerID')");

if($DB->num_rows() == 0) {

return false;
}

$DB->query("UPDATE banner SET hits=".($DB->f('clicks')+1)." WHERE(ID='$_bannerID')");

}

And I get the following area:

Fatal error: Call to a member function on a non-object in /home/.../public_html/adrotator.php on line 82

On the page I want it to display I am including this file and using:
display_banner();

Thanks.

eelixduppy

1:41 pm on Jul 7, 2007 (gmt 0)



Can you please tell us which is line 82.

[edit]

Try this instead:


$DB->display_banner();

Jeigh

2:00 pm on Jul 7, 2007 (gmt 0)

10+ Year Member



Thanks for the advice, I tried that and get:

Fatal error: Call to a member function on a non-object in /home/graphics/public_html/header.php on line 57

Code:

<? include('adrotator.php');
$DB->display_banner(); ----------Line 57
?>

On the first post I just wrote Line 82 next to line 82 (probably a bit hard to find) So this is it:

$DB->query("SELECT * FROM banner WHERE pos=''
LIMIT 1");

henry0

6:21 pm on Jul 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jan 18/07 the same problem was reported in ZEND php forum, looks like the script was also posted in ZEND.
the user mentioned something about php.ini and .htaccess
did you follow the instructions?

Jeigh

4:15 am on Jul 8, 2007 (gmt 0)

10+ Year Member



I've read the instructions over a few times carefully and I'm pretty sure I've done what it said, but just incase I'll give it another read today.

Jeigh

9:35 am on Jul 8, 2007 (gmt 0)

10+ Year Member



I found the php.ini bit you were talking about, but I'm not exactly sure how this works so from the information given I just made a file called php.ini that contained:

auto_prepend_file adrotator.php

Hopefully theres an error in the way I've done that there because I'm still getting the same message. So hopefully someone can tell me if I've done that right.

Thanks for everyones help so far.

henry0

11:47 am on Jul 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now we are making progress; sort of :)
php.ini is a config file inherent to PHP
You can not create such a file.

“PHP is presently the most popular scripting language in use on the Internet”

But you could access it via your server
<edit>
If you do not know how to do it, you should not try without asking if you are in the right direction.
First make a backup of the php.ini.
</edit>
If you are in a shared server environment you are probably not entitled to such access and modification.
You will need to contact your host and ask them about.

The bit about .htaccess is probably linked to the same alteration that might be performed out of .htaccess
thus not requiring you to edit the PHP.INI

Jeigh

11:54 am on Jul 8, 2007 (gmt 0)

10+ Year Member



So I can just edit my .htaccess file on the FTP and add:

auto_prepend_file adrotator.php

?

Thanks.

henry0

3:33 pm on Jul 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, depending on how your .htaccess may interact you could give it a try
However the file location will not be defined as
auto_prepend_file adrotator.php
but upon its location based on the server file directories.
possibly starting by /usr/this/that/adrotator.php
you might need to place a call to your isp
to figure it out.

Jeigh

3:46 pm on Jul 8, 2007 (gmt 0)

10+ Year Member



Thanks, before I try this again I probably should ask how to edit the .htaccess file properly.

The first time I opened it up, edited and saved as .htaccess from notepad. This saved it has .htaccess.txt so in the FTP I just took out the .txt. extension, however that messed up somthing. I kept getting a 403 Access Forbidden Error which I could not get rid of.

After contacting my provider it was fixed, but when I tried to add password protection again it did the same thing. Again I contacted them and they fixed another problem and it works fine now.

So before I try it again I thought I should ask. :)

henry0

4:59 pm on Jul 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As always do a copy of it and save it; one) on your local machine
and two) before uploading the new one rename the previous one .htaccess_OLD
so you will be safe and will have two ways of resetting your previous default
Read this [httpd.apache.org]

comments in .htaccess are done like this
####my comments aaaa bbbb ##########

respect any previous provider addition, they help running your sector.

and now give it a try.
do you hace the correct path handy?

php_value auto_prepend_file "/your path/your file"

Jeigh

12:44 am on Jul 9, 2007 (gmt 0)

10+ Year Member



I believe the path to it is /home/graphics/public_html/adrotator.php

Edit:

I edited it properly and uploaded, this being the full file:

AuthType Basic
AuthName "Site Construction"
AuthUserFile "/home/graphics/.htpasswds/passwd"
require valid-user
auto_prepend_file adrotator.php

and got the following error:

500 server error
I encountered an unrecoverable server error. Please go back and try again.

[edited by: Jeigh at 12:52 am (utc) on July 9, 2007]

henry0

11:27 am on Jul 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is what you need to try:

php_value auto_prepend_file /home/graphics/public_html/adrotator.php

php_value is part of it.

Jeigh

4:31 pm on Jul 9, 2007 (gmt 0)

10+ Year Member



Thanks! I get the feeling it's just about done now (no more server errors from the .htaccess) however I am getting this error now:

"Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/graphics/public_html/adrotator.php:207) in /home/graphics/public_html/header.php on line 1"

header.php line 1:

<? session_start();

and line 207 on adrotator.php is:

?>

henry0

5:51 pm on Jul 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it means that
your session and other script segments related to session NEED to be "served" BEFORE any actual kinf of echo"..." or any HTML output

without looking at the whole thing it will not be easy to find what causes it

you could resolve the problem by turning OB On (output buffering)

but since it seems that you may not modif php.ini you might ask you ISP to turn on OB

OR
add a new line in .htaccess

php_value output_buffering On