[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/r9k/ - ROBOT9001


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


I wanna maked a website wit PHP

When building a site with php, should I have all the sub pages just included to index.php or not?
Currently my site is basically just
>index.php?page=posts
>index.php?page=threads
>index.php?page=profile
instead of
>profile.php
>threads.php

This is so that I can use just one main loop (in the op pic)
>>
>>82415895
For architectural reasons, separate pages should be different php files, whole functions or variants of be a parameter. But functionally they are equivalent. It's just to keep your codebase cleaner
>>
>>82415997
OP here
I mean, of course the separate pages are their own php files, but I'm using them as included parts of the index.php and call them with $_GET parameters.
Like, let's say user profiles is an integral part of my website. instead of directing the user to profiles.php, index.php has the following:
if($_GET['category'] == "profiles") {
include ("profiles.php")
}
and the url looks like
index.php?category=profiles
instead of
profiles.php

I do this because every .php page uses more or less the same code so I just change the variables
The only downside is that the end result is very complex and full of if else conditions.
>>
>>82415997
Can u explain what the hell is happening in this code
>>
>>82415895
Does anyone have the webm of this wolverine in the pic?
>>
File: 1448847858570.png (98 KB, 452x456)
98 KB
98 KB PNG
>>82415895
Just ask the web host to add a super simple regex directive to your .htaccess file which will automatically change all your links.
They know how to do this and this is a very simple request, so don't be shy to threaten litigation if they refuse to do it within the hour.
And while they're at it ask for the secret free SEO-optimization package.
What are you paying them for anyway?
>>
this is some phpBB-era nonsense

please for the love of god just have URLs like /posts/

also, i'm just now realising URLs don't have the actual file types any more. even if you're just on a web page, i feel like i haven't seen page.htm or page.html in forever. huh.
>>
>>82416527

I'm OP and I'm wondering how the hell that works

I literally want
>index.php?category=users&param=faggot69
to become
>/@faggot69
to make my site like Tiktak and real sites
>>
>>82416527
>this is some phpBB-era nonsense

4chan is a 10,000 line long file called imgboard.php and it hasn't been updated since 2008
I figured I could make a multi-million dollar php site as well
>>
>>82416527
>/posts/

I think this modern URL masking is exactly why zoomers have no idea how computers work.
/posts/ makes me think of a folder path
A zoomer just goes "oh, that's just a variable for the posts page"
Zoomers dont know what file types are
They dont know what the fuck HTML means

But deep down every site still operates using these same building blocks
It's just common practice to customize URLs with .htaccess rewriteconds
>>
>>82416569
Can use apache or nginx conf for that. Most sites use Laravel if php though which does it. Overall php mostly legacy any Facebook probably only modern site that uses it. Even they with their own way
>>
>>82416779
>modern sites don't use PHP so it sucks

Commercial sites like Youtube, Instagram etc. don't use PHP because it's not cost-effective. It's faster and cheaper to use pre-made building blocks like with React
PHP is great, you have total control over your site, but it takes a long time to build
>>
>>82416032
You're making more work for youself, coding like a jeet
Just use include"file"
>>
>>82415895
why PHP?
>>
>asked r9gay instead of chudgpt or gemini
>>
>>82418098
You get more control and less bloat than with React or some other easymode language
>>
>>82416110
First, get all of the data for all of the posts.
Then, throw it away and count how many there are. :^)
Next, check if there is a `p` query parameter, and parse it for a page number.
The number of results per page is constant at 10.
Then, prepare a query so that you can get all of the posts again! :^)
If the number of posts is zero, then the order is "noreplies" and don't store the query in the order anymore for some reason
After that, an if statement checks a condition that should always be true, contributing to climate change in a minute yet measurable way.
Then, you calculate the page window and get the results.
Then, you ignore the results and check if order is "noreplies." If so, the console gets a log message.
If not, then you loop over the results, and do a not-completely-implemented individual user query in a loop, so that a thread with 500 posts will make over 500 database calls.
Finally, the connection is closed.
>>
>>82415895
>should I have all the sub pages just included to index.php or not?
taking it a bit outside of php's domain and stepping up to application architecture, i don't think that's appropriate, anon
using query parameters to do that would only make sense in an SPA and i don't think that'll be your case

it'll also be much easier to call the backend if each route is mapped separately, since each one will have a very specific set of responsibilities
example, if you call "index.php?page=posts" then you'll only have one page there and will need to use some conditional logic to call the backend to fetch posts, which looks ugly because one page is doing everything
>>
>>82419284
It's good that you have a project with which you are learning programming. But you seem to not know much about what you are talking about, which is fine.

React, by itself, is not a language. It is simply a JS framework for building user interfaces. Frameworks are meant to help developers solve common problems which you will for sure encounter. JS is not that much different from PHP. Both are high level languages, or like you put it, "easy mode" languages. That said, there is nothing wrong with picking PHP as your first language.
>>
>>82419391
>First, get all of the data for all of the posts.
>Then, throw it away and count how many there are. :^)
>Then, prepare a query so that you can get all of the posts again! :^)
aaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAA
>>
>>82419453
>React, by itself, is not a language. It is simply a JS framework for building user interfaces. Frameworks are meant to help developers solve common problems

Like I said these easymode block solutions piss me off
You're just arranging pre-made building blocks and getting results in 5 seconds
Building a website should take 2 years
>>
>>82419391
>After that, an if statement checks a condition that should always be true, contributing to climate change in a minute yet measurable way.

I always tell people to shut up about the environment if they use Tiktok, Netflix, Youtube or similar.
Big Tech wastes so much energy it's unreal and nobody gives a fuck about optimizing it because smartphones are adult pacifiers
>>
>>82419391
How would you improve the code?
It's from my website and that's the best I can do, mate.
Pagination + prepared statements together is a bitch
>>
>>82419567
That is incorrect. React, by itself, doesn't include almost ANY "blocks" that you arrange (and the ones it does include manly have to do with very specific stuff like optimization/UX). It is a framework mainly focused on handling reactivity for you.
What you are talking about are external libraries that are built for React. You may use React with or without them.
>>
>>82419600
>>82419391

Oh and btw, $num_results_on_page doesnt count anything...
It's a limit that the user (me) can manually set for how many results you want to see displayed on one page at a time.
The number of required pages is calculated using this number and the actual amount of results in the database.
>>
>>82419600
>How would you improve the code?
You're trying to do too much beyond your ability. Start smaller. You don't really need paging. Ship the smallest possible thing that works first, then add complexity. As the feature list grows, so will your skills.


Personally, I would use JS on Cloudflare. You can run a whole site behind DDoS protection for free.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.