Current location: Hot Scripts Forums » Programming Languages » PHP » newbie help with php code


newbie help with php code

Reply
  #1 (permalink)  
Old 05-10-06, 08:44 AM
ashwelljames ashwelljames is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
newbie help with php code

i have downloaded a php script that uses a mysql database.
i managed to install it no problem and change a few of the grapics files as it seemed alot like html.

i wanted to install a counter on the site and one i downloaded said to create a text file which i did then it says put the script in the page you want it to be displayed.

heres the problem index.php looks nothing like a index.html and i dont know where to put it.

any help would be great thanks
Reply With Quote
  #2 (permalink)  
Old 05-10-06, 08:49 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
could you post the index.php page?
it's rather hard to say where to put it when you don't know what coding there is

probably the entire html output is generated by php, so you could just place it on top of the script. or at the bottom, as long as you don't place it somewhere in between.

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #3 (permalink)  
Old 05-10-06, 10:08 AM
ashwelljames ashwelljames is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
here is the index.php

this is what is in the main program index.php file

PHP Code:

<?php 


require_once('config.php');
require_once(
'grid.class.php');

// handle magnifier toggle
if (isset($_REQUEST['magnify'])) {
  
$_SESSION['magnify'] = !empty($_REQUEST['magnify']);
  
$app->redirect();
}

// handle clickthrough
if (isset($_REQUEST['r'])) {
  require_once(
'region.class.php');
  
$tbl = new Region;
  
$region $tbl->get($_REQUEST['r'], false);
  if (
is_null($region->id()) || $region->status != REGION_ACTIVE)
    
$app->redirect();
  
$region->clicks++;
  
$region->save();
  
header("Location: " $region->url);
  exit;
}

$tbl = new Grid;
$grids $tbl->find_all('order by display_order');
$pixels_avail 0;
$pixels_used 0;
foreach (
$grids as $k => $grid) {
  
$pixels_used += $grid->pixels_used;
  
$pixels_avail += $grid->width $grid->height $grid->pixels_used;
}

$smarty->assign('pixels_avail'$pixels_avail);
$smarty->assign('pixels_used'$pixels_used);
$smarty->assign('grids'$grids);
$smarty->display('index.tpl');

?>

Last edited by Christian; 05-10-06 at 12:36 PM.
Reply With Quote
  #4 (permalink)  
Old 05-10-06, 10:15 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
does your counter script require something from the coding that is in the index page?
if not, just past it on top of the page

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 05-10-06, 11:30 AM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
The "HTML version" of your page is index.tpl. You are using smarty, so all of your program logic is in the php file and all of the layout (html, etc.) is in the tpl (template) file.

So, if your counter is a php script, you'll need to run it in the php page and then assign the output as a variable to smarty. If it is javascript code, then you should be able to just paste it into the tpl file.

HTH
Reply With Quote
  #6 (permalink)  
Old 05-10-06, 04:37 PM
ashwelljames ashwelljames is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
well i dowloaded the main script from the internet and followed the instructions to install it. compaired to simple html its seems totally different. so i dont know where to put the counter code . html would be easy id just put it in the html anywhere. php seem to have no logic to me. is index the start page when a web address is looked at?

here the script i want to add

Hit Counter

This script gives you all required code to add a simple hit counter onto your webpage, with the option to make it invisible.

PHP Code:

<?php


/**
* The counter.txt file stores the information for the hits
* All you need to do is upload the counter.txt file and 
* the counter.php file to your website and then

* Add this line of code on your page to be counted:
* <?php include "counter.php"; ?>
*/

$fp fopen("counter.txt""r");
$count fread($fp1024);
fclose($fp);
$count $count 1;

// Display the number of hits
echo "Page views:" $count "";
// To disable output to webpage quote the above line using //

$fp fopen("counter.txt""w");
fwrite($fp$count);
fclose($fp);

?>
Reply With Quote
  #7 (permalink)  
Old 05-10-06, 04:55 PM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
This should work...

Change your index.php file to this:

PHP Code:

<?php 


require_once('config.php');
require_once(
'grid.class.php');

// handle magnifier toggle
if (isset($_REQUEST['magnify'])) {
  
$_SESSION['magnify'] = !empty($_REQUEST['magnify']);
  
$app->redirect();
}

// handle clickthrough
if (isset($_REQUEST['r'])) {
  require_once(
'region.class.php');
  
$tbl = new Region;
  
$region $tbl->get($_REQUEST['r'], false);
  if (
is_null($region->id()) || $region->status != REGION_ACTIVE)
    
$app->redirect();
  
$region->clicks++;
  
$region->save();
  
header("Location: " $region->url);
  exit;
}

$tbl = new Grid;
$grids $tbl->find_all('order by display_order');
$pixels_avail 0;
$pixels_used 0;
foreach (
$grids as $k => $grid) {
  
$pixels_used += $grid->pixels_used;
  
$pixels_avail += $grid->width $grid->height $grid->pixels_used;
}


/**
* Get the hit count.
*/
$fp fopen("counter.txt""r");
$count fread($fp1024);
fclose($fp);
$count $hitcounter 1;
$fp fopen("counter.txt""w");
fwrite($fp$hitcounter);
fclose($fp); 


$smarty->assign('pixels_avail'$pixels_avail);
$smarty->assign('pixels_used'$pixels_used);
$smarty->assign('grids'$grids);
/**
*assign the variable in smarty
*/
$smarty->assign('hit_counter'$hitcounter);
$smarty->display('index.tpl');

?>
And then in your index.tpl file, wherever you want the count to show up, add:
PHP Code:

{$hit_counter|default:"counter unavailable"
That should do it.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I insert PHP code into HTML ?? cc79 HTML/XHTML/XML 5 04-12-08 11:00 AM
Conception of you php code gigi_online Job Offers & Assistance 5 10-01-05 06:35 PM
Trying to echo PHP code from SQL and run it. And failing. Sheldon PHP 4 08-01-05 11:22 AM
newbie: form-to-mail php script merc1 Script Requests 2 03-03-05 09:57 PM
Use this code outside of PHP tags? D_tunisia PHP 6 04-12-04 12:06 PM


All times are GMT -5. The time now is 07:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.