Call php within HTML.. Working, but....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RichGags
Forum Newbie
Posts: 9
Joined: Tue Jan 04, 2005 8:13 pm

Call php within HTML.. Working, but....

Post by RichGags »

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Ive made my own invisible counter for my site...by combining a couple of php scripts Ive found on the net.  Sorry if I sound like a dope, but Im a real novice with php.

Code: Select all

<?php
$tempo = $HTTP_COOKIE_VARSї'tempo'];
$file = "counter.dat"; 
if (!$tempo){
  $count = implode('',file($file)) + 1;
  if(!($fp = fopen($file, "w"))) die ("Cannot open $file.");
  fwrite($fp, $count);fclose($fp);
  if ($_REQUESTї"show"]) echo "You're visitor Number <b>$count</b>.";
  // ------------------------------------------------
  } 
else { echo "You're cookied.";} // I put this in just to test the cookie.

?>
and..... to set the cookie, I used setcookie.php which looks like this:

Code: Select all

<?php
$value = 'something from somewhere';

setcookie("main", $value);
setcookie("main", $value, time()+3600);  /* expire in 1 hour */
setcookie("main", $value, time()+3600, "/", ".mydomain.com", 1);
?>

Ive included this in my index.html page to call the php files:

Code: Select all

<img src="counter.php" height="1" width="1" border="0">
<img src="setcookie.php" height="1" width="1" border="0">
Its working fine, but is this the proper programming etiquette way to call php files? I dont know if img src tags were meant for this...

BTW, The counter works great...its invisible. If anyone want to use it, please do. Just make sure you upload counter.dat in ascii and chmod it to 777.

Thanks!


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

both are returning non-images. So there is a problem in that a browser will have broken images for those two. Since neither are actually doing anything more than returning headers, just include them directly in the actual script: [php_man]include()[/php_man]
RichGags
Forum Newbie
Posts: 9
Joined: Tue Jan 04, 2005 8:13 pm

Post by RichGags »

Thanks for your help, Im sorry but I dont understand. Where do I put the include()??? In my HTML?

The img src tags are working. They will set the cookie and update the counter.dat. Dont ask me how, but it works. :)

But within index.html, what do I write and where? Thanks,
RIch

PS: Sorry about the code posting...didnt know how. Now I do :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sure, the scripts get called. But they don't return an image... which actually makes a broken image.. try it, make the image tags 100x100. Anyways, what I'm suggesting is make the page a php file. Then include the 2 scripts at the top, being the only php in the file.
RichGags
Forum Newbie
Posts: 9
Joined: Tue Jan 04, 2005 8:13 pm

Post by RichGags »

Ahhhhh.... Now I see what you mean. I guess setting the img height and width to 1 with no border will just make the broken box appear invisible. Sneaky Sneaky.

Thanks!
Post Reply