Jump to content

WolfRage

Members
  • Posts

    647
  • Joined

  • Last visited

    Never

Everything posted by WolfRage

  1. PHP is server side, if you want to submit a form to the server than do so and check it using PHP on the server side. Then if the results are good take them to a completion page else send them back to the form and highlight the improper field(s). There is no opening and closing windows using PHP that is javascript.
  2. Simply includen the script below for the page with comments. Not tested! <?php $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='SELECT * FROM comment WHERE page='.$_SERVER['PHP_SELF']; $result=$mysqli->query($sql); while($row = $result->fetch_array(MYSQLI_ASSOC)) { ?><div class="comment_container"> <p class="comment"><?php echo $row['notes']; ?></p> <p class="comment_signature"><?php echo $row['name'].' | '.$row['time']; ?></p> </div><?php /*Be sure to include your HTML that will separate each comment block you will most likely want the separation to be applied on the top.*/ } $result->close(); $mysqli->close(); ?> In order to post comments you will need to use the comment form that you created earlier and submit to this script: <?php if($_POST['submit']==='Submit') { $name=htmlspecialchars(trim($_POST['visitor'])); // we use htmlspecialchars to prevent some one from injecting content. $email=htmlspecialchars(trim($_POST['visitormail'])); //We could also use the filter_var() here if you want more precision. $url=htmlspecialchars(trim($_POST['url'])); $notes=nl2br(htmlspecialchars(trim($_POST['notes']))); if(empty($name)&&empty($email)&&empty($url)&&empty($notes)) { $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='INSERT INTO table_name (name, email, url, notes, time, pagecolumn) VALUES ('.$mysqli->real_escape_string($visitor).', '.$mysqli->real_escape_string($visitoremail).', '.$mysqli->real_escape_string($url).', '.$mysqli->real_escape_string($notes).','.$mysqli->real_escape_string($_SERVER['REQUEST_TIME']).','.$mysqli->real_escape_string($_SERVER['PHP_SELF']).')'; $mysqli->query($sql); $mysqli->close(); } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. header('Location: '.$_SERVER['HTTP_REFERER']); //HTTP_REFERER may not always be set by the users browser! } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. ?> Besure to take the time to customize these scripts further; at the very least you will need to change the database settings to correctly connect. Truth of the matter is that you had everything that you needed right here to complete your comment script. However you unfortunately did not participate in the excercise. Thus you have learned little of PHP; so it is very unlikely that I will help you out agian. Particularly because you do not appreciate free work and expected me to build you something quickly even though you were not willing to contribute anything more than setting up the database.
  3. Ok so the html structure should look something like this: <div class="comment_container"> <p class="comment"></p> <p class="comment_signature"></p> </div> *Note to self be sure to perform nl2br before inserting the comments into the DB. You can of course apply your CSS rules using the classes. I will have more latter today, should have time throughout the day and for the rest of the week during work. We will get it done. Sorry for delays but as you know time is money. This weekend I launched one new website and I am nearing a deadline for another project that has much work still to be done. Any ways still trying to squeeze you in.
  4. No make the name something like include_comments.php. Change your pagecolumn column to a varchar not an int. I need your html that will style the comments just like you want. So please mock up the html the way you would want it to look for a comment, you can even include a fake comment and I will modify it to properly loop with our SQL Query.
  5. OK I saw that you added a time stamp to the table like I suggested, but we will also need a page column; so that we can pull comments for a specific page. This lesson will be to more parts. One more tonight and the final tomorrow. Then we can wrap up any lose ends. After you have added that other column for your entries into your data base we will extract the comments on a per page level. As a quick side note to automate the process when we add comments to the database we will pull the page name with the Reserved variable $_SERVER['PHP_SELF']. The automated page for pulling your comments. <?php $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='SELECT * FROM comment WHERE page='.$_SERVER['PHP_SELF']; $result=$mysqli->query($sql); while($row = $result->fetch_array(MYSQLI_ASSOC) { //At this point I am guessing that this will work as a while statement. But I am pretty sure. //Next we need your HTML here so that it will be styled the way you would like for your comments. //We should be able to spit our the parts of the returned query like so. echo $row['time']; echo $row['name']; echo $row['url']; echo $row['notes']; /*Be sure to include your HTML that will separate each comment block you will most likely want the separation to be applied on the top.*/ } $result->close(); $mysqli->close(); ?> Tomorrow I will combine all of the sections together appropriately and then we will add any missing pieces. Then you can have a look and tell me what else you would like.
  6. Hey I wanted to tell you sorry for dorpping off, but I got buzy over the weekend with a new site launch. Do you still want my help in completing this project? Have you made any progress outside of the forum?
  7. You are going to to compare the string that you plan to insert into the file with every line in the file and if no match is found then you can insert it.
  8. All together the script will look something like this, minus your changes for your database information and the table name. <?php if($_POST['submit']==='Submit') { $name=htmlspecialchars(trim($_POST['visitor'])); // we use htmlspecialchars to prevent some one from injecting content. $email=htmlspecialchars(trim($_POST['visitormail'])); //We could also use the filter_var() here if you want more precision. $url=htmlspecialchars(trim($_POST['url'])); $notes=htmlspecialchars(trim($_POST['notes'])); if(empty($name)&&empty($email)&&empty($url)&&empty($notes)) { $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='INSERT INTO table_name (visitor, visitoremail, url, notes) VALUES ('.$mysqli->real_escape_string($visitor).', '.$mysqli->real_escape_string($visitoremail).', '.$mysqli->real_escape_string($url).', '.$mysqli->real_escape_string($notes).')'; $mysqli->query($sql); $mysqli->close(); } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. header('Location: '.$_SERVER['HTTP_REFERER']); //HTTP_REFERER may not always be set by the users browser! } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. ?> Next we will work on the script to extract these entries from your database; and then display them on your page. For all of those critics out there: Before we take this live we will need to make the input script more complex to include at the minimum a page column so that comments can be stored in the same table for multiple pages. We should also add a time stamp column which can be done with either PHP or MySQL.
  9. Our SQl statement for inserting the information in your data base will look like this: <?php $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='INSERT INTO table_name (visitor, visitoremail, url, notes) VALUES ('.$mysqli->real_escape_string($visitor).', '.$mysqli->real_escape_string($visitoremail).', '.$mysqli->real_escape_string($url).', '.$mysqli->real_escape_string($notes).')'; $mysqli->query($sql); $mysqli->close(); ?> More to come...
  10. Yes target = "framename" shoud do it. This method is probably the simplest method it enact however it is also the most resource intensive as it reads the entire file into an array. $lines = count(file($file)); I think the best appraoch is to use the while with the fgets() as it automatically advances the file pointer. Sorry about the infinite loop, I forgot to use fgets in my example along with incrementing the counter which caused your loop. So I would do it like this: $handle = fopen( $filepath, "r" ); $count =0; while( fgets($handle) ) { $count++; } $line=rand(0,$count); fseek($handle,0); fseek($handle,$line); $data=fgets($handle); fclose($handle); echo '<FORM METHOD="'."LINK".'" ACTION="'.$line.'"> <INPUT TYPE="'."submit".'" VALUE="'.$data.'"> </FORM>'; //Your echo statement was not producing valid HTML. Hope this advances your quest! Make sure you replace "LINK" with your actual link...
  11. Really Thanks, Gizmola! SOrry having a busy day at work today. When I get home I will work to put together the rest of your scripts so that you can implement your comments. Of course any other interested parties could actively contribute before then... giz... mola... lol
  12. To allow you to move forward look up the SQL for simple insert into a single table. We will use that SQL statement to craft our php prepared SQL statement. Also did you test out the form with the script and did it echo all of the variables as expected?
  13. Come on now try to learn. You know that this code was not complete I stated you need to increment your counter, which is not defined, plus you need to echo it. <?php $fp = fopen("myfile.txt", "r"); $count=0; while (!feof($fp)) { $count=$count+1; } echo 'The number of lines in this file is = '.$count.' +1 because the file and the counter start at line 0.'; fclose($fp); ?>
  14. Ok in order to pull off what you want to do with the dates, it is going to be relatively complex at least in my mind I am working through it now. I know we will need to use strtotime() along with date() in order to get the future dates we want. To help me visualize this can you give me some example dates to work with and what the expected out come would look like. Then I should be able to come up with a formula that will parse the dates the way you want.
  15. I know your in a hurry but I am doing this in my spare time, which I ran out of yesterday. You will want 5 fields the first field should be a incremental unique key. I will post the next steps in a few.
  16. Yes but we need to know what your metrics are for determining a pay period. A time stamp is measured in seconds so you can convert the difference between two time stamps into days or add time in increments if days. Ex... 60 seconds in one minute, 60minutes in one hour and 24 hours in a day. 60*60*24=86400 seconds or one day.
  17. Cookies are not secure that is why you never store any sensitive data in a cookie. However by creating links to the users information via a cookie we can help to keep that users experince more pleasant. If a hacker hacks your server then they will surely see your php code that shows them how you confirm users, in which case you are simply screwed. If a hacker gets into your database they will still have the correct dbid but he will need to know that before it gets run through your login that it needs to be reversed through md5, which is theoretically impossible because of the number of possible answers. However if he gets any answer that translates to the correct md5 sum then he can get authenticated because it will pass according to your md5 sum. Truth is md5 is vulnerable because rainbow tables have been created and there are many values that will wind up giving the same md5 sum. Either way if a hacker hacks your server or your database it is very hard to prevent what they can and can not do with the knowledge that they now have access to. You should limit the scope of your security to the level of cookies and database inputs. Then create a seperate level to address what if issues; like if a hacker cracked your server or database or both, then resolve what you can do to minimize the damage they can do.
  18. Everything is good except that you named your website input box as visitormail. OK next we will build comment_post.php . <?php if($_POST['submit']==='Submit') { $name=htmlspecialchars($_POST['visitor']); // we use htmlspecialchars to prevent some one from injecting content. $email=htmlspecialchars($_POST['visitormail']); //We could also use the filter_var() here if you want more precision. $url=htmlspecialchars($_POST['url']); $notes=htmlspecialchars($_POST['notes']); echo 'Let test to make sure the data is being passed.'."\n"; echo 'name='.$name.' email='.$email.' url='.$url."\n".'notes='.$notes; } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. ?> We will need the name of the database and the table that you have created for the comments. You can keep the name of the database to yourself if you would like. Also do not at any point during these posts reveal your password. Once you are able to successfully see the varibles getting passed well proceed to the next step. Also try to take a moment to understand why I used the code that I did. http://php.net/manual/en/function.htmlspecialchars.php http://php.net/manual/en/function.filter-var.php http://php.net/manual/en/reserved.variables.post.php
  19. You are correct in your assumption you can assign a cookie to the user with a unique identifier that will allow you to authenticate them. But you have to ensure that the ID is unique or else you may need a couple of cookies. Also if the user comes back with the cookie after being inactive for awhile you may want to reauthenticate before you let them make any kind of changes or do something that requires explicit authentication.
  20. OK go ahead and create the new MySQL database. Lets begin with a comment form. You said you understand html, so you should be able to make the form. Show me what you come up with make sure that for now the form method is POST and that the action is the name of the script that you want to proccess the comments, like "comment_post.php". I did visit you link and I see how his comments work, but you can make the html side so that it will look just like that. To make your comments like his at a minimum you will need to collect the users name and there comment but of course you can collect extra information such as a email. This helps for validation. We are going to need to plan a database structure, this could be very simple but it could be more complex to allow for easy expansion latter. Which would you perfer and how much do you know about databases and SQL?
  21. Well you will need to count the number of lines in the file and then pick a random number between zero and the number of lines. To loop through the file use a while like so: <?php [font=consolas]$fp = fopen("myfile.txt", "r"); while (!feof($fp)) { // increment your counter. } fclose($fp);[/font] ?> To learn more check out http://php.net/manual/en/function.feof.php & http://php.net/manual/en/function.fgets.php
  22. Ok this will be a bit of a challenge for me, but that is because I try to avoid databases (SQL is not my fortay); but it will be a learning opportunity for me. Just a little more planning before we begin. The database that you have does it already contain data similiar to the type of information we will be collecting? If so we could just give the comments a unique table in the database. Have you already tested your server for PHP capability? Also how much understanding do you have of PHP? Initially we are going to need a place to store the data. = In the database, either a seperate one or a unique table. We will need to build a comment form to collect the information from the user. We will have to build a php script that will be responsible for catching the form information and filtering the users input accordingly. It will also have to pass the data to the database. Finally if we are not using AJAX the script will redirect the user back to the page they came from so that they can see there newly added coment. We will also need a script built into each page that will grab the comments that relate to that page and display them. I am going to look up some SQL. Well you answer my questions and start to prepare the outlines of our scripts. Post back when you are ready to move forward.
  23. Well that would depend on how you want to go about it. Do you have a database? Or do you plan to use text files, or will you be editing html files directly? Do you know how to sanatize user inputs? Do you plan on collecting some of the information that users submit for use latter? These are just a few of the questions you need to ask yourself. Also before you can just jump in you need to have a plan. Post back when you know what you want to do and you think you are ready to begin.
  24. I believe that jl5501 meant fwrite(). other than that he is right. To add a new line simple change this line: <?php fwrite($Handle, $Data); ?> to: <?php fwrite($Handle, $Data."\n"); ?> to read a specific line from a file you will want to use fgets() http://php.net/manual/en/function.fgets.php Then simply echo the fgets() string to the frame. To redirect use header() http://php.net/manual/en/function.header.php Like: <?php header([font=consolas]'Location: [url=http://www.example.com/']http://www.example.com/'[/url]);[/font] ?> Make sure you have no output prior to that command.
  25. You can try using fsockopen, but you may be mostly on your own with that. However maybe this script will be handy for you. http://www.phpclasses.org/browse/package/281.html fsockopen() http://php.net/manual/en/function.fsockopen.php
×
×
  • 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.