DotDragnet
May 24, 2012, 08:19:57 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: really simple php function... I think  (Read 158 times)
fordie
Global Moderator
Sr. Member
*****
Posts: 329


<span id="attention" class="short">...</span>


View Profile Awards
« on: November 16, 2011, 10:42:37 AM »

folks I want to knock up a page that users can visit to find out the status of something. It only really needs to return "yes" or "no". Users also need to be able to toggle the status by clicking a link so that other users can see it. I imagin the page markup would look like this:

Code:
<body>
    <h1>No</h1>

<a href="?status=yes">set status to yes</a>
</body>

I guess the easiest way to do this would be to have a txt file on the server which php can update when a user clicks a link. The trouble is I have no idea how to do this. Any pointers would be greatly appreciated.
Logged
JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #1 on: November 16, 2011, 11:19:03 AM »

Code:
<?php
if (isset($_GET['status']) && ($_GET['status'] == 'yes' || $_GET['status'] == 'no')) {
    
file_put_contents('./status'$_GET['status']);
    
$status $_GET['status'];
} else {
    
$status file_get_contents('./status');
}
if (
$status == 'yes') {
?>

<h1>Yes</h1>
<a href="?status=no">set status to no</a>
<?php } else { ?>
<h1>No</h1>
<a href="?status=yes">set status to yes</a>
<?php ?>
You'll have to create the ./status file (and maybe call it something else) and make it writable.
Logged
fordie
Global Moderator
Sr. Member
*****
Posts: 329


<span id="attention" class="short">...</span>


View Profile Awards
« Reply #2 on: November 16, 2011, 11:42:52 AM »

Perfect! Thanks Jason
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!