PDA

View Full Version : Click code PHP



GpF
31 Jan 2011, 12:47 PM
Hi!

Can anyone help me to change the php code.

What is the correct code with full url in click line?

<a href="?click=yes">clickMe</a>


<?php
if(!file_exists('counter.txt')){
file_put_contents('counter.txt', '0');
}
if($_GET['click'] == 'yes'){
file_put_contents('counter.txt', ((int) file_get_contents('counter.txt')) + 1);
header('Location: ' . $_SERVER['SCRIPT_NAME']);
die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>counter example</title>
</head>
<body>
<h1><?php echo file_get_contents('counter.txt'); ?></h1>


<a href="?click=yes">clickMe</a>


</body>
</html>

resdog
31 Jan 2011, 02:35 PM
it would be the folder structure/file name you are on now. For example, this page's URL is:

http://www.mysite.com/welcome/entertext.php

Then the href for what you have would be:

<a href="entertext.php?click=yes">

or you could do
<a href="/welcome/entertext.php?click=yes">

or you could put in the entire website:
<a href="http://www.mysite.com/welcome/entertext.php?click=yes">