PHP - Not Quite A Noob, I Have One Years Worth Of Experience 10 X And Am Trying To Improve My Skills.
I have started learning OOP, by following a few tutorials, My problem with most tutorial is they show you how, but don't tell you the what and the why. It's all good an well seeing what to do, but if you have no idea why it's being done, you don't learn much. I started a tutorial on Udemy but am not actually gaining a lot from it. I want to alter the code so that it will do it the way I want it to. I am not wanting you to write the code for me, if you do please explain it so that I can understand the logic, preferably show me where to make changes and point me at the php tutorial that can solve my problem. I have been trying to solve this for a couple of weeks now, I tried a few things but none worked.
The full followLinks function function followLinks($url) { global $alreadyCrawled; global $crawling; $host = parse_url($url)["host"]; $parser = new DomDocumentParser($url); $linkList = $parser->getLinks(); foreach($linkList as $link) { $href = $link->getAttribute("href"); if((substr($href, 0, 3) !== "../") AND (strpos($href, $host) === false)) { continue; } else if(strpos($href, "#") !== false) { continue; } else if(substr($href, 0, 11) == "javascript:") { continue; } // I need to change this below somehow, the two arrays are identical, // What I want to do is move $href(crawled) to $alreadyCrawled and remove it from $crawling // I also want to check if the current $href (crawling) is in $alreadyCrawled and if it is skip crawling and move on to the next one. //In essence I want to prevent the crawler from crawling anything already crawled in order to speed up the crawler. $href = createLink($href, $url); if(!in_array($href, $alreadyCrawled)) { $alreadyCrawled[] = $href; $crawling[] = $href; } else { continue;} echo $href . "<br>"; } array_shift($crawling); foreach($crawling as $site) { followLinks($site); } } $startUrl = "https://imagimedia.co.za"; followLinks($startUrl); ?>
Result.
https://imagimedia.co.za/../seo/ https://imagimedia.co.za/../pages/marketing.html https://imagimedia.co.za/../pages/web-design.html http://imagimedia.co.za/ https://imagimedia.co.za/../website-cost-quote.php https://imagimedia.co.za/../blogs/history.html https://imagimedia.co.za/../blogs/payment.html https://imagimedia.co.za/../blogs/copy.html https://imagimedia.co.za/../blogs/cycle.html https://imagimedia.co.za/../blogs/information.html https://imagimedia.co.za/../blogs/privacy.html https://imagimedia.co.za/../blogs/terms.html https://imagimedia.co.za/../blogs/content-is-king.html https://imagimedia.co.za/../blogs/pretoria-north-web-design.html https://imagimedia.co.za/../blogs/annlin-web-design.html https://imagimedia.co.za/../blogs/ http://imagimedia.co.za http://imagimedia.co.za/../seo/ http://imagimedia.co.za/../pages/marketing.html http://imagimedia.co.za/../pages/web-design.html http://imagimedia.co.za/../website-cost-quote.php http://imagimedia.co.za/../blogs/history.html http://imagimedia.co.za/../blogs/payment.html http://imagimedia.co.za/../blogs/copy.html http://imagimedia.co.za/../blogs/cycle.html http://imagimedia.co.za/../blogs/information.html http://imagimedia.co.za/../blogs/privacy.html http://imagimedia.co.za/../blogs/terms.html http://imagimedia.co.za/../blogs/content-is-king.html http://imagimedia.co.za/../blogs/pretoria-north-web-design.html http://imagimedia.co.za/../blogs/annlin-web-design.html http://imagimedia.co.za/../blogs/ I know I am also going to have to exclude duplicates created by the http and https pages. But that is not my main issue. Similar TutorialsHi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin?? echo '<select name="year_of_birth">',"\n"; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { if($i == $thisYear) { $s = ' selected'; } else { $s=''; } echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n"; } echo '</select>',"\n"; Little topic that's gonna bug me if I don't ask
I'm trying to learn static layouts, and I'm just getting the hang of them. A few friends are telling me to go responsive to accommodate mobile/tablet users? I can see it from a business sites perspective where you want all types of users and with ease of access, but my site is going to be a gaming modification community, where mobile users aren't really the target audience as it's quicker and easier to download them on the PC than a Phone. I was going to accommodate that audience by allowing them very basic usage (chat, forums, account) and leave off the heavy parts like the gallery, and downloads.
Am I going in the wrong direction? Should I be heading down the responsive route? I've literally only just started the first page for the site, but it'd mean re-learning a whole bunch more new stuff which'd prolong the sites progress.
Just looking for a little advice in which direction to head
Hello Php Freaks! I have decided to create a website and got exactly how i want it in my head, but the problem is.... i can't really program any php, so i've been reading different tutorials for every bit of those things i need for my site.... Still its very hard.... So i were wondering if anyone could give me some help? A tutorial, or help me with the errors i encounter and so on. Here is what i plan on getting: (The site will be for a guild in a game) 1. Login 2. News 3. Some sort of photo/video archieve 4. Rankings 5. Profile pages (With name, age, character name and so on). 6. Medals (Hooked up with Rankings mostly). 7. Private messages 8. Application site 9. calender And thats it, its quite alot of work... But i believe that if i read though alot of tutorials i miiight get it all done one day... But first i guess i gotta learn how to set up a site so it looks good xD!... - Seems like im a lost cause, anyways... anybody who got any kind of help ?... Would be soo appriciated. So I've been using this websocket: http://code.google.com/p/phpwebsocket/
Love it because I don't know javascript as well as I do PHP. (Absolutely hated learning socket.io and their style of javascript, just gave up on it).
Anyways, I'm using MYSQL with the php socket for the chatroom authentication with my forum. (Sending the cookie values to the socket, to authenticate user). It's working fine and the MYSQL only get's called for each time a user is authenticated (logged into the websocket). The usernames and sessions are actually stored in a Temporary array which is nice. So only on authentication it queries the database for the authentication itself. (Very lightweight and a smart way for a chat system).
My question is, how does this compare to a node.js and socket.io server with a MYSQL plugin, etc? seems like that route would actually be more intensive?
I don't even need to include the socket.io.js for the client / PHP setup I have here as well. This way seems lightweight in my opinion (clientside) but not sure on the server end.
Thoughts?
TLDR: Running a PHP Websocket as compared to a node.js/socket.io server with mysql plugins the same in performance? Is it even noticeable? Should I be worried?
Edit: Disregard compatibility issues too. ( Using this http://tools.ietf.org/html/rfc6455 protocol is fine for my audience and intentions )
Edited by Monkuar, 02 December 2014 - 07:46 PM. I am using Amazon's S3 service to allow users to upload images. Since you have to pay for this service, my plan was to resize all uploaded images (maybe to a max of 200 pixels wide or something) immediately before sending them to Amazon. I googled this and only thing I found said that "resizing on the fly is slow and expensive because disk space is cheaper than CPU." Is this accurate? Anyone have any thoughts on this? I feel like I have to restrict the size of images some way because I don't wan't people uploading huge 2000x2000 images. In case it matters, below is some code I have used below for resizing (albeit on my own server), so I imagine I'll use something similar for this new project which ultimately sends the image to Amazon. Code: [Select] // This is the temporary file created by PHP $uploadedfile = $_FILES['userfile']['tmp_name']; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture the original size of the uploaded image list($width,$height) = getimagesize($uploadedfile); $newheight=70; $newwidth= 70; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $imagefolder = 'images/userimages/user' . $_SESSION['userid'] . '.jpg'; $filename = $imagefolder; $_SESSION['filename'] = $filename; if (imagejpeg($tmp,$imagefolder,100)) { $imagemessage = "File is valid, and was successfully uploaded into FOLDER.\n"; $success="yes"; } else { $imagemessage = "Possible file upload attack!\n"; $success="no"; } imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. } This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=328252.0 I am trying to get a website up for my mother and am running into so many brick walls. There is so much i dont know about php. I know basics. What i would really love is some to try to tutor me through what i need to know. If anyone could do this for me i would be forever grateful. //level 2 - 500 //level 3 - 1500 //level 4 - 3500 //level 5 - 6000 function experience($L) { return $L * 495; } function Get_The_Level($exp) { return floor($exp / 495) + 60; } function Get_Max_Exp($L){ $end=0; if ($exp == 0){ return 0; $end =1; } for($L=1;($L<1000 && $end==0);$L++) { $exp = experience($L); //echo $exp; if ($exp >= $user_class->exp){ return $exp; $end=1; } } } cant get over level 70 can any one help to get it like level 1=200 level 2 =400 level 3= 600 and so on any help HI all, Yesterday i read quite alot about htmlentities() htmlspecialchars() mysql_real_escape_string But today i stumbled upon filter() (http://www.w3schools.com/php/php_filter.asp). Does anyone know if this is also a good way to sanitize and may even be an alternative for the other functions? OR is it something completly different? I am still a novice with this so please enlighten me : ) TY I am in the process of developing a commercial web application to be offered as a SAAS to small businesses in the U.S. on a subscription basis. I have been working with a developer for a while now and the project timelines are starting to slip. I need someone to help get the project back on track and completed so we can roll it out and I can start selling it. Once the project is completed, there will be many ongoing opportunities for future work making customizations for specific customers and developing enhancements and new features and versions. It could very easily turn into a full time gig.
A large portion of the project is done but there are some key features that need to be completed.
I need to get this done as soon as possible - please contact me on skype - patrick.mathews67 or by email - patrick@systemvillage.com.
It was started using phpixie and I think it would be best to continue with it, however, I need to get it done so I am open to suggestions.
I can determine 3 years from today, but How do determineo 3 years from march 1st? So I want to echo out "3/1/2013"? Thanks! Hi Guys, In a form within PHP coding i can get the the next 10 years with the following code: Code: (php) [Select] <?php $date_future = date("Y", strtotime('+10 year')); $date_year = date("Y"); for($i=$date_year;$i<$date_future;$i++){ if($date_year == $i){ echo "<option value=\"$i\" selected=\"selected\">$i</option> \n"; } else { echo "<option value=\"$i\">$i</option> \n"; } } ?> I have tried to mess about with the same code and try and get it to work for the last 10 years without any luck. He's what i did: Code: (php) [Select] <?php $date_past = date("Y", strtotime('-10 year')); $date_year = date("Y"); for($i=$date_year;$i>$date_past;$i++){ if($date_year == $i){ echo "<option value=\"$i\" selected=\"selected\">$i</option> \n"; } else { echo "<option value=\"$i\">$i</option> \n"; } } ?> I would appreciate any help with this. I need to secure my code more Code: [Select] $_POST['amount'] = intval($_POST['amount']); if ($_POST['amount'] <= 0){ message($lang_common['Bad request']); } if (!is_numeric($_POST['amount'])){ message($lang_common['Bad request']); } $_POST['amount'] will be the amount of gold people will beable to send to each other. any sql injections vulnerability right now? if so, help i casted my intval and is_numeric on it any other ways to secure it with php functions as of right now it can only be numeric right? Part of my class: using PHP5 ( http://php.net/manua...ssword-hash.php) If you know of anything new in PHP5 related to please do share
protected function create_hash($string){ $password = "#" . strrev($password); $grs = $this->grs("|WordToTheWise",rand(22, 50)); $hash = password_hash("_" . strrev($string), PASSWORD_BCRYPT, array('cost'=>rand(4,14),'salt'=>$grs)); return strrev($hash); } public function verifyhash($string, $hash_string){//verifies that the hash is equal to the password return (password_verify("_" . strrev($string), strrev($hash_string)) ? true : false); } private function grs($string_append = "", $length = 22) { $length = $length - strlen($string_append); $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&()_*,./;[]|'; $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) - 1)]; } return $randomString . $string_append; }Okay so u use strrev on my string and hash just to make everything a bit more CONFUSING and i append the string with a "]" just to make the password harder to brute the strrev and append string is not meant to make the hash any more secure. I store the reversed hash in my DB as a varchar The point of the reverse hash is only to make the hash a little more unrecognizable to the human eye. The Const is randomly chosen 4 - 14, and the salt is randomly generated with a special string appended. How would you improve the hashing? Edited by Richard_Grant, 09 September 2014 - 11:48 PM. Hello. I have written this script where user restaurant owner can add his place to the database of all local restaurants. (insert basic information into database, add up to 3 images, thumbnail creation, insert image information to database). It works well on localhost, but i would like some suggestions for improvement. Im not very sure of its structure, it may not execute well once it is online. And i also think there are too many "IF's". But i really have no idea how to do it any other way. Thanks for all the suggestions. Code: [Select] <?php if(!defined('PROTECTION') || constant('PROTECTION') != 'demover') { echo "fuck off intruder!"; exit; } $naziv = mysql_real_escape_string($_POST['Naziv']); $naslov = mysql_real_escape_string($_POST['Naslov']); $kraj = mysql_real_escape_string($_POST['Kraj']); $telefon = mysql_real_escape_string($_POST['Telefon']); $web = "http://www.".mysql_real_escape_string($_POST['Spletna']); $gm = mysql_real_escape_string($_POST['Lokacija']); //$gmaps = gmParse($gm); $gmaps = 10; $fill="INSERT INTO bpoint (sName, sAddr, placeID, sPhone, sWeb, sGMaps, companyID) VALUES ('$naziv','$naslov','$kraj','$telefon','$web','$gmaps','$cID')"; if (mysql_query($fill)) { $lastID=mysql_insert_id(); $path="./truck/".$cID."/".$lastID; $pname=$_FILES["pic"]["tmp_name"]; $num=0; if (count($_FILES["pic"]) && mkdir($path, 0777)) { include "thumbs.php"; foreach($pname as $imag){ $bname=date("YmdHis").$num; $num++; $finalpath=$path."/".$bname.".jpg"; $finalthumb=$path."/".$bname."_thumb.jpg"; if($imag!="") { if (move_uploaded_file($imag, $finalpath)) { make_thumb($finalpath,$finalthumb,150); mysql_query("INSERT INTO images (name, companyID) VALUES ('$finalpath', '$cID')"); } } } } unset($_FILES["pic"]); } else {die(mysql_error());} ?> I am searching the database for items that are plaques. There are different years of plaques. I find all the plaques sorted by year. My display puts them in rows of 4 max. What I want is to display them by year with a different year on a different line. Right now there are 4 (1963), 3 (1965), 1 (1978) all bunched together. 1963, 1963, 1963, 1963, 1965, 1965, 1965, 1978 What I want is: 1963, 1963, 1963, 1963, 1965, 1965, 1965, 1978, Any help would greatly be appreciated. <?php include 'config0.php'; $search=$_GET["search"]; // Connect to server and select database. mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect"); mysql_select_db("$dbname")or die("cannot select DB"); $result = mysql_query("SELECT * FROM table1 WHERE plaques LIKE '%$search%' ORDER BY year") or die(mysql_error()); // store the record of the "" table into $row //$current = ''; // keeps getting the next row until there are no more to get if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 4; echo "<table align=center>"; echo "<br>"; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; echo "<td align=center>"; ?> <div style="float: left;"> <div><img src="<?php echo $tn; ?>"></div> </div> <?php echo "</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i > 0) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo '</tr>'; } mysql_close(); ?> </table> How can i group the data by year to build the graph I need the data to be like so 2012 0 - total customers 0 - total customers 0 - total customers 0 - total customers 0 - total customers 9 - total customers 5 - total customers 3 - total customers 5 - total customers however i only have this data Code: [Select] total_customers month year 1 Aug 2011 9 Oct 2011 8 Nov 2011 4 Dec 2011 4 Jan 2012 so i need to make it show 0 for the months i dont have data for Code: [Select] <div id="dash_chart" class="portlet x9"> <div class="portlet-header"> <h4>Customer Growth</h4> <ul class="portlet-tab-nav"> <li class="portlet-tab-nav-active"><a href="#tab1" rel="tooltip" title="Customers">Customers </a></li> <li class=""><a href="#tab2" rel="tooltip" title="Sales over last 48 hours.">Sales </a></li> </ul> </div> <!-- .portlet-header --> <div class="portlet-content"> <div id="tab1" class="portlet-tab-content portlet-tab-content-active"> <?php echo '<table class="stats" title="area" width="100%" cellpadding="0" cellspacing="0"> <caption>Customer Base Growth</caption> <thead> <tr>'; $monthNames = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $i = 0; foreach ($monthNames as $month){ echo '<th>'.$month.'</th>'."\n"; } echo '</tr> </thead>'; $q = "SELECT count(cus_id) as total_customers, DATE_FORMAT(sign_date, '%b') as month, YEAR(sign_date) as year FROM customers GROUP BY YEAR(sign_date), MONTH(sign_date) ORDER BY sign_date ASC"; $r = @mysqli_query ($dbc, $q); $data = array(); if (mysqli_affected_rows($dbc) >= 1) { echo '<tbody> <tr> <th>2011</th>'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { } } echo '</tr>'; ?> <tr> <th>2012</th> <td>3</td> <td>4</td> <td>2</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>3</td> <td>5</td> <td>3</td> <td>9</td> </tr> </tbody> </table> Ok so here is my code. Ignore the $_POST['dobm']. That is part of the whole script. All I want to know is how to set the list from 1998 to 1911 in descending order. I already tried making $i = 1998 and make $i - 1 til $i >= 1911. It seems to go in an infinite loop when I do that. Code: [Select] <?php for($i = 1911; $i <= 1998; $i++) { if ($_POST['dobm'] == $i) { echo '<option selected="selected" value="'.$i.'">'.date('Y', mktime(0,0,0,0,0,$i+1)).'</option>\n'; } else { echo '<option value="'.$i.'">'.date('Y', mktime(0,0,0,0,0,$i+1)).'</option>\n'; } } ?> Hi everyone, I'm writing a science fiction wordpress blog set 10 years into the future. I basically need all posts to display as if they are 10 years from now. Eg. posts needs to display as: February 7, 2021 instead of February 7, 2011 This will be for every post that I write. How can I automatically add 10 years to every post date? (And where would I put that code?) Currently, the wordpress php is calling the date with `<?php the_time(__('M j, Y')) ?>` I realise it's a bit of an odd request, but it's necessary for this particular project. I know it's possible - but I'm brand new to php and am not sure how. =) I hope someone out there can help. It would be very much appreciated. many thanks in advance Luke Hi Guys, I have a simple PHP search facility (Below this post) for my customer system which uses a input form so users enter a customers name/telephone/address and it echos the result. Its great but I observed as my customer table got bigger the search got less accurate, what i mean is when you search for mr test is give ur mr test along with mr andy and ms danielle. Its ok but those any know how to make my search code better or can y'all help me with a better php search script. Thanks. <?php $query=$_GET['query']; $query= str_replace("'","",$query); // Change the fields below as per the requirements $db_host="localhost"; $db_username="root"; $db_password=""; $db_name=""; $db_tb_name="customer"; $db_tb_atr_name="c_name"; $query= str_replace("'","",$query); //Now we are going to write a script that will do search task // leave the below fields as it is except while loop, which will display results on screen mysql_connect("$db_host","$db_username","$db_password"); mysql_select_db("$db_name"); $query_for_result=mysql_query("SELECT * FROM customer WHERE c_name like '%".$query."%' OR c_telephone like '%".$query."%' OR c_address like '%".$query."%'"); while($row=mysql_fetch_assoc($query_for_result)) { $c_id = $row['c_id']; $c_name = $row["c_name"]; $c_address = $row["c_address"]; $c_postcode = $row["c_postcode"]; $c_city = $row["c_city"]; $c_telephone = $row["c_telephone"]; $c_email = $row["c_email"]; $salesman = $row["salesman"]; echo '<table width="100%" border="0"> <tr> <td><a href="customers.php?id=' . $c_id . '"> ' . $c_name . '</a> - ' . $c_address . ' - ' . $c_city . ' - ' . $c_telephone . '• <a href="customer_edit_index.php?pid=' . $c_id . '">edit</a><br /><br/></td> </tr> </table>'; } mysql_close(); ?> |