Jump to content

k00ld00dz

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

About k00ld00dz

  • Birthday 12/17/1989

Profile Information

  • Gender
    Male
  • Location
    Spokane, WA

k00ld00dz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hey, I have had this question myself. I needed to make a log of IP addresses that went on my site. The thing is that I wanted to make each new IP add a row of an existing table written in HTML. I had to 'chop' the variable(which included the entire HTML code) into a couple of parts(header, body and footer). The code breaks up the variable into sections and puts each section into an array. In my HTML file, I added an HTML comment "<!--break-->" which does nothing in the web browser when ran, but this is where the pieces get chopped up by the PHP code into sections. Then later I include the "<--break-->" comment again for further processing. This script works really good, It got me very excited when I actually did this the first time . Here is my PHP code:(look for the '$pieces = explode("<!--break-->", $ffh);' part, this is the code you need) <?php //Create TXT of log //Get Remote IP into $IP variable $IP=$_SERVER['REMOTE_ADDR']; //Display $IP variable on Client echo "Your IP is:";echo $IP; //Set file to be edited into variable $IPFile $IPFile = "Data/Logs/IPLog.txt"; //Open File to be edited, "Append" Mode into $fh variable $fh = fopen($IPFile, 'a') or die("can't open file"); //Write IP into file specified in $fh variable each line fwrite($fh, $IP); fwrite($fh, " Accessed:"); fwrite($fh, date("d/m/y H:i:s",time())); fwrite($fh, " "); //Close $fh variable(close file) fclose($fh); ?><?php //Create HTML of LOG !!!No Auto Refresh inside log!!! //Declare File to be written into variable $IPFileHTML = "Data/Logs/IPLog.html"; //if Declare file does NOT exsist, show error message and create new file if (!file_exists($IPFileHTML)) { echo "<br>IPTRACELOG not found, New Log being created."; fopen($IPFileHTML, 'w') or die("cannot create log file, check permissions. If you do not have permissions, contact your system administrator");} //Get contents of that file $ffh = file_get_contents("Data/Logs/IPLog.html"); //break contents into an array, <!--break--> identifies where to split file $pieces = explode("<!--break-->", $ffh); //open declared variable to be written to $fh = fopen($IPFileHTML, 'w') or die("can't open file to write"); //write new file replacing old one every time this page is loaded fputs($fh, "<html><title>IP TRACE LOG</title><script language='javascript' type='text/javascript'>function refresh(){window.location.href='IPLog.html';setTimeout('setTimeout()', 2000); }</script><body bgcolor='#C0C0C0'><center><h1>USAGE LOG</h1><table bgcolor='#FF8C00' border=5><tr><th>IP</th><th>Acessed Date/Time</th></tr><!--break-->"); fputs($fh, "<tr><td>"); fputs($fh, $_SERVER['REMOTE_ADDR']); fputs($fh, "</td><td>"); fputs($fh, date("d/m/y H:i:s",time())); fputs($fh, "</td></tr>"); fputs($fh, $pieces[1]); fputs($fh, "<!--break--></table></center></body></html>"); fclose($fh); ?> Hope this helps:) God Bless:)
  2. Ok I found my problem. Thank you all who replied so quickly, I really appreciate your help. The reply about variable scopes helped a lot, but that was not my only problem with the code. This PHP file was executed from a JavaScript code using AJAX, so the PHP file opened, did what it was suppose to, and closed. I did not realize that every time my JS called for the PHP file, the PHP file started without the variables that were stored from the previous time it was called. To combat this problem, I had to create an external file using the PHP file to store the $bgcolorplace variable. Also I had to write PHP so that the file that was automatically generated the previous execution would be loaded into the $bgcolorplace variable. I also had to change the order around a little bit. Here is my new PHP script: <?php function readtrace(){ $trace = ("colortrace.txt"); if (!file_exists($trace)) { echo "<br>count_my_page not found, New trace file being created.<br>"; fopen($trace, 'w') or die("<br>cannot create trace file, check permissions. If you do not have permissions, contact your system administrator<br>");} $value = file($trace); global $bgcolorplace; $bgcolorplace=$value[0]; } function storetrace($place){ $trace = ("colortrace.txt"); if (!file_exists($trace)) { echo "<br>count_my_page not found, New trace file being created.<br>"; fopen($trace, 'w') or die("<br>cannot create trace file, check permissions. If you do not have permissions, contact your system administrator<br>");} $value = file($trace); $value[0]=$place; $fp = fopen($trace , "w"); fputs($fp , "$value[0]"); fclose($fp); } $input=($_GET['inputText']); $ItemNum='Item'.$input; $Title='Bible'; $Description='softcover'; $PriceEach='45'; function changebgcolor(){ global $bgcolor; global $bgcolorplace; if ($bgcolorplace=="1"){ $bgcolorplace--; $bgcolor="00ee00"; storetrace($bgcolorplace); }elseif($bgcolorplace=="0"){ $bgcolorplace++; $bgcolor="aaffaaa"; storetrace($bgcolorplace); }else {echo ("<br/>bgcolorplace undefined, check global variable in Data.php<br/>");} } if ($input=='123'){ readtrace(); $bgcolor; changebgcolor(); $out=/*$ItemNum.*/"<tr bgcolor='#".$bgcolor."' id='".$ItemNum."'><?--jsbreak--><td align='center' width='5%'>".$input."</td><td align='center' width='30%'>".$Title."</td><td align='center' width='50%'>".$Description."</td><td align='center' width='5%'>".$PriceEach."</td><td align='center' width='5%'>1</td><td align='center' width='5%'>45</td></tr>"; echo($out); }else{ echo('none'); } ?>
  3. Hello, I am trying to make this work. what i am trying to do is to make a function that changes a variable back and forth. for example, I need to have a variable $bgcolorplace that is set to 1, as soon as the function is executed the variable $bgcolorplace changes to 0. The next time the function executes, variable should turn to 1 again. This pattern should repeat forever only when the function is executed. I am trying to use this to change the background color of a generated HTML code which will be on the webpage. Here is my script. <?php $input=($_GET['inputText']); //get info from JS $ItemNum='Item'.$input; //make a var with contents "Item" + the info from JS to display later $bgcolorplace; //var that keeps track of what color to make the next background $bgcolor; //keeps the color of the background for this execution function changebgcolor(){ if ($bgcolorplace=="0"){ $bgcolorplace="1"; //$bgcolor="444444" echo("0 to 1<br/>".$bgcolorplace."<br/>");//display which part of code is executed 1 to 0 or 0 to 1(can never get the script to run this part), this line is temp/test code }else{ $bgcolorplace="0"; //$bgcolor="ffffff" echo("1 to 0<br/>".$bgcolorplace."<br/>"); //display which part of code is executed 1 to 0 or 0 to 1(It works), this line is temp/test code } } //this next section I have temporarily commented for testing purposes, this section works fine /*$out="<tr bgcolor=#'".$bgcolor."' id='".$input."'><td align='center' width='5%'>".$input."</td><td align='center' width='30%'>bible</td><td align='center' width='50%'>Softcover</td><td align='center' width='5%'>45</td><td align='center' width='5%'>1</td><td align='center' width='5%'>45</td></tr>";*/ if ($input=='123'){ changebgcolor(); //echo($out); }else{ echo('none'); } ?> I get a responds of this everytime 1 to 0 1 this means that the function is being processed, but the value of $bgcolorplace is always a 1, it never changes to 0 like I am trying to inside the IF Else Statement. The commented Items are just my code that I have temp disabled while I try to figure out why my IF Else statement doesnt work. Help is much appreciated, and thank you in advanced.
×
×
  • 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.