Activity Stream
48,167 MEMBERS
65066 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 7 of 7
  1.     
    #1
    Member

    Default [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

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    facebook.com
    ...not really, dont follow
    All right everyone, line up alphabetically according to your height.

  4.     
    #3
    Member
    Website's:
    felonygames.com
    Im 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;

    ?>



  5.     
    #4
    Member
    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
    it would do

    Code: 
    <?php 
    $load = file_get_contents("load.txt"); 
    $load = $load + 1; 
    $opentxt = fopen("load.txt", "w"); 
    fwrite($opentxt, $load); 
    fclose($opentxt); 
    
    print $load; 
    
    ?>
    and if i done

    Code: 
    http://www.site.com/example.php?type=decrease
    it would do

    Code: 
    <?php 
    $load = file_get_contents("load.txt"); 
    $load = $load - 1; 
    $opentxt = fopen("load.txt", "w"); 
    fwrite($opentxt, $load); 
    fclose($opentxt); 
    
    print $load; 
    
    ?>
    but i want to be able to tell the .php file whether or not to increase or decrease the number.

    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.

  6.     
    #5
    You 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

  7.     
    #6
    Member
    Website's:
    somik.org sborg.us
    PHP 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");

  8.     
    #7
    Member
    thank you somik it works like a charm, exactly what i wanted.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 3rd Apr 2012, 09:50 AM
  2. [Hiring] Somenone to code simple batch script
    By STiNKY in forum Completed Transactions
    Replies: 0
    Last Post: 8th May 2011, 12:42 PM
  3. [Hiring] $10 for a simple piece of code [URGENT]
    By kohkindachi in forum Completed Transactions
    Replies: 1
    Last Post: 19th Nov 2010, 01:30 PM
  4. [vBulletin BB Code] Moderated Message: (Like W-BB's Staff BB Code!)
    By Ghost Dog 13 in forum Webmaster Resources
    Replies: 13
    Last Post: 26th Sep 2009, 06:19 PM
  5. PHP/HTML : Simple Ad Poll Code
    By Pyro in forum Tutorials and Guides
    Replies: 4
    Last Post: 11th Aug 2009, 05:50 AM

Tags for this Thread

BE SOCIAL