Jump to content

Recommended Posts

Hey, let me start by saying my knowledge of php is exactly = 0

so if anything i state is extremely noobish please forgive me, the guy who usually writes my scripts cant do it atm.

 

Im looking to get a script that will show one of 2 status' in text form on a page (most likely in an iframe).

I want the status to be able to be changed by hitting a button located directly below it.

eg:

 

This orange text will be displayed and below it, the button.

(-BUTTON-)

 

And when i press the button, it changes to:

 

This green text will be displayed and below it, the button.

(-BUTTON-)

 

NOW! This i have been told is really easy, BUT! i want it to be able to stay on the current specified status even after the page is refreshed or accessed at a different time.

Now if this requires sql stuff then it will suck, but im hoping theres some php that can be split into 2 files and one can be updated by the other based on the current status it contains.

 

Is this possible???

 

Heres a better example:

It starts as this...

status1.PNG

 

Then when the button is clicked:

status2.PNG

 

And it stays like that whether refreshed or revisited later...

Link to comment
https://forums.phpfreaks.com/topic/75743-status-button-thing/
Share on other sites

um.. wat are sessions?

 

Like i said i dont know anything about php, so names of functions are gonna confuse me lol

 

Is it easy to do something like this?

 

OH also!

It has to be able to show that status specified for anyone else viewing it. If it simply stored in a cookie then itll be only for my computer, when i want anyone that sees it to be able to know the status...

Link to comment
https://forums.phpfreaks.com/topic/75743-status-button-thing/#findComment-383334
Share on other sites

This looked easy but is not, anyway I got this one  ;D

 

<?php

$done = FALSE ; 
$text = "This is default";

if(isset($_REQUEST['check'])) 

{
        $text = "This is green";
	$done = TRUE ; 
	$mycss = "css_green";

}

if(isset($_REQUEST['check2'])) 

{
        $text = "This is orange";
	$done = FALSE ; 
	$mycss = "css_orange";

}


?>
<style type="text/css">
<!--
.css_green {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #66CC33;
}
.css_orange {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #FF9933;
}
-->
</style>


<table width="261" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <form name="check" method="post">
  <tr>
    <td width="261" height="112" valign="top" class="<?=$mycss?>"><?=$text?></td>
  </tr>
  <tr>
  <? if ($done != TRUE) { ?>
  
    <td height="76" valign="top">
      <input name="check" type="submit" id="check" value="Change Status" />
  <input type="hidden" name="hide" value="1" />
  </td>
  <? } else { ?>
   <td height="76" valign="top">
      <input name="check2" type="submit" id="check" value="Change Status" />
  <input type="hidden" name="hide" value="2" />
  </td>
  
  <? } ?>
  
    
  </tr>
  </form>
</table>

Link to comment
https://forums.phpfreaks.com/topic/75743-status-button-thing/#findComment-383367
Share on other sites

dude this is great, and exactly how i pictured it, its just it doesnt keep the status if i look at in a diff browser or close and reopen it...

 

It only shows the defualt then i have to set the status again...

 

How can i make it so when i set the status no matter where i view it from, diff comp, tab or browser, it stays the same until i change it again...??

Link to comment
https://forums.phpfreaks.com/topic/75743-status-button-thing/#findComment-383390
Share on other sites

Why not use an AJAX call to a php script that writes to a flat file?

 

Then, call up the flat-file, read it to determine current status.. Works on all browsers, no cookies, no sql, just basic php knowledge and a little AJAX on the side. (AJAX calls to a php script without going to a new page, imagine the process of submitting a form without actually doing so).

Link to comment
https://forums.phpfreaks.com/topic/75743-status-button-thing/#findComment-383976
Share on other sites

Of the top of my head... O_o

 

ajax_button.js

//Global XMLHttpObject variable

function request() {
var req = null;
if (typeof XMLHttpRequest != "undefined")
    req = new XMLHttpRequest();
if (!req && typeof ActiveXObject != "undefined")
{
    try
    {
        req=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {
        try
        {
            req=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e2)
        {
            try
            {
                req=new ActiveXObject("Msxml2.XMLHTTP.4.0");
            }
            catch (e3)
            {
                req=null;
            }
        }
    }
}
return req;
}

var span = document.getElementById("status_span");

function update_status() {
req1 = request();

if (req1==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }

    req1.onreadystatechange=change_status;

currtime = new Date().getTime();

    req1.open("GET","update.php?time="+currtime,true);//you may want to most likely put this file above the public_html so script can still access, but people can't
    req1.send(null);
}

function change_status(){
      if(req1.readyState==4)
        {
        if(req1.responseText){//returned true, so we update, else we alert an error
                if(span.style.color == "orange"){//orange text to green text
                        span.innerHTML = "show green text";
                        span.style.color = "green";
                } else {//green text to orange text
                        span.innerHTML = "show orange text";
                        span.style.color = "orange";
                }
        } else {
                window.alert("I'm sorry, we encountered an error with the processing, please try again later.");
        }
        }
      }

 

This code above will handle the AJAX.

 

update.php

<?php
if($_GET['update']){//it's true, else it's false
$file=fopen("status.txt",'r');
while($line = fgets($file)){//while we can still read the file
	$line=trim($line);//remove the line endings
	list($color,$message) = explode(':',$line);//$string[0] = $user, etc...
}

if($color == "orange"){$color = "green";$message = "green text here";} else {$color = "orange";$message="orange text here";}
$file=fopen("status.txt",'w');
$contents[] = "$color:$message\n";
foreach($contents as $data){
	fwrite($file,$data);
}
fclose($file);

return true;
?>

 

php page that has the html

<script type='text/javascript' src='ajax_button.js'>

<?php
//use php to get the current span status
echo '<span id="status_span" style="color:orange;">this is orange text</span>';
?>
<input type="button" onclick="update_span();" value="Change Button">

Link to comment
https://forums.phpfreaks.com/topic/75743-status-button-thing/#findComment-384146
Share on other sites

I pasted all of those codes into notepad and saved them as the right file (except the last which i placed in dreamweaver), but when i visit status.html that was made with the last thing and nothing shows up... is there a special way i have to view it or set it up?

 

Thanks alot btw, i really appreciate your help :)

Link to comment
https://forums.phpfreaks.com/topic/75743-status-button-thing/#findComment-384574
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.