Jump to content

Gabrielphp

Members
  • Content count

    26
  • Joined

  • Last visited

  • Days Won

    5

Gabrielphp last won the day on June 29

Gabrielphp had the most liked content!

Community Reputation

6 Neutral

About Gabrielphp

  • Rank
    Newbie

Profile Information

  • Gender
    Male
  • Interests
    Web development

Previous Fields

  • Languages
    PHP, Javascript, jQuery, HTML, CSS, MySQL
  1. University exam exercise

    So this is my answer for your problem: index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Name Control</title> </head> <body> <form method="post" action="namecontrol.php" > <input type="text" name="name" placeholder="Insert your name ..." /><br/> <input type="text" name="lastname" placeholder="Insert your last name ..." /><br/> <input type="submit" value="Submit" name="submit" /><br/> </form> </body> </html> namecontrol.php (HTML LIST) <?php if($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_POST['submit'])) { $name = $_POST['name']; $lastName = $_POST['lastname']; if(empty($name) || empty($lastName)) { echo "Please complete all fields to proceed !"; } else { echo "<ul>"; echo "<li>name: " . $name . " </li>"; echo "<li>lastname: " . $lastName . "</li>"; echo "</ul>"; } } } ?> namecontrol.php (ARRAY) <?php if($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_POST['submit'])) { $name = $_POST['name']; $lastName = $_POST['lastname']; if(empty($name) || empty($lastName)) { echo "Please complete all fields to proceed !"; } else { $array = array("name" => $name, "lastname" => $lastName); print_r($array); } } } ?>
  2. How does include path resolution work in require_once?

    I think you're missing something to tell us. I've recreated the same environment as yours and also added an echo "Ok!"; in the c.php and at me it works fine, exactly the same settings as yours. As i did it, i used Windows to do it, so it might aswell be the thing that you're using linux, and it might be possible that the paths don't work as are working in windows. Try putting the "../obj/c.php"; as path in the b.php althought you have it in the same directory and see if that works, if not then i don't know what should work as on my pc (windows) works just fine.
  3. University exam exercise

    What does it reffers to when it says has to see the data as a list? You mean like a html <ul><li> or an array() in php and echo that?
  4. The query return 0 record

    It shouldn't let him log in as long as there is no other user with the same "Matricola" as in his SQL, i'm using fetchAll myself and i intentionally created another username with the same password as my other username and it won't log me in.
  5. Encoding PHP code

    What do you mean by encoding your php code? All i know is encoding charachters (UTF-8 etc) or json_encode(). What should your encoded code do?
  6. Profile Picture Framer Web App

    As long as my php knowledge goes is that you can't do it in pure php, you need some javascript aswell. Unfortunately i can't tell you diretly how is done cuz i never did something like that myself, but i found some tutorials that might help: http://subinsb.com/create-profile-picture-framer-web-app https://www.experts-exchange.com/articles/217/Framing-images-in-PHP.html Hope it helps.
  7. The query return 0 record

    Try using fetchAll() instead of fetch().
  8. Please help a newbie

    Ah, true, it has an or die statement. Sorry.
  9. Please help a newbie

    In your code at the mysqli_connect() it misses this ";" it cannot work if you don't put it.
  10. Unusual Code - A PHP Shortcut?

    Yes. <?= ?> is a shortcut for <?php echo ""; ?> All of the above will translate as follows: <?php echo ++$a; ?> <?php echo ++$b; ?> <?php echo $private_id; ?> <?php echo session_id(); ?>
  11. Structuring the PHP site

    In your users table you should have a column called group or rang or whatever you want your admin to be named. After that you simply create a table called groups with your different ranks and functions, when you done that, you make sure that the id of the rang in the groups table match the id the user has in it's column. For example you make 2 different groups, Super User, and Moderator. Super User has the id of 1 and can access all administrative pages, in that case you make an IF condition between the Super User record's ID in the table and the user's ID in the column. The script will be something like this: if($_SESSION['user_rank'] == rank_required('page.php')) { //display page } else { //use a redirect method to a 404 not found or some kind of access restricted page } In the rank_required('page.php') will be a function that you will make and will check the rank's you've set for those pages, so that you make it a bit dynamically. But if you want an easy way, just set up it like: if($_SESSION['user_rank'] == 1) //in our case the super user { //display super user content } else { //display error or redirect } /* Also you can do something like this: */ if($_SESSION['user_rank'] == 1) { //display super user content } else if($_SESSION['user_rank'] == 2) //in our case the moderator rank { //display moderator content } else //in our case none of the above { //redirect page / error page } Easy enough, if you have any questions, feel free to ask, i personally didn't try the dynamically part as i never had a big website in which the dynamics would make a difference. But, in theory this should work pretty fine. I'm sure there are other methods out there. Oh, and for the rank_required('page.php'); function, never made a function like that, but i assume in order to work properly you will need to have another table in your database called page_ranks, in which will be a column with the name of the physical name of the page, the rank required (id from the groups table). After that it's all about if conditions with database record for that page. //Function function rank_required($page) { try { $sql = "SELECT * FROM pages_ranks WHERE page_name = :page"; //first we crate our sql to the database, we assume you already have a db connection $stmt = $db->prepare($sql); $stmt->bindParam(":page", $page); //now we bind the paramter in the sql with the variable from our function that we get from a page through basename() function; $stmt->execute(); $rowCount = $stmt->rowCount(); //warning as the rowCount(); function doesn't work if the previous statement that affected the db was an SELECT statement, but as long as you don't change records, i assume you will add all of your pages at one time, and then with the time the last sql statement would change, this should work just fine. if($rowCount > 0) { $row = $stmt->fetch(); //we fetch the result return $row['page_required_rank']; //this result will echo a value like: 1 or 2, depending on what id you have for your page in the page_required_rank collumn. Don't forget the ID depends on the group record's ID. And then this value will be compared into the header of the page with the $_SESSION['user_rank']; } else { return false; } } catch (PDOException $e) //catching possible errors { echo $e->getMessage(); } } But if you don't want to get complicated with all of this database stuff you can just use the define function and you can change the ranks whenever you want through the variables you defined, this will make a lot easier to work with grades, still, you will need to edit the user's column in the database. //Create a page like ranks.php and include it in everypage you need a rank system. //ranks.php define('SUPER_USER_RANK', '1'); define('MODERATOR', '2'); //page.php if($_SESSION['user_rank'] == SUPER_USER_RANK) { //display super user settings } else { //display error, redirect } //This helps you from later changing of the variable's value, so in that way you don't need to change the value from 1 to 2 or so on in everypage, you just have to change it in ranks.php to change the level of the required_rank. This is just a concept, to help you understand how this thing works, of course this is some basic php scripting, as i said before, i'm sure there are more complex and way efficient ways to do this, but if you're a beginner, this might help. It helped me in the past, and still helps me now. Hope i could help.
  12. Sending mail

    You could just use XAMPP as your default webbrowser, xampp comes with pre-installed mysql, php and apache server, and it also have a firezilla ftp server and the mercury mail server. Just look up on it.
  13. PHP Website?

    You can look up for bootstrap landing pages and then you can work yourself up from there. Bootstrap it's easy to customize and you can always create your own pages as you don't need to create the components yourself, just paste the code, make a css file to have your own design, put some js and jquery in it for effects and there it is. And you can always use php and ajax to make it more interactive with users.
  14. Page redirection if invalid URL parameter

    It won't redirect you mainly because header cannot be used like that. Instead of using header just echo a javascript script: echo '<script>window.location.href="url";</script>';
  15. First of all you don't need to save the all URL in the database, you just need to save the path like if your view_video.php (example) is in the home directory, where index and other pages are and your video is in uploaded/$name, then you need to insert into the DB only uploaded/$name. If your php page is in other folder like a folder named "videos" and there is your page but then you have your video in the "uploaded" folder outside the videos folder then the path will be ../uploaded/$name and so on. And to stop uploading the URL in the DB you need to check whether the video has done uploading or not (and that's a bit hard cuz you need some kind of a library to check the percentage of the video uploading status) or you can just create a simple function that is being called every time you access the page, so the logic will be something like this "if(DB_URL == HOST_URL) { then show video } else { REDIRECT 404 NOT FOUND AND DELETE URL FROM DB}" this will be the logic, so if in the DB the url will be uploaded/$name but in the folder there is no such video with that url then it will redirect the user to 404 not found. I hope i helped you.
×