Results 1 to 7 of 7
-
18th May 2011, 03:24 AM #1OPMember
[SOLVED]in need of simple php code.
I need just a simple php code, its probly only a few lines of code.
anyways, here's what i need.
i need a php script in which i visit and it will INCREASE or DECREASE 1 number.
example URL would be.
site.com/example.php?type=inc
^^ that would increase my number by one
site.com/example.php?type=dec
^^ that would decrease my number by one.
i would prefer it be a POST instead of a GET request so this cannot be abused as much.
by default the number would be 0 of course.
i would like to be able to use this file so i can use it on a webpage to display the number.
so i could do something like
The number is: <? include(example.php) ?>
and would would display something like
The number is: 9
hopefully you understand what im saying.DeJay Reviewed by DeJay on . in need of simple php code. I need just a simple php code, its probly only a few lines of code. anyways, here's what i need. i need a php script in which i visit and it will INCREASE or DECREASE 1 number. example URL would be. site.com/example.php?type=inc ^^ that would increase my number by one Rating: 5
-
18th May 2011, 04:23 AM #2MemberWebsite's:
facebook.com...not really, dont follow
All right everyone, line up alphabetically according to your height.
-
18th May 2011, 04:32 AM #3MemberWebsite's:
felonygames.comIm sure i could do this if you explain better.
Something like this?
<?php
$load = file_get_contents("load.txt");
$load = $load + 1;
//$load = $load - 1; comment out above and uncomment this to subtract
$opentxt = fopen("load.txt", "w");
fwrite($opentxt, $load);
fclose($opentxt);
print $load;
?>
-
18th May 2011, 04:40 AM #4OPMember
you have the right idea, only i want it to do both in the same file.
here is what i mean.
if i open the link
Code:http://www.site.com/example.php?type=increase
Code:<?php $load = file_get_contents("load.txt"); $load = $load + 1; $opentxt = fopen("load.txt", "w"); fwrite($opentxt, $load); fclose($opentxt); print $load; ?>
Code:http://www.site.com/example.php?type=decrease
Code:<?php $load = file_get_contents("load.txt"); $load = $load - 1; $opentxt = fopen("load.txt", "w"); fwrite($opentxt, $load); fclose($opentxt); print $load; ?>
im going to bed now, but i think i know enough php i might be able to finish the rest, but if someone that's better in php gets to it before me it would be greatly appreciated.
i think the rest that is needed to do what i want to do is just simple IF statements.
-
18th May 2011, 04:55 AM #5You can call me G
Since you're getting the parameters by GET use $_GET to set a condition
My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz
-
18th May 2011, 04:56 AM #6MemberWebsite's:
somik.org sborg.usPHP Code:<?php
/**
* @author Somik Khan
* @copyright 2011
*/
// Enter the name of the file which the count is stored to
$filename = "counter.txt";
// Get action from $_GET['type'] or $_POST['type'] variable
$action = $_POST['type'];
// Load the file into $visit file
$visit = file_get_contents($filename);
// Remove garbase data and only keep the integer value of visit
$visit = intval($visit);
if($action == "increase"){
$visit++;
file_put_contents($filename,$visit);
}
elseif($action == "decrease"){
$visit--;
file_put_contents($filename,$visit);
}
echo $visit;
?>
Usage:
Code:To increase: Go to: http://www.site.com/example.php?type=increase OR post "type" with value "increase" to example.php To decrease: Go to: http://www.site.com/example.php?type=decrease OR post "type" with value "decrease" to example.php To display, just add: include("example.php");
-
18th May 2011, 02:28 PM #7OPMember
thank you somik it works like a charm, exactly what i wanted.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Help With Letitbit Js To BB Code aka Embedding streaming code in forums
By JoomlaZ in forum Web Development AreaReplies: 1Last Post: 3rd Apr 2012, 09:50 AM -
[Hiring] Somenone to code simple batch script
By STiNKY in forum Completed TransactionsReplies: 0Last Post: 8th May 2011, 12:42 PM -
[Hiring] $10 for a simple piece of code [URGENT]
By kohkindachi in forum Completed TransactionsReplies: 1Last Post: 19th Nov 2010, 01:30 PM -
[vBulletin BB Code] Moderated Message: (Like W-BB's Staff BB Code!)
By Ghost Dog 13 in forum Webmaster ResourcesReplies: 13Last Post: 26th Sep 2009, 06:19 PM -
PHP/HTML : Simple Ad Poll Code
By Pyro in forum Tutorials and GuidesReplies: 4Last Post: 11th Aug 2009, 05:50 AM
themaLeecher - leech and manage...
Version 5.06 released. Open older version (or...