PHP - Storing Articles On Github
Howdy colleagues,
I have a history blog where I post, well, history related essays of my own. I'd like to store the articles in .md or .txt document in my GitHub profile. My question is, would these articles get indexed by Google, since I want them to be original for my blog?
Thank you!
Stef
Similar TutorialsThis topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=318333.0 Hi, I come to know that we can use secret vars of out GIT Project to store password. But can you tell me how can we access it in PHP and how I can get same data at localhost xamp server? Thanks in advance. Hi everyone, I'm making an admin page which will contain a number of articles. Unlike most sites, these articles won't be ordered based on date, but however the admin wishes. To do this I've added an order column to the mysql, in the admin page all the articles are displayed and next to them a text input, with the value set to their current order number (1,2,3, 4 etc) Here's selections of the code <?php $o = $_GET['o']; if($o == 'new') { $order1 = $_POST['order1']; $update = "UPDATE `content` SET `order` = '$order1' WHERE `id` = '1'"; $result=mysql_query($update) or die(mysql_error()); } ?> <form method="post" action="?o=new" name="order_form"> <!-- CONTENT --> <div id="content"> <?php $sql="SELECT * FROM `content` ORDER BY `order` ASC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <ul> <li class="article_left"> <input type="text" value="<?php echo $rows['order']; ?>" name="order<?php echo $rows['id']; ?>" class="order"> </li> <li class="article_left_title"> <?php echo $rows['title']; ?> </li> <li <?php if ($rows['live'] == '1') { echo 'class="live"'; }else echo 'class="launch"'; ?>> <?php if ($rows['live'] == '1') { echo 'Now Live'; }else { echo 'Launch'; } ?> </li> <div class="clear"></div> </ul> <?php } ?> </div> <!-- END CONTENT --> <div id="submit_order"> <input type="submit" name="submit" value="Submit Re-Order"> </div> </form> My problem is hard to explain, but as you can tell $update only does it for the first article. How can I make it change the `order` column for all the articles. Feel free to ask more questions. Would really appreciate any help! This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=355205.0 Im running a website about health and foods. I would like that at the end of each article, it shows other related articles that I have on my website.
Im relatively new with php and mysql so I figure I have to put every page onto a database table.
I looked already everywhere but all I found is how to do with wordpress. But i'm not using anything like that.
I made the website myself with css and html and php.
Can somebody help me with a website where they explain how to do?
Also I would like that automatically it shows my latest articles in a sidebar. Without anytime adding myself manually.
Can anybody help me?
I have a full-text RSS component for Joomla that I was trying to modify. I wanted to be able to truncate the article to a given number of words and place a link at the end for the rest of the article. I need help figuring out how to add a link to the end of the source article. Added this script to the post.php file. It sort of works but the "$ending" tag doesn't seem to function since there is no "..." appended to the end of articles posted, when I tested it. public function truncate($text, $length = 200, $ending = '...', $exact = true, $considerHtml = false) { if ($considerHtml) { // if the plain text is shorter than the maximum length, return the whole text if (str_word_count(preg_replace('/<.*?>/', '', $text)) <= $length) { return $text; } // splits all html-tags to scanable lines preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); $total_length = str_word_count($ending); $open_tags = array(); $truncate = ''; foreach ($lines as $line_matchings) { // if there is any html-tag in this line, handle it and add it (uncounted) to the output if (!empty($line_matchings[1])) { // if it's an "empty element" with or without xhtml-conform closing slash (f.e. <br/>) if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { // do nothing // if tag is a closing tag (f.e. </b>) } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { // delete tag from $open_tags list $pos = array_search($tag_matchings[1], $open_tags); if ($pos !== false) { unset($open_tags[$pos]); } // if tag is an opening tag (f.e. <b>) } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { // add tag to the beginning of $open_tags list array_unshift($open_tags, strtolower($tag_matchings[1])); } // add html-tag to $truncate'd text $truncate .= $line_matchings[1]; } // calculate the length of the plain text part of the line; handle entities as one character $content_length = str_word_count(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); if ($total_length+$content_length> $length) { // the number of characters which are left $left = $length - $total_length; $entities_length = 0; // search for html entities if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { // calculate the real length of all entities in the legal range foreach ($entities[0] as $entity) { if ($entity[1]+1-$entities_length <= $left) { $left--; $entities_length += str_word_count($entity[0]); } else { // no more characters left break; } } } $truncate .= substr($line_matchings[2], 0, $left+$entities_length); // maximum lenght is reached, so get off the loop break; } else { $truncate .= $line_matchings[2]; $total_length += $content_length; } // if the maximum length is reached, get off the loop if($total_length>= $length) { break; } } } else { if (str_word_count($text) <= $length) { return $text; } else { $truncate = substr($text, 0, $length - str_word_count($ending)); } } // if the words shouldn't be cut in the middle... if (!$exact) { // ...search the last occurance of a space... $spacepos = strrpos($truncate, ' '); if (isset($spacepos)) { // ...and cut the text in this position $truncate = substr($truncate, 0, $spacepos); } } // add the defined ending to the text $truncate .= $ending; if($considerHtml) { // close all unclosed html-tags foreach ($open_tags as $tag) { $truncate .= '</' . $tag . '>'; } } return $truncate; } I have attached the whole file as well if you want to see the rest. This part of the script has the function that originally automatically added the link to the source article: if($link_original==1){ if(strlen($ret->fullText)) $ret->fullText.="<p><a href='". $item->link."' target='_blank'>".$text_link_original."</a></p>"; else $ret->introText.="<p><a href='". $item->link."' target='_blank'>".$text_link_original."</a></p>"; } The problem is that it gets truncated with the rest of the article now. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=346922.0 Hi again PhpFreakz, yet again I have some issues with my PHP part of my website. Is there any simple algorithm to summarize web news articles in PHP? I'm using the fairly simple below code to output a list of the latest articles, but I'm wanting (not sure if it's possible) to display the articles from the current day in bold so users recognise that they are new and the older ones non-bold. I've tried a few things, but they're not giving the desired results. Code: [Select] <?php $con = mysql_connect("localhost","xxx","xxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxx", $con); $result = mysql_query("SELECT * FROM `articles` WHERE `quotes` NOT LIKE '%yes%' ORDER BY `date` DESC limit 0,14"); echo "<table class='links' border='0' width='100%'>"; while($row = mysql_fetch_array($result)) { echo '<tr><td width="270" valign="top"><h4>» <a href="news/display/'.$row['id'].'">'.$row['title'].'</a></td><td width="40" valign="top"><span class="small">'.date("M d", strtotime($row['date'])).'</span></h4></td></tr>'; } mysql_close($con); ?> Cheers! This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317019.0 Hello all, I'm having some problems with a script ive written which is designed to allow me to send a message to all the users of my site. the form works fine, the SQL works fine but im having a problem with storing php variables and outputting them in the message. The form has a field named "allmessage" which is where i'll type my message, I'll type something like "Hello $Name" and store the text as $allmessage = $_POST['allmessage']; example script //loops through each member while ($row=mysql_fetch_array($sql)) { //sets variables $ID=$row['ID']; $Name=$row['MemberName']; $Email=$row['Email']; $content_type = 'Content-Type: text/plain; charset="UTF-8"' ; mail($Email, $allsubject, $allmessage, $content_type); } //loop ends send us a copy of the mail mail("me@me.com", $allsubject, $allmessage, $headers ); Now what I want to be outputted in the email is "Hello John" or "Hello Paul" but what I get is "Hello $Name". Any ideas?! So, on my website, i have added a "last active" feature, so if someone is surfing the site, they can view when another users last page visit was. so, every second, +1 is added to the $ts variable what i have now, working and all, shows ONLY "NOW!", or ONLY "1 second", ONLY "___ seconds ago"... and so on I have tred over, and over, and over to fix this to my liking, with more instances available, as an example, my current script will show somebody who is 13 months and 26 days inactive, just as "1 year", i want to see the "1 year, 1 month, and 26 days inactive"... or even simpler, just so it displays days/minutes/seconds/NOW! function howlongtil($ts) { $ts=$ts - time(); if ($ts<1) // <1 second return " NOW"; elseif ($ts==1) // <1 second return $ts." second"; elseif ($ts<60) // <1 minute return $ts." seconds"; elseif ($ts<120) // 1 minute return "1 minute"; elseif ($ts<60*60) // <1 hour return floor($ts/60)." minutes"; elseif ($ts<60*60*2) // <2 hour return "1 hour"; elseif ($ts<60*60*24) // <24 hours = 1 day return floor($ts/(60*60))." hours"; elseif ($ts<60*60*24*2) // <2 days return "1 day"; elseif ($ts<(60*60*24*7)) // <7 days = 1 week return floor($ts/(60*60*24))." days"; elseif ($ts<60*60*24*30.5) // <30.5 days ~ 1 month return floor($ts/(60*60*24*7))." weeks"; elseif ($ts<60*60*24*365) // <365 days = 1 year return floor($ts/(60*60*24*30.5))." months"; else // more than 1 year return floor($ts/(60*60*24*365))." years"; }; anyone know how? Code: [Select] <?php $going=''; $name='<span id="name"></span>'; echo "$name"; //results : stevengoh --- wanted $going=substr($name, 1, 17); echo "$name"; //results : <span id="going"> ---- don't want ?> Is it possible to store in php the results of variable id="going" javascript instead of <span id="going"></span>?. Hi, when a user logs out, I want to store the last activity in for the user. I have a db table users: userID userName userPassword lastSession lastActivity ===== ======= ========== ======== ======= 1 bob password 2011-08-09 About.html 2 dre passwords 2011-09-23 Home.php here is logout script: =============== Code: [Select] <?php //run this script only if the logout button has been clicked if(array_key_exists('logout', $_POST)) { require("connect.inc"); $username=$_POST["username"]; $updateLastSessionQuery=mysql_query("UPDATE users SET lastSession=NOW() WHERE userName='$username'"); // end session and redirect //empty the $_SESSION array $_SESSION = array(); session_destroy(); header("Location: xmlShredderLogin.php"); exit; }//END IF for when logout submitted ?> here is Index.php: ============= Code: [Select] <?php session_start(); if(isset($_SESSION["isAuthenticated"])) { require("logout.inc.php"); $username=$_POST["username"]; //print $username."<br />"; print ' <html> <head><title>Home</title></head> <body> <form id="logoutForm" name="logoutForm" method="post" action=""> <input name="logout" type="submit" id="logout" value="Log out" /> <input type="hidden" name="usernameHidden" value='; print$username; print '/> </form>'; mysql_connect("localhost","root"); mysql_select_db("someDB"); $getUserInfoQuery=mysql_query("SELECT lastSession,lastActivity FROM users WHERE userName='$userName'"); $getUserInfo=mysql_fetch_assoc($getUserInfoQuery); print "Last session: ".$getUserInfo["lastSession"]."<br />"; print "Last activity: ".$getUserInfo["lastActivity"]."<br />"; Let's say the last page the user is on is Index.php, so what do I use to track the last page they are on?? I can't user a form b/c if I have to type in the last activity, that's nonsense! So far I have only figured out how to store the current time in last session (but this doesn't work either). I just want to track the last page and then have a switch such as: switch(type) case 1: $lastActivity="About.html"; case 2: $lastActivity="somethingelse.php"; Any help much appreciated! Hey guys, What would you recommend to store db values for later? the only thing I can come up with is doing it this way: $result = mysql_query("SELECT * FROM users WHERE name='$user'"); while($row = mysql_fetch_array($result)) { } { and then using the $row['dbvariable'] later is that the best way? Hi, I am struggling with a form in php. I am trying to add a form by using the include function. I want to include thsi form on all pages so it would be very useful if I can save the current page name somewhere so that I can use to validate the form. For example, this is the form I am trying to include. <?php if(!empty($errors)) { if(isset($errors['sendError'])) { echo '<p><strong class="error">There was a problem with our system please contact us directly.</strong></p>'; } else { echo '<p><strong class="error">Please check the form below for errors.</strong></p>'; } } ?> <form action="index.php" method="post" id="form1"> <p> <label><?php if(isset($errors['name'])) { echo '<span class="error">'; } ?>Name<font color="red">*</font>: <?php if(isset($errors['name'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['name']; ?>" name="name" size="60" align="right" style="background:#EEF5A4" /> <label><?php if(isset($errors['company'])) { echo '<span class="error">'; } ?>Company: <?php if(isset($errors['company'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['company']; ?>" name="company" size="60" align="right" /> <label><?php if(isset($errors['phone'])) { echo '<span class="error">'; } ?>Phone Number: <?php if(isset($errors['phone'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['phone']; ?>" name="phone" size="60" align="right" /> <label><?php if(isset($errors['email'])) { echo '<span class="error">'; } ?>Email<font color="red">*</font>: <?php if(isset($errors['email'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['email']; ?>" name="email" size="60" align="right" style="background:#EEF5A4" /> <label><?php if(isset($errors['enquiry'])) { echo '<span class="error">'; } ?>Enquiry: <?php if(isset($errors['enquiry'])) { echo '</span>'; } ?></label> <textarea id="search1" id="complete" textarea name="enquiry" rows=4 cols=40 value="<?php echo $form['enquiry']; ?>" name="enquiry" size="60" align="right"></textarea> </p> <p> <input type="submit" class="formbutton" value="Submit" /> <input type="reset" class="formbutton" value="Reset" /> </p> <p><font color="red">*</font> Denotes a required field</p> </form> Because I am going to use this form on all pages, I would like it to include whatever the filename is rather than index.php in the first line of the form so that when the user clicks submit, it will stay on the same page but validate the form based on the mandatory fields. I don't know if the question is clear. I would very much appreciate any help at all. Thank you very much. Alright, the register/login system is fully working with sql injection, BUUUT now I want to store their IP Address. WHOLE new function that I've never dealt with before. So I need some help. Am I doing something wrong? I have the IPadd in the database as INT(10) and then I went down to another drop down list and hit unsigned. I feel like I'm doing something wrong with the field in the database.. { $_SERVER['REMOTE_ADDR'] = $IPadd; $sql = "INSERT INTO Member (username,createDate,password,firstName,email,IPadd) VALUES ('$username',NOW(),md5('$password'),'$firstName','$email',inet_aton('$IPadd'))"; mysqli_query($cxn,$sql); $_SESSION['auth']="yes"; $_SESSION['username'] = $username; header("Location: testing.php"); } Im making a application but many users can access it at the same time, also the data that needs to be stored into the database in 3 parts firstly the user will enter some details the comany will fill out the reamining details and the user will then accept or decline the companies proposal. The issue im havign will it be easier to just store all of this information into session variables and then save them into the database at the end when all of the details are ready ? Thank You Can anyone tell me whats wrong with this: The file uploads fine, the url however does not get posted to the database? I added a 'or die' but it didn't execute...Do I need to move the query higher up the script? <?php include ('base.php'); $id = $_GET['id']; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "imgs/pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } $file = $_FILES["file"]["name"]; $sql = "UPDATE `chillp_security`.`staff` SET `picture` = \'imgs/pictures/$file\' WHERE `staff`.`id` = $id;"; ?> |