r/learnphp • • Jul 06 '14

We are here, and we are here to help

18 Upvotes

/r/learnphp has come under the attention of /r/php and we are available to help if you have any questions.


r/learnphp • • Nov 25 '20

I gave myself a challenge : To code a blackjack game on PHP ! I’m not a graphic designer but I managed to make it look good !

Post image
11 Upvotes

r/learnphp • • Jul 16 '14

PHP Home Curriculum -- what do you think?

10 Upvotes

I've worked with PHP for a while, mostly customizing vendor programs that are PHP/MySQL based. I have some independently created, low-use apps out there, too, but they are pretty basic without a lot of OOP.

The more I learn, the more I realize that I need to get serious if I want to take it to the next level and make my own well-done, scalable applications. Most of what I do is not OOP, or in frameworks -- it is basic scripting and largely back-end work (front-end done by others or handled by vendor programs). And I don't work with version control.

My goal is to get a full-time position in development, where I am writing new code (and not just customizing a vendor product).

I work full-time, so my study will mostly be done at home.

I've come up with the following curriculum for home study, to take me to the next level. I was inspired by Josh Kemp's blog on going from Blacksmith to Rails developer when coming up with this.

Edited to add: I've read poor reviews of Code Academy's PHP course. Beginners may want to pick up an intro book in addition to doing the course.


r/learnphp • • Jun 17 '20

Best advanced PHP courses?

8 Upvotes

Most courses just tells you how to do a basic MVC application, but doesn't tell you how to use a production-level architecture and use interfaces and class inheritance in the way a senior developer is expected to use them. Any good course you would recommend? I would recommend Stephen Grider's course for Node.js, but for PHP, I don't really know anyone who's quite at that level.


r/learnphp • • Feb 18 '21

I am trying to output the print_r inside of update-reviews-rating.php, but I can't see them

6 Upvotes
timeout -s9 3h php -d memory_limit=9096M ./update-reviews-rating.php --max=5 --host=www.pancakes.com --lock=reviews_update > /dev/tty1

Is there a way to do this? I tried a bunch of things, but couldn't get it to output something.


r/learnphp • • Jan 02 '21

Please help with Symfony project I inherited

6 Upvotes

Hello everyone.

I just recently inherited a Symfony project. The website I'm supposed to be working on looks pretty simple but I am not at all familiar with Symfony, and the last time I worked with PHP was I think the Bush administration.

So let me tell you what I have. The company gave me credentials for which to SFTP. I SFTP'd into a root user and when I looked around, I didn't really see anything that jumped out to me as application code. I copied everything in the directory anyway. Here's what I have:

a bunch of SQL files
a bunch of .csv files
a mysql-apt-config_version#_all.deb file
certbot-auto bash script
compressed MySQL backup dumps
a epel-release-version#.noarch.rpm and ius-release-version#.ius.centos6.noarch.rpm files
the above both have:
etc/pki/rpm-gpg/RPM-GPG key
etc/yum.repos.d/ with epel.repo and epel-testing.repo
  ^ the ius one also has a -archive and -dev .repo files
usr/share/doc/epe-release-6/GPL

I told the project manager that I couldn't find any of the source code files but he told me "you should do some research on how Symfony projects are architected" or something like that.

So am I supposed to do something with these .repo files to start working on the application?

Any help is greatly appreciated.


r/learnphp • • Apr 05 '20

Are foreach's in alternative syntax implemented as stack?

6 Upvotes

Hi, I am having a problem with putting a foreach inside a foreach in HTML/PHP. I am wondering if the foreach's in the alternative structure are implemented as a stack?

My code can be found below.

I have this array that contains data:

$tasks = [
    [
        "category" => "to do",
        "items" => [
            [
                "title" => "Buy fireworks for New Year",
                "description" => "Make sure they are not dangerous.",
                "id" => 1
            ]
        ]
    ],
];

And here is my HTML in which I am trying to:

  1. Display the category name.

  2. Loop through the tasks in the $task variable to put the items inside a <li> inside a <ul>.

