27: Session and Cookies in PHP | PHP Tutorial | Learn PHP Programming | PHP for Beginners

  Рет қаралды 292,898

Dani Krossing

Dani Krossing

Күн бұрын

Пікірлер: 87
@anvinawalgaria
@anvinawalgaria 6 жыл бұрын
I had my exam today and I got a question on session and cookies. I watched this video in the morning. Because of your video I could answer that question. Thank you 🙏💕
@nikosn.9932
@nikosn.9932 3 жыл бұрын
i was like number 69.
@alexanderer_
@alexanderer_ Жыл бұрын
A tip for writing the expiration-time is to, instead of writing it in seconds, write it in a more comprehendable manner: SYNTAX: time() + seconds * minutes * hours * days Example for a cookie that lasts a week (7 days): time() + 60 * 60 * 24 * 7
@WahyuArtka
@WahyuArtka Жыл бұрын
do you know how to expire cookies for the next 8 years??
@abderrahmanemessaoudene3404
@abderrahmanemessaoudene3404 Жыл бұрын
@@WahyuArtka time() + 60 * 60 * 24 * 365 * 8
@esu9591
@esu9591 7 жыл бұрын
This guy is on point. I've been trying to learn this stuff for a while now. Great job on explaining the semantics.
@no_short_circuit
@no_short_circuit 9 жыл бұрын
Daniel....great set of videos, thanks for taking the time to make them. Small point - the number after time() is seconds not mili-seconds
@Dani_Krossing
@Dani_Krossing 9 жыл бұрын
+Bill Baird Thank you for pointing that out Bill :) I was calculating it on the side as I was recording the tutorial and must have gotten it wrong
@viniciusvalente312
@viniciusvalente312 6 жыл бұрын
So should I use 86.400 or 86.400.000 for one day?
@nrnugteren
@nrnugteren 6 жыл бұрын
Good question +Vinicius Valente, was wondering the same. 24 hours * 60 minutes * 60 seconds is 86.400 seconds, but how does PHP interpret that number? EDIT (found the answer): Just found the answer on php.net/manual/en/function.setcookie.php "expire The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire." In other words: Daniel has set the value correctly in this tutorial, if he wants the cookie to be expired after 1 day.
@danish6192
@danish6192 6 жыл бұрын
I actually was coming down to to comments section to say the same, but found this already :p
@WaliBD1
@WaliBD1 9 ай бұрын
​​@@viniciusvalente312 86400 for 1 day 👍
@funixer
@funixer 5 жыл бұрын
Now as I watched your video , I understand now what is cookie. Thanks!
@yannik8271
@yannik8271 2 жыл бұрын
Great explanation, bro! Best PHP series on KZbin man! :)
@starkandjack6411
@starkandjack6411 4 жыл бұрын
Thanks for all the videos man, one of the best channels explaining PHP really good ..
@senju31
@senju31 5 жыл бұрын
You've said my name so many times.
@Born2DoubleUp
@Born2DoubleUp 2 жыл бұрын
I'm here! 😎 Great video, just posting a comment to show some support! Keep up the good work. 🤙
@samuelkaka1350
@samuelkaka1350 4 жыл бұрын
Thanks man for sharing your knowledge. Cheers! God bless you!
@rgryczan83
@rgryczan83 8 жыл бұрын
Your tutorials look very good; i have know some PHP and JS but i think when i watch all of your tutorials(about js/php) i would be so much better :p thanks!
@EmbellishedCreations
@EmbellishedCreations 5 жыл бұрын
Awesome Tutorial!Thanks for sharing!
@jackywong941
@jackywong941 6 жыл бұрын
if u want delete session you can use session_unset('your session name'); or session_unset(); clear everything
@seifcocksucker5457
@seifcocksucker5457 8 жыл бұрын
I´ve been watching your videos for a week and seems to be longer! great job!
@tvs3497
@tvs3497 4 жыл бұрын
Programming is a very powerful tool. You can create universes with it... and destroy them as well.
@rizwanhamidrandhawa8090
@rizwanhamidrandhawa8090 6 жыл бұрын
In one day there are 86400 seconds and 86400000 milliseconds.
@simopelle
@simopelle 4 жыл бұрын
yeah, the third setcookie() parameter is set in seconds, not in milliseconds as he said
@xiaoti8035
@xiaoti8035 4 жыл бұрын
bullshit, 86400 seconds and 86400000 milliseconds would be 172,800 seconds. there are only 86400 seconds in a day OR 86400000 milliseconds. Please,man your in the coding world, syntax is important. JK
@atmian
@atmian 10 ай бұрын
Good info. However, 1 day = 86400 seconds, not milliseconds as you said. So should seconds or milliseconds be used for cookie time? If milliseconds, you should enter 86400000 instead.
@ricekrissy9769
@ricekrissy9769 5 жыл бұрын
Great videos 👍 In this video you mentioned that usernames/passwords should be stored in sessions and that sessions end as soon as you close the browser. But When I go to a website that needs me to login, I can close the site and then go back and still be logged in. Does that mean that site is using cookies to store my username and password? Or is there something else they're using to remember my username and password?
@mariac7772
@mariac7772 5 жыл бұрын
Thanks Daniel
@yongjung5433
@yongjung5433 6 жыл бұрын
thank you!
@ASouza-ut9kb
@ASouza-ut9kb 6 жыл бұрын
Excellent videos!
@a.yashwanth
@a.yashwanth 4 жыл бұрын
I am using xampp on windows. I restarted my computer and started xampp but my previous logged in session stayed. Why is that so? Also it is fresh install of xampp.
@sharifabahar6257
@sharifabahar6257 7 жыл бұрын
Thank you Danial for such great series. Do we you what is the id of a user when we assign value for session ? If yes how do we know ?
@nrnugteren
@nrnugteren 6 жыл бұрын
If I had to guess (not there yet, but from my previous slight experiences with MySQL): The ID (for example '12') corresponds with an ID in a database, they you either create manually or that is being assigned automatically upon user creation. In that table you will have one row with ID's (i.e. 1 to 20) and the row next to it has the usernames corresponding to those ID's. Anyone feel free to correct me if I'm wrong, but I think that's how it will work when we arrive at the tutorial about databases and login systems.
@traciss
@traciss 2 жыл бұрын
I'm completely new to php, well programming on a whole. However we were asked to make a cookie for our store page. We use the MVC approach, how would this be implemented using that approach.
@cmd9183
@cmd9183 4 жыл бұрын
I use a cookie to remember the user so they dont have to log in every time they visit the website and I store there username in that cookie is this wrong?
@cmd9183
@cmd9183 4 жыл бұрын
@HOTBOINICK i found out its bad because if you know another accounts username you can simpally change the cookie to there username and you would be logged in
@cmd9183
@cmd9183 4 жыл бұрын
@HOTBOINICK lol we learn as we go
@collegestudy5977
@collegestudy5977 5 жыл бұрын
sessions are stored in server then how can closing chrome delete session?
@siddharthgaglani4445
@siddharthgaglani4445 3 жыл бұрын
Which keyboard are you using ?
@RagHelen
@RagHelen 6 жыл бұрын
How is PHP on my server able to write a cookie in the client's browser?
@1699107
@1699107 4 жыл бұрын
Would there be a reason why a session may drop before a session destroy and don't close the browser? Im using PHP 5.5.4 on xamp package 1.8.3, and I cannot for the life of me work out why sessions could drop without either of the aforementioned events happening.
@smacdsmaccers
@smacdsmaccers 3 жыл бұрын
nice, digital baking
@sstream17
@sstream17 6 жыл бұрын
I would have appreciated explanations on retrieving the variables and performing other actions with them.
@nrnugteren
@nrnugteren 6 жыл бұрын
Are you perhaps referring to the stuff that was explained in previous lessons? Hopefully you'll find there what you were looking for. The whole course starts here: kzbin.info/www/bejne/p4e4ZIlmdpVooZo And here the explanations about variables begin: kzbin.info/www/bejne/eaDSo5anl9Cjf5I
@adriandinca5682
@adriandinca5682 7 жыл бұрын
First of all, you have the best php tutorials on youtube! :D Secondly, I was wondering if it's possible to share a session between two or more users. Here is what I mean. Let's say we have a $_SESSION['room'] (which stores a multidimensional array) is it possible to share a reference to this session between two users? I tried something like generating a random name for the room and store it inside a variable called $room_id and than I started a session $_SESSION[$room_id] but of course it didn't work :). Thanks in advance!
@kreut8817
@kreut8817 4 жыл бұрын
hello, if you are still here, how are you doing three years from now? lol
@adriandinca5682
@adriandinca5682 4 жыл бұрын
@@kreut8817 Hello AJ, I have to say your comment was a pleasant surprise, I almost shed a tear :,D. I am doing great, thanks for asking! Looking back I never expected actually become a web developer, it was more of a passion project. Although I switched from PHP to JavaScript, this channel is where my passion for web development started. I am currently working for a fin tech company and I love it. How are you doing?
@kreut8817
@kreut8817 4 жыл бұрын
@@adriandinca5682 Hello Adrian, I am doing great! It's nice to know after three years, you have found a place where you can do what you love. I feel like I am where you once were before, in a stage of learning, hoping to become something in the future. Next year, I'll be a senior in high school, so I've been spending my time binge watching programming videos like these as well as coding projects. I'm so happy to hear from you! I never expected a response.
@biskutnation
@biskutnation 4 жыл бұрын
@@adriandinca5682 , are you ditching PHP completely? did you find the JS much more easier to use?
@janx963
@janx963 Жыл бұрын
You wrote it wrongly, here is the correct one to start SESSION named room with a value of $room: $_SESSION["room"] = $room;
@lakshanchamod1208
@lakshanchamod1208 5 ай бұрын
Nice
@ericmammburu1886
@ericmammburu1886 2 жыл бұрын
Hello mr Dani, Iam having a problem its like $_SESSIONS dont work in google chrome any help please
@GohersWay
@GohersWay 4 жыл бұрын
For me own-self X video with lesson 27 and 28 also ( search login system by mmtuts or something similar ).
@eosapril
@eosapril 9 жыл бұрын
I'm stuck here, offfff...
@SuperTherock12345
@SuperTherock12345 6 жыл бұрын
session changed from page to page. how to rectify this problem.
@djleisheng
@djleisheng 6 жыл бұрын
Turns out you have to start a session on each new page that is executed and in the page where you are setting session variables BEFORE you set them (I think he shows this in the next video, but anyway..) -----index.php----- if (!isset($_SESSION)) { session_start(); } $_SESSION['name'] = 'Daniel; -----test.php----- if (!isset($_SESSION)) { session_start(); } echo $_SESSION['name'];
@CastleShield
@CastleShield 3 жыл бұрын
I am watching how to make cookies in php, meanwhile my wife is watching how to make chocolate cookies. I'm kidding.
@Star-hw8bh
@Star-hw8bh 2 жыл бұрын
when the course gonna update?
@VeronaLynne
@VeronaLynne 3 жыл бұрын
I don't get it.. Why should we make the time negative when deleting a cookie instead of just removing the line of code??
@Dani_Krossing
@Dani_Krossing 3 жыл бұрын
If you delete a line of code, it will get deleted for all the users using the site. And because PHP is a language used to make dynamic content on web sites, it defeats the purpose. 🙂 Look at it this way... If you have vending machine that people can get a variety of snacks from. Deleting the line of code would be the same as stopping the machine from being able to sell, let’s say chips, to ALL customers. Not just to some of the them. Instead we need the customers to be able to buy chips, but also cancel their purchase if needed. And that’s why we have statements in PHP to determine “if the customer wants chips” as well “if they want to cancel their order”.
@lakshanchamod1208
@lakshanchamod1208 Ай бұрын
for my php exam
@tusharjajodia9077
@tusharjajodia9077 6 жыл бұрын
in 3:58. You saying milliseconds and adding 86400 second??? a day has 86400*1000 milliseconds
@nrnugteren
@nrnugteren 6 жыл бұрын
PHP works with seconds indeed: Just found the answer on php.net/manual/en/function.setcookie.php "expire The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you'll most likely set this with the time() function plus the number of seconds before you want it to expire." In other words: Daniel has set the value correctly in this tutorial, if he wants the cookie to be expired after 1 day.
@devonvermaak4101
@devonvermaak4101 5 жыл бұрын
Did I just learn how to steal to steal client data. Holy shit.
@iamchiragarora
@iamchiragarora 6 жыл бұрын
at 5:50 there's a sound. Can you describe that? I mean i am not mocking you with this comment but just curious to know.
@Dani_Krossing
@Dani_Krossing 6 жыл бұрын
Probably rain in the background
@mdz7372
@mdz7372 4 жыл бұрын
How to make cookie logger
@kmtsvetanov
@kmtsvetanov 5 жыл бұрын
Start a session: session_start();
@mibrahim4245
@mibrahim4245 5 жыл бұрын
Yea he missed this, but he targeted to manifest the main difference between cookies and sessions...
@HarryPotter-nc3vz
@HarryPotter-nc3vz 4 жыл бұрын
wait, he doesn't actually set a cookie since the time is in negative
@Dani_Krossing
@Dani_Krossing 4 жыл бұрын
That's exactly right. This is how you "unset a cookie" 🙂 I explained that in the video.
@SMAKIEVISUALMEDIA
@SMAKIEVISUALMEDIA 5 жыл бұрын
how can i download all video at once
@Dani_Krossing
@Dani_Krossing 5 жыл бұрын
On my Patreon I have a link where you can download all my videos :)
@iamnsk8811
@iamnsk8811 6 жыл бұрын
Pls help me i want make an asmin panel !
@shruti2981
@shruti2981 Жыл бұрын
@rafiqjarjous7542
@rafiqjarjous7542 3 жыл бұрын
but how do we actually use it tho
@Dani_Krossing
@Dani_Krossing 3 жыл бұрын
My login system project video later on shows how :)
@Freelancer19841
@Freelancer19841 3 жыл бұрын
Millisecond?
@LeonSafal
@LeonSafal 6 жыл бұрын
u said lock in or login ? haha anyways thanks for the tutorial
@iamnsk8811
@iamnsk8811 6 жыл бұрын
/
@tusharveeramani3742
@tusharveeramani3742 6 жыл бұрын
heck... errrr........???!!
Difference between cookies, session and tokens
11:53
Valentin Despa
Рет қаралды 657 М.
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 22 МЛН
From Small To Giant 0%🍫 VS 100%🍫 #katebrush #shorts #gummy
00:19
Cookies in PHP | Tutorial 27
9:34
FineGap
Рет қаралды 445
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,2 МЛН
Login form using session and cookie with remember me in php
31:19
learnWebCoding
Рет қаралды 266 М.
PHP For Beginners, Ep 37 - Sessions 101
13:57
Laracasts
Рет қаралды 14 М.