Skewled
Members-
Posts
387 -
Joined
-
Last visited
About Skewled
- Birthday 11/08/1980
Profile Information
-
Gender
Male
-
Location
USA
-
Interests
Programming / Solving Problems - Freelancer for Hire
Skewled's Achievements
Member (2/5)
1
Reputation
-
Yes I know what I want to achive, one blog post with the comments under each post. All of the trouble started with MySQL returning multiple rows because of the JOIN, the php array was rebuilt but it needs to filter the array more. Thank you for all the help!! Marked Solved because the jQuery was correct to achieve the desire results with the JSON data passed to the function, the PHP array needs to be re-factored to compile the JSON data better.
-
The extra post: (First Post of the Blog) Title: blog post one Image: public/img/blog-image.png Dateposted: 2014-04-13 Content: blog article one (Comment Stays) Login: admin Username: Gaddam Comment: blog post one comment (Filter this out because only needs to be displayed once) Title: blog post one Image: public/img/blog-image.png Dateposted: 2014-04-13 Content: blog article one (Comment Stays) Login: admin Username: Gaddam Comment: blog post one comment I'm trying to filter out the need to repost the title, image, dateposted, and content for each comment.
-
secure login, strong(est) session ID's and secure site navigation
Skewled replied to ajoo's topic in PHP Coding Help
That should do the trick: } else { header('Location: /login.php'); die; // end execution on next line to prevent the rest of the code from executing. }- 8 replies
-
- security
- strong sessions ids
-
(and 1 more)
Tagged with:
-
Output: Blog ID: 36 Dateposted: 2014-04-13 Content: blog article one Title: blog post one Published: 1 Login: admin Image: public/img/blog-image.png Username: Gaddam Comment: blog post one comment Blog ID: 36 Dateposted: 2014-04-13 Content: blog article one Title: blog post one Published: 1 Login: admin Image: public/img/blog-image.png Username: Gaddam Comment: blog post one comment Blog ID: 37 Dateposted: 2014-04-13 Content: blog article two Title: blog post two Published: 1 Login: admin Image: public/img/blog-image.png Username: Skewled Comment: blog two comment Blog ID: 37 Dateposted: 2014-04-13 Content: blog article two Title: blog post two Published: 1 Login: admin Image: public/img/blog-image.png Username: Skewled Comment: blog two comment
-
secure login, strong(est) session ID's and secure site navigation
Skewled replied to ajoo's topic in PHP Coding Help
No offense taken Jacques! I was just showing how to create the session along with some cookie information, I should have certainly answered the OP question better so I am rather embarrassed if anything lol. Use the code as an example for setting session variables and establishing cookies, and verification on pages that need to know if a session exists, don't use it verbatim.- 8 replies
-
- security
- strong sessions ids
-
(and 1 more)
Tagged with:
-
Passing parameters and sending them another URL
Skewled replied to chupacabrot's topic in PHP Coding Help
I would do it like this <?php if (isset($_POST['submit'])) { // You'd want to verify the POST data though echo "$newUrl = 'http://www.myothertestspace.com/simlpe2.php?name=' . $_POST['name'] . '&surname=' . $_POST['lastname'] . '&phone=' . $_POST['phone']"; } ?> <html> <form name="Students Management"action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" accept-charset="utf-8"> <p> <label>First Name</label> <input type="text" value="" name="firstname" ></input> </p> <p> <label>Phone</label> <input type="text" value="" name="phone" ></input> </p> <p> <label>Last Name</label> <input type="text" value="" name="lastname" required="true"></input> </p> <p> <label>Company</label> <input type="text" value="" name="school" required="true"></input> </p> <p> <label>Email</label> <input type="text" value="" name="email" ></input> </p> <p> <label>Country</label> <input type="text" value="" name="age" ></input> </p> <p> <input type="submit" value="Submit" ></input> </p> </form> </html> You could apply some CSS and place the output into an iframe if you wanted. -
secure login, strong(est) session ID's and secure site navigation
Skewled replied to ajoo's topic in PHP Coding Help
I've used a session.php file that I coded that is bare minimum: <?php header("Cache-Control: no-cache"); session_start(); // If the session vars aren't set, try to set them with a cookie if (!isset($_SESSION['user_id'])) { if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) { $_SESSION['user_id'] = $_COOKIE['user_id']; $_SESSION['username'] = $_COOKIE['username']; } else { header('Location: /login.php'); } } ?> Login: I would then have a form that checks to see if the data exsist for the login and do the following: require_once('session.php'); // Start the session session_start(); // Query database code goes here $query = " "; // SELECT SOMETHING FROM USERS WHERE USERNAME = SOMETHING AND PASSWORD = SOMETHING $data = mysqli_query($dbc, $query); if (mysqli_num_rows($data) == 1) { // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page $row = mysqli_fetch_array($data); $_SESSION['user_id'] = $row['id']; $_SESSION['username'] = $row['username']; setcookie('user_id', $row['id'], time() + (60 * 60 * 24 * 30)); // expires in 30 days setcookie('username', $row['username'], time() + (60 * 60 * 24 * 30)); // expires in 30 days $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { // The username/password are incorrect so set an error message $error_msg = '<p class="error">Sorry, you must enter a valid username and password to log in.<br>'; } Each page the user would access would require an active session, using the session.php file. So if they didn't have a valid cookie anymore they would need to log back in, each login resets the session data. Hope this helps you out.- 8 replies
-
- security
- strong sessions ids
-
(and 1 more)
Tagged with:
-
Denno, Thank you for your reply, I've been doing some reading about $(each) and it functions like a for loop. I know I need to come up with a method of storing the first blog_id and then during each iteration store the value so that on the next iteration it skips over the data but I can't figure out how to put it into code. I've been playing with the jfiddle and reading around on google, lot's of helpful information but I haven't found anything with filtering the data or iterating over the data. I blame my poor search skills lol. Currently it outputs: Blog Post Two Blog Post Two Comment Blog Post Two Blog Post Two Comment Here is the jsfiddle: http://jsfiddle.net/66c8z/1/, in this it actually shows the data somewhat correctly but just has the duplicates. Updated Function: var load_blog = function() { $.getJSON('api/get_blog', function(data) { $.each(data, function() { //Loop through each blog_id section var output = ''; $.each(this, function(){ //Loop through each comment in this blog_id output += Template.blog(this); //output the template }); $("#list_blog").html(output); }); }); };
-
I have the following JSON string of data that I'm trying to loop over: { "35": [ { "blog_id": "35", "dateposted": "2014-04-10", "content": "<p>Wow this is <span style=\"color: #008000;\"><em><span style=\"font-size: 14pt;\"><strong>very nice...<\/strong><\/span><\/em><\/span><\/p>", "title": "Thanks", "published": "1", "login": "admin", "img": "public\/img\/blog-image.png", "username": "Skewled", "comment": "thanks" }, { "blog_id": "35", "dateposted": "2014-04-10", "content": "<p>Wow this is <span style=\"color: #008000;\"><em><span style=\"font-size: 14pt;\"><strong>very nice...<\/strong><\/span><\/em><\/span><\/p>", "title": "Thanks", "published": "1", "login": "admin", "img": "public\/img\/blog-image.png", "username": "Skewled", "comment": "fasdfa asdf asd fasdfasd [b]test[\/b]" } ], "34": [ { "blog_id": "34", "dateposted": "2014-04-09", "content": "<p><em><strong>sdfasdf asdafsadf<\/strong> asdfasd <\/em> asdfasdf <span style=\"color: #008000;\">asdf asdf asdf asdfsa asfasdfaasdf <span style=\"color: #000000;\">asdfasdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">saf asdfasd <strong>fasdfasdf asdfasdf<\/strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">sadfs dfasdf asdf asdf asdf<\/span><\/span><\/p>", "title": "Launch Party", "published": "1", "login": "admin", "img": "public\/img\/blog-image.png", "username": "Skewled", "comment": "<p><em><strong>sdfasdf asdafsadf<\/strong> asdfasd <\/em> asdfasdf <span style=\"color: #008000;\">asdf asdf asdf asdfsa asfasdfaasdf <span style=\"color: #000000;\">asdfasdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">saf asdfasd <strong>fasdfasdf asdfasdf<\/strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">sadfs dfasdf asdf asdf asdf<\/span><\/span><\/p>" }, { "blog_id": "34", "dateposted": "2014-04-09", "content": "<p><em><strong>sdfasdf asdafsadf<\/strong> asdfasd <\/em> asdfasdf <span style=\"color: #008000;\">asdf asdf asdf asdfsa asfasdfaasdf <span style=\"color: #000000;\">asdfasdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">saf asdfasd <strong>fasdfasdf asdfasdf<\/strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">sadfs dfasdf asdf asdf asdf<\/span><\/span><\/p>", "title": "Launch Party", "published": "1", "login": "admin", "img": "public\/img\/blog-image.png", "username": "Skewled", "comment": "<p><em><strong>sdfasdf asdafsadf<\/strong> asdfasd <\/em> asdfasdf <span style=\"color: #008000;\">asdf asdf asdf asdfsa asfasdfaasdf <span style=\"color: #000000;\">asdfasdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">saf asdfasd <strong>fasdfasdf asdfasdf<\/strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf<\/span><\/span><\/p>\n<p><span style=\"color: #008000;\"><span style=\"color: #000000;\">sadfs dfasdf asdf asdf asdf<\/span><\/span><\/p>" } ] } I have the following loop but since the data change to a multidimensional setup I've gotten a bit lost, so if anyone would be willing to walk me through the process so I can learn I'd really appreciate it. The is my api call to grab the data above: var load_blog = function() { $.get('api/get_blog', function(o) { var output = ''; for (var i = 0; i < o.length; i++) { output += Template.blog(o[i]); } $("#list_blog").html(output); }, 'json'); }; I then have the HTML template separate from the code here: this.blog = function(obj) { var output = ''; output += '<div class="blog-post" style="margin: 5px;">'; output += '<h2 class="blog-post-title">'; output += obj.title + '</h2>'; output += '<p class="blog-post-meta">'; output += '<img src="' + obj.img +'">' + ' ' + obj.dateposted + ' by ' + obj.login + '</p>'; output += '<p>' + obj.content + '</p>'; output += '</div>'; output += '<span class="options">'; output += '<a class ="blog_update_display" data-id="' + obj.blog_id + '" href="#"><i class="glyphicon glyphicon-pencil"></i></a> Leave Comment '; output += '<div class="blog_comment_container" id="blog_comment_container_'+ obj.blog_id +'"></div>'; output += '<div class="hide" id="blog_comment_' + obj.blog_id + '">' + obj.comment + '</div>'; output += '</span>'; output += '<hr>'; output += '<span><a class="comment_toggle" data-id="'+ obj.blog_id +'" id="blog_title_' + obj.blog_id + '" href="#">View Comments</a></span> '; output += '<div class="hide" id="blog_comment_block_' + obj.blog_id + '">'; output += '<hr>'; if (obj.username) { output += '<h5 class="users">' + obj.username + ' commented:</h5>'; output += '<p>' + obj.comment + '</p>'; } else { output += '<p>Be the first to comment!</p>'; } output += '</div>'; output += '<hr>'; output += '</div>'; return output; }; I'm not sure how to change my template to work with the new object data. Thanks!
-
Thank you guys, I just need to work with that array in jQuery as you mentioned.. it's not easy to digest information like this and I appreciate your patience and for each of you re-iterating the same solution!
-
I would just disable the submit button until they check the box. $('#opt-in-checkbox').click(function(){ if($(this).attr('checked') == false){ $('#wpsp-continue').attr("disabled","disabled"); } else { $('#wpsp-continue').removeAttr('disabled'); } }); Feedback: I would have an age verification such as a birthday added to the form and server side checking because you can disable javascript.
-
<script> $(document).ready(function() { $("a").click(function(e) { e.preventDefault; var c = confirm('If you leave your upload may fail.'); if (c == false) return false; }); }); </script> This will alert on any link clicked on the page and if they click ok they will be able to follow the link or if they click cancel it won't do anything.
-
I think your missing some header information for sending a file in the email. $header = ''; $headers .= "From:" . $to; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: multipart/mixed; boundary=\"\"\n\n"; $headers .= "This is a multi-part message in MIME format.\n"; $headers .= "Content-type: text/html; charset=utf-8\n"; $headers .= "Content-Transfer-Encoding: 7bit\n\n";
-
Let me just say I love this community and I appreciate all of the input I've gotten, I've learned so much from the help I've received here! Here is the plan in my mind: 1. Fetch the data from the database 2. Filter the data so that each blog only get's displayed once and all of the comments are looped underneath it. - I'm using jQuery for the client view and currently it's setup as a MVC as well, so functions are seperated from the view which calls from a template which is just the HTML of the view with the variables that I want to display to the client area. 3. Allow additions to the comments by users - jQuery post and update the html area for the comments to append the post I'm doing this to learn something new and I've gotten the system going except this issue, so I'm wondering if my setup is incorrect and I should redo the whole thing or I'm going in the right direction and continue learning more. Eventually I would love to paginate the results using jQuery so I can keep all the blog posts, and an Archive. I've gotten the basics of PHP down and I've moved into the OOP side which has certainly been rewarding and I continue to practice and learn. So I am openly embracing all input I receive here that can help solidify the knowledge I've gained. I'm posing the setup I've coded so everyone can see what I'm working with, I think so far I'm pretty happy with what I've come up with so far but please any input is welcomed!! (: So here is a basic example of my overall setup: PHP API Call: public function get_blog() { $query = $this->db->query( "SELECT blog.blog_id, blog.dateposted, blog.content, blog.title, blog.published, user.login, user.img, bc.username, bc.comment FROM blog JOIN user ON blog.user_id = user.user_id LEFT JOIN blog_comments bc ON blog.blog_id = bc.blog_id WHERE blog.published = 1 ORDER BY blog.blog_id DESC "); $data = $query->result_array(); $outputArr = array(); foreach ($data as $result) { //Initialise array for the blog ID of the current $result, if it's not already done so if (!isset($outputArr[$result['blog_id']])) { $outputArr[$result['blog_id']] = array(); } //Append the comment_text for this result to the array for this blog_id $outputArr[$result['blog_id']]['blog_id'] = $result['blog_id']; $outputArr[$result['blog_id']]['dateposted'] = $result['comment']; $outputArr[$result['blog_id']]['content'] = $result['content']; $outputArr[$result['blog_id']]['title'] = $result['title']; $outputArr[$result['blog_id']]['published'] = $result['published']; $outputArr[$result['blog_id']]['login'] = $result['login']; $outputArr[$result['blog_id']]['img'] = $result['img']; $outputArr[$result['blog_id']]['username'] = $result['username']; $outputArr[$result['blog_id']]['comment'] = $result['comment']; } $result = $outputArr; if ($result) { $this->output->set_output(json_encode($result)); return false; } } Template for the View: this.blog = function(obj) { var output = ''; output += '<div class="blog-post" style="margin: 5px;">'; output += '<h2 class="blog-post-title">'; output += obj.title + '</h2>'; output += '<p class="blog-post-meta">'; output += '<img src="' + obj.img +'">' + ' ' + obj.dateposted + ' by ' + obj.login + '</p>'; output += '<p>' + obj.content + '</p>'; output += '</div>'; output += '<span class="options">'; output += '<a class ="blog_update_display" data-id="' + obj.blog_id + '" href="#"><i class="glyphicon glyphicon-pencil"></i></a> Leave Comment '; output += '<div class="blog_comment_container" id="blog_comment_container_'+ obj.blog_id +'"></div>'; output += '<div class="hide" id="blog_comment_' + obj.blog_id + '">' + obj.comment + '</div>'; output += '</span>'; output += '<hr>'; output += '<span><a class="comment_toggle" data-id="'+ obj.blog_id +'" id="blog_title_' + obj.blog_id + '" href="#">View Comments</a></span> '; output += '<div class="hide" id="blog_comment_block_' + obj.blog_id + '">'; output += '<hr>'; if (obj.username) { output += '<h5 class="users">' + obj.username + ' commented:</h5>'; output += '<p>' + obj.comment + '</p>'; } else { output += '<p>Be the first to comment!</p>'; } output += '</div>'; output += '<hr>'; output += '</div>'; return output; }; // ------------------------------------------------------------------------ this.blog_comment = function(blog_id) { var output = ''; output += '<form method="post" class="blog_comment_form form-horizontal" action="../api/post_comment">'; output += '<input class="blog_id" type="hidden" name="blog_id" value="' + blog_id + '" />'; output += '<div class="input-append">'; output += '<label for="comment">Comment:</label><br>'; output += '<textarea style="width:100%" rows="10" class="comment" name="comment" id="comment"></textarea>'; output += '<input tabindex="3" type="submit" class="btn btn-success" value="Post Comment" />'; output += '<input type="submit" class="btn blog_comment_cancel" value="Cancel" />'; output += '</form>'; return output; }; Events: var toggle_comments = function() { $('body').on("click", ".comment_toggle", function (evt) { evt.preventDefault; var blog_id = $(this).data('id'); $("#blog_comment_block_" + blog_id).toggleClass('hide'); return false; }); }; // ------------------------------------------------------------------------ var add_comment = function() { $("body").on("submit", ".blog_comment_form", function(evt) { evt.preventDefault(); var form = $(this); var url = $(this).attr('action'); var postData = { blog_id: $(this).find('.blog_id').val(), comment: $(this).find('.comment').val() }; //console.log(postData); $.post(url, postData, function(o) { if(o.result == 1) { Result.success("Successfuly Added Comment."); $("#blog_comment_" + postData.blog_id).html(postData.comment); form.remove(); } else { Result.error("No Changes Made."); } }, 'json'); }); }; // ------------------------------------------------------------------------ var update_blog_display = function() { $("body").on('click', '.blog_update_display', function(e) { // Debug: console.log(e); e.preventDefault(); var blog_id = $(this).data('id'); var output = Template.blog_comment(blog_id); $("#blog_comment_container_" + blog_id).html(output); }); $("body").on("click", ".blog_comment_cancel", function(e) { e.preventDefault(); $(this).parents('.blog_comment_container').empty(); }); }; Loading Code: var load_blog = function() { $.get('api/get_blog', function(o) { var output = ''; for (var i = 0; i < o.length; i++) { output += Template.blog(o[i]); } $("#list_blog").html(output); }, 'json'); };
-
Denno, Thank you for the reply and I see what you were doing for the most part. I have difficulty when working with data and arrays so I'm practicing. Here is the data returned by my query: Array ( [0] => Array ( [blog_id] => 35 [dateposted] => 2014-04-10 [content] => <p>Wow this is <span style="color: #008000;"><em><span style="font-size: 14pt;"><strong>very nice...</strong></span></em></span></p> [title] => Thanks [published] => 1 [login] => admin [img] => public/img/blog-image.png [username] => Skewled [comment] => thanks ) [1] => Array ( [blog_id] => 35 [dateposted] => 2014-04-10 [content] => <p>Wow this is <span style="color: #008000;"><em><span style="font-size: 14pt;"><strong>very nice...</strong></span></em></span></p> [title] => Thanks [published] => 1 [login] => admin [img] => public/img/blog-image.png [username] => Skewled [comment] => fasdfa asdf asd fasdfasd [b]test[/b] ) [2] => Array ( [blog_id] => 34 [dateposted] => 2014-04-09 [content] => <p><em><strong>sdfasdf asdafsadf</strong> asdfasd </em> asdfasdf <span style="color: #008000;">asdf asdf asdf asdfsa asfasdfaasdf <span style="color: #000000;">asdfasdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">saf asdfasd <strong>fasdfasdf asdfasdf</strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">sadfs dfasdf asdf asdf asdf</span></span></p> [title] => Launch Party [published] => 1 [login] => admin [img] => public/img/blog-image.png [username] => Skewled [comment] => <p><em><strong>sdfasdf asdafsadf</strong> asdfasd </em> asdfasdf <span style="color: #008000;">asdf asdf asdf asdfsa asfasdfaasdf <span style="color: #000000;">asdfasdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">saf asdfasd <strong>fasdfasdf asdfasdf</strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">sadfs dfasdf asdf asdf asdf</span></span></p> ) [3] => Array ( [blog_id] => 34 [dateposted] => 2014-04-09 [content] => <p><em><strong>sdfasdf asdafsadf</strong> asdfasd </em> asdfasdf <span style="color: #008000;">asdf asdf asdf asdfsa asfasdfaasdf <span style="color: #000000;">asdfasdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">saf asdfasd <strong>fasdfasdf asdfasdf</strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">sadfs dfasdf asdf asdf asdf</span></span></p> [title] => Launch Party [published] => 1 [login] => admin [img] => public/img/blog-image.png [username] => Skewled [comment] => <p><em><strong>sdfasdf asdafsadf</strong> asdfasd </em> asdfasdf <span style="color: #008000;">asdf asdf asdf asdfsa asfasdfaasdf <span style="color: #000000;">asdfasdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">saf asdfasd <strong>fasdfasdf asdfasdf</strong> asdf adsfa asdfasdf asdf asdf asdfasdfa sdf asdf</span></span></p> <p><span style="color: #008000;"><span style="color: #000000;">sadfs dfasdf asdf asdf asdf</span></span></p> ) ) As you can see each blog_id is repeated with a comment, so I'm trying to restructure it so each blog_id is only posted once to the array and then the comments are posted into it. Would I need to add another array to this for each comment so the key's would be unique based off the comment_id? I really appreciate your help and your reply was very clear and concise, my questioning and logic are faulting me here lol. Thanks! EDIT: I wanted to show you the json_encoded output that I was working with: non-filtered: https://www.dropbox.com/s/nsq8vas9469uzit/output0.png filtered: https://www.dropbox.com/s/4a3h8o7649ee1fo/output1.png