<div class="appcontainer">
    <?php foreach ($tasks as $taskGroup) : ?>
        <div class="task-container">
            <h2 class="task-container__title"><?=$taskGroup['category']?></h2>
            <? if (count($taskGroup['items'])) : ?>
                <ul class="task-container__items">
                    <?php foreach ($taskGroup['items'] as $ta) : ?>
                        <!-- <li class="task-container__item">
                            //////////PUT THE ITEMS HERE///////////
                        </li> -->
                    <? endforeach; ?>
                </ul>
            <? endif; ?>
        </div>        
    <?php endforeach; ?>
</div>

As you can see, I am looping through the categories in the $tasks variable. Then for each $items in the category, I want to loop through them and add them as <li> elements. However, I always get the error:

Parse error: syntax error, unexpected end of file in ...

when I add the second foreach inside the first foreach.

Am I doing something wrong? Or nesting a foreach inside a foreach is forbidden in PHP?


r/learnphp • • Mar 24 '20

how did you learn Design Patterns in PHP?

6 Upvotes

What is the best way you learned design patterns in PHP? Any particular books or resources?


r/learnphp • • Mar 06 '18

How to improve your PHP code? Part 1 - Automated tools

Thumbnail
schibsted.pl
6 Upvotes

r/learnphp • • Apr 16 '16

After years of not being able to motivate myself to learn PHP and SQL, I finally did a thing...

Thumbnail iconofsin.net
6 Upvotes

r/learnphp • • Jul 11 '14

The Coupon Code Programming Exercise

6 Upvotes

Taken from codewars:

Your online store likes to give out coupons for special occasions. Some customers try to cheat the system by entering invalid codes or using expired coupons.

Your mission: Write a function called checkCoupon to verify that a coupon is valid and not expired. If the coupon is good, return true. Otherwise, return false.

A coupon expires at the END of the expiration date. All dates will be passed in as strings in this format: "June 15, 2014"


r/learnphp • • Apr 21 '25

Just a php Enthusiast here. Learning by doing it...

5 Upvotes

The best way to learn it is to use it.
Too bad they do not teach php in hyperskill dot org.
If i see another "hello world" or Car Object teaching example am gonna go nuts.
So I decided to try to create a proper php oop MVC framework with user Login and Posts (crud)
so far it has been very educational.

PHP, OOP, and the development platform is very Alien to be. I come from a COBOL background.


r/learnphp • • Jun 13 '23

Anyone had experience with Leaf PHP?

5 Upvotes

I was watching a PHP Frameworks Speed Comparison in 2023 video on YouTube and noticed a framework I've never heard of before called [LeafPHP] (https://leafphp.dev/) doing really well.

It seems to have clean design, and good docs, including videos on its YouTube channel. Even a discord where the creator hangs out. I have only skimmed the docs though and don't really have the experience to "judge" frameworks based on their design.

I was wondering if anyone has invested time in Leaf and would care to share their experience with it.

Thanks.


r/learnphp • • Dec 14 '20

How do you access the files in your Google drive?

5 Upvotes

https://vitux.com/how-to-access-your-google-drive-account-in-ubuntu/

I followed this tutorial and got it working. Now, I want to create a little php script that prints out all the files in my Google drive account. How do you find the path to the mounted online drive? Also, is that all I need to do?


r/learnphp • • Jun 07 '20

I found what seems to be a security hole in my PHP website, is it a hole and how can I fix this?

5 Upvotes

So basically my authentication module works like this:

  1. A user enters their email and password and (using password_verify) I check it against the database, if everything checks out, I set a user session with a randomly generated user ID that I set when they signed up and I use that ID to identify them throughout the website, as expected. (PHP: $_SESSION['userId'] = $row->user_id;)

  2. Setting aside persistent logins (which also has a hole), the PHP session is the only thing the user needs to have set to be logged in.

I found a hole where I can jump in the browser console and change the value of the PHPSESSID cookie from the value of it with a logged in user. Once I change that value, if I reload the page I'm logged into their account, only with the 36 or so characters of the PHPSESSID.

My question is, is there a better way to handle user sessions? This /seems/ like a hole to me, but maybe not. How hard is it to steal cookie info from someone's browser? Should I be worried?

