Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Auto creation of pages on a site?? (e.g Youtube)

  • 02-06-2014 12:00pm
    #1
    Registered Users, Registered Users 2 Posts: 537 ✭✭✭


    How do sites like youtube create new pages every time a user uploads A Video?
    Is it done through a CMS or through some programming language. I am assuming people at youtube dont create the pages manually as that would take ages. Can anyone explain please? Thanks!


Comments

  • Registered Users, Registered Users 2 Posts: 11,989 ✭✭✭✭Giblet


    Very basically? They have a template and they assign an id to new users. You will see this id passed in the URL, this tells youtube which user's details to display in that template. The template will automatically pull in all their videos sorted by date or something, and pull in their profile data where appropiate. Basically filling out the template. There is usually code on the server which reads the URL to parse the iid, and pulls in the appropiate content and renders the HTML. The language can be any language, usually PHP, Java with some web framework, C# with ASP.NET, Ruby on Rails, Python with Django or many of the other languages and web frameworks that are out there. And particular reason for the question? It's very broad.


  • Registered Users, Registered Users 2 Posts: 537 ✭✭✭sw33t_r3v3ng3


    Giblet wrote: »
    Very basically? They have a template and they assign an id to new users. You will see this id passed in the URL, this tells youtube which user's details to display in that template. The template will automatically pull in all their videos sorted by date or something, and pull in their profile data where appropiate. Basically filling out the template. There is usually code on the server which reads the URL to parse the iid, and pulls in the appropiate content and renders the HTML. The language can be any language, usually PHP, Java with some web framework, C# with ASP.NET, Ruby on Rails, Python with Django or many of the other languages and web frameworks that are out there. And particular reason for the question? It's very broad.

    Thanks for your answer! Sorry if it was hard to understand.
    I was wondering about creating something like this. Not sure would it be too difficult though?


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    Creating what?


  • Registered Users, Registered Users 2 Posts: 537 ✭✭✭sw33t_r3v3ng3


    Creating what?

    Some way of displaying different info on a page depending on the id


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    Well, the reason why Giblet says it's broad is because there are so many ways of doing it. The whole point of the likes of PHP and Python in a web context is to generate content dynamically in the way you describe.

    The "best" way is to use a framework and a template engine but you sound like a beginner so I would learn how to do it by interpreting the query string of a URL yourself and pull content from a database or file dynamically.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 537 ✭✭✭sw33t_r3v3ng3


    Well, the reason why Giblet says it's broad is because there are so many ways of doing it. The whole point of the likes of PHP and Python in a web context is to generate content dynamically in the way you describe.

    The "best" way is to use a framework and a template engine but you sound like a beginner so I would learn how to do it by interpreting the query string of a URL yourself and pull content from a database or file dynamically.

    I have created pages that display info from a database before, but ive never done it through the id


  • Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭The_B_Man


    The ID is just a query string parameter. This is the basic building blocks of a dynamic web page.

    Basic example, the ID is a users id or username or something.

    So you go to:
    www.mysite.com/page.php?id=3

    Then in your code you just (after security etc etc) just do a SELECT * from DB WHERE ID=3

    This will pull back all the columns and you just display them however way you want.

    In the example of Youtube, it might be:
    www.mysite.com/video.php?id=4

    Then same again, do a SELECT statement, and pull back the relevant info, in this case it could be the path to the video.
    The template mentioned above would be used here, like you have a box (div) above that plays a video when supplied with a path. So the path retrieved from the DB would be put here and the template code would play it. Same with the comments section. You could just SELECT all the comments from the COMMENTS table where the ID=4, in this example, and display them in another template div below.


  • Registered Users, Registered Users 2 Posts: 537 ✭✭✭sw33t_r3v3ng3


    The_B_Man wrote: »
    The ID is just a query string parameter. This is the basic building blocks of a dynamic web page.

    Basic example, the ID is a users id or username or something.

    So you go to:
    www.mysite.com/page.php?id=3

    Then in your code you just (after security etc etc) just do a SELECT * from DB WHERE ID=3

    This will pull back all the columns and you just display them however way you want.

    In the example of Youtube, it might be:
    www.mysite.com/video.php?id=4

    Then same again, do a SELECT statement, and pull back the relevant info, in this case it could be the path to the video.
    The template mentioned above would be used here, like you have a box (div) above that plays a video when supplied with a path. So the path retrieved from the DB would be put here and the template code would play it. Same with the comments section. You could just SELECT all the comments from the COMMENTS table where the ID=4, in this example, and display them in another template div below.

    Thanks a million!! I will definitely have a look into this!
    When you mention security, I know there's sql injection, xss etc. But how can you prevent malicious attacks? is it ever really secure?


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    You can never be 100% secure but don't trust use input is the best advice. The specifics is yet another huge subject.

    Use parameterised SQL queries. If you're expecting an integer ID in a query string, parse that id into a number and validate it. If you're storing user supplied text in a database, escape it.


  • Registered Users, Registered Users 2 Posts: 537 ✭✭✭sw33t_r3v3ng3


    What would happen on this line of php ?
    what do i put in 'WHERE id = xxx ' to get the id from the DB

    $query = "SELECT * FROM `users` WHERE id = ``";


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    You're not even trying!!! :D

    If you want to do SQL right in PHP, use paramaterised queries:

    First Google result:

    http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php

    And something on getting the external variables:

    http://www.php.net/manual/en/language.variables.external.php


  • Registered Users, Registered Users 2 Posts: 537 ✭✭✭sw33t_r3v3ng3


    You're not even trying!!! :D

    If you want to do SQL right in PHP, use paramaterised queries:

    First Google result:

    http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php

    And something on getting the external variables:

    http://www.php.net/manual/en/language.variables.external.php

    I will admit im pretty awful when it comes to sql :P


  • Registered Users, Registered Users 2 Posts: 2,040 ✭✭✭Colonel Panic


    It might be worth looking at the Learn SQL the Hard Way book online to get a feel for SQL before spending too much time trying to hack things out in PHP.

    Trust me when I say that spending time on the basics is well worth it. You've got plenty of time to learn and in a few months it'll be easy, in a few years it'll be second nature.


  • Registered Users, Registered Users 2 Posts: 537 ✭✭✭sw33t_r3v3ng3


    It might be worth looking at the Learn SQL the Hard Way book online to get a feel for SQL before spending too much time trying to hack things out in PHP.

    Trust me when I say that spending time on the basics is well worth it. You've got plenty of time to learn and in a few months it'll be easy, in a few years it'll be second nature.

    I should probably get some book of some sort. It wouldnt do any harm to get familiar with sql through a book


  • Registered Users, Registered Users 2 Posts: 7,893 ✭✭✭The_B_Man


    I saw this on LinkedIn just there. See if its any use to you.

    https://www.youtube.com/channel/UCZEEBhAmBWMi8x9diJK5Pyw


  • Registered Users, Registered Users 2 Posts: 7,521 ✭✭✭jmcc


    I should probably get some book of some sort. It wouldnt do any harm to get familiar with sql through a book
    You will need a lot more than one book if you want to build a large template and database driven website. SQL is going to take you a while to master and it may be five years or so before you can think in SQL. Learning PHP might be useful.

    Regards...jmcc


Advertisement