All of the articles and tutorials I've seen on PHP authentication recommend using PHP Session variables, so this hole is a little worrying, if it even is a hole.

(My auth code is pretty long and I didn't want to overload you with code but let me know if you want it.)


r/learnphp • • Apr 27 '20

How would I implement this Restful API to insert and retrieve data using PHP?

5 Upvotes

Being fairly new to Restful Api, I am in doubt as to how I would retrieve and update my MySQL database using the following PHP Restful API.

<?php

// get the HTTP method, path and body of the request
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$input = json_decode(file_get_contents('php://input'),true);
 
// connect to the mysql database
$link = mysqli_connect('localhost', 'user', 'pass', 'dbname');
mysqli_set_charset($link,'utf8');
 
// retrieve the table and key from the path
$table = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));
$key = array_shift($request)+0;
 
// escape the columns and values from the input object
$columns = preg_replace('/[^a-z0-9_]+/i','',array_keys($input));
$values = array_map(function ($value) use ($link) {
  if ($value===null) return null;
  return mysqli_real_escape_string($link,(string)$value);
},array_values($input));
 
// build the SET part of the SQL command
$set = '';
for ($i=0;$i<count($columns);$i++) {
  $set.=($i>0?',':'').'`'.$columns[$i].'`=';
  $set.=($values[$i]===null?'NULL':'"'.$values[$i].'"');
}
 
// create SQL based on HTTP method
switch ($method) {
  case 'GET':
    $sql = "select * from `$table`".($key?" WHERE id=$key":''); break;
  case 'PUT':
    $sql = "update `$table` set $set where id=$key"; break;
  case 'POST':
    $sql = "insert into `$table` set $set"; break;
  case 'DELETE':
    $sql = "delete `$table` where id=$key"; break;
}
 
// excecute SQL statement
$result = mysqli_query($link,$sql);
 
// die if SQL statement failed
if (!$result) {
  http_response_code(404);
  die(mysqli_error());
}
 
// print results, insert id or affected row count
if ($method == 'GET') {
  if (!$key) echo '[';
  for ($i=0;$i<mysqli_num_rows($result);$i++) {
    echo ($i>0?',':'').json_encode(mysqli_fetch_object($result));
  }
  if (!$key) echo ']';
} elseif ($method == 'POST') {
  echo mysqli_insert_id($link);
} else {
  echo mysqli_affected_rows($link);
}
 
// close mysql connection
mysqli_close($link);

r/learnphp • • Apr 28 '19

PHP udemy course.

5 Upvotes

Please recommend the best udemy course to learn php.


r/learnphp • • Mar 19 '19

Cleanest way to do multiline HTML inside PHP?

5 Upvotes

I notice line breaks/hard returns seem to change the HTML and cause errors. But this code seems verbose:

    if ( !empty( $user_name ) ) {
        $output = '<a class="twitter-timeline" href="'; 
        $output .= esc_url( 'https://twitter.com/' . $user_name );
        $output .= '">Tweets by ' . esc_html( $user_name );
        $output .= '</a><script async ';
        $output .= 'src="//platform.twitter.com/widgets.js"';
        $output .= ' charset="utf-8"></script>';
    } else {
        $output = '';
    }
    return $output;

Is there a cleaner way to do it or is this the best option?


r/learnphp • • Oct 10 '18

What's the most efficient way to learn PHP?

5 Upvotes

I have a new job that involves PHP & Laravel! What's the best way to study?

(I have intermediate JavaScript skills and know how to do in PHP; Echo, Variables, Loops, String manipulation, Templating that kind of thing.)

  1. I like online video tutorials: which do you reccomend?

  2. Any really good books on PHP?

  3. How to go from beginner level to intermediate?

  4. What's Laravel and what stage & how to learn it?

  5. Are there standard exams for PHP (to have a proof of knowledge)?

  6. How to study and pass these exams quickly?

  7. What bits of PHP are best to learn in terms of working with WordPress & Wordpress plugins?

Thanks!


r/learnphp • • Dec 26 '17

I know what I want to do, but not sure about how to do it...

5 Upvotes

Hello learnphp, I have a project that I want to make and think php might be the answer. If it isn't, I'd rather know now than dumping a ton of effort into a janky solution. Any advice the community can give is greatly appreciated.

The project seems pretty straightforward. I want a form on a website to produce a Word document, or optionally a PDF document, or both. The document is comprised of several sections of canned language that I want to dump into the Word doc if the user selects that option and a user provided narrative section. Lets use a report as an example document. The user would need to write about multiple things like a house, a car, and a helicopter. When the user opens the form, they would select the house, car, and helicopter options and these canned language descriptions would automatically be added to the word document. The descriptions would be at least a paragraph, maybe more. Also, because the user selected the helicopter option, a warning section would be added to the document towards the beginning. I planned on keeping this canned language in a sql database and having the php reference it. I'm just learning about arrays which I think might work, but seems less efficient for such long strings.

For reference, I found a GitHub library named PHPOffice/PHPWord that looks like a useful resource, but since I'm just starting out I haven't really sorted it out yet.

The tricky bit is that I need the Word document to look exactly like a preexisting Word document.

Am I on the right track? should I be looking elsewhere? Is there an easier solution? Any advice is definitely appreciated!


r/learnphp • • Apr 25 '16

[Question] How to start PHP? - Tool kit

5 Upvotes

Hello everyone, I'm going to start with PHP, and I'd like to know what is the best way to start. What are the tools that I have to install? Installing XAMPP is a good idea? Is there a better way to start PHP, without installing XAMPP? What is the tool for managing dependencies? What Web Framework should I use? and so on. I'll really apreciate it, if you can help me with that. Thanks.


r/learnphp • • May 30 '15

PHP Drills - Part 1

Thumbnail
xcodula.com
5 Upvotes

r/learnphp • • Oct 21 '14

Learn PHP with us! Free 12 week internet study group starting Oct 27

5 Upvotes

I'm assembling a group of folks that want to bring their experience and inquisitive natures together to encourage and help each other learn PHP.

I have thrown together a 12 week 'curriculum' that hopefully covers all the fundamentals of PHP, including some database stuff towards the end. Ideally after 12 weeks participants should be in good shape to approach more advanced stuff like frameworks and CMS/wordpress hacking.

If you're interested please read the intro thread here, which has instructions for participating: http://grokphp.buscommando.com/index.php?topic=2.0

Prerequisites:

  • knowledge of HTML/CSS, basic web stuff (if you can put together a crappy static page you'll probably be fine)

  • previous experience with a scripting or programming language (if PHP is your first language you will probably have a really hard time keeping up)

  • Mac, Windows, or Linux PC + Internet connection


r/learnphp • • Oct 04 '24

Can’t run : Php DB connectivity program: [Class "mysqli" not found

4 Upvotes

I have got the following program from:

https://www.w3schools.com/php/php_mysql_connect.asp

<?php
$servername = "localhost";
$username = "root";
$password = "";

// Create connection
$conn = new mysqli($localhost, $root, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

The name of above program is:dbconnect.php

I have got mysql running:

puser@lc2530:~$ sudo mysql

[sudo] password for puser:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.39-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

mysql> show databases;

+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

mysql>

I have other Php programs running:

$ ls /etc/apache2/mods-available/php*

/etc/apache2/mods-available/php8.1.conf
/etc/apache2/mods-available/php8.1.load
/etc/apache2/mods-available/php8.2.conf
/etc/apache2/mods-available/php8.2.load
zulfikar@lc2530:~$

localhost is also running but when give the command

But my program is no generating any out. In the log file I am getting the error:

[Fri Oct 04 17:44:12.762726 2024] [php:error] [pid 1107] [client 127.0.0.1:55776] PHP Fatal error: Uncaught Error: Class "mysqli" not found in /var/www/html/dbconnect.php:7\nStack trace:\n#0 {main}\n thrown in /var/www/html/dbconnect.php

Somebody please guide me. Zulfi.


r/learnphp • • Sep 20 '24

How can I avoid seeing warnings for Laravel magic methods?

4 Upvotes