how to store a cookie [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
<?php
$id=721914338;
setcookie("id",$id,time()+1200,'/');
?>
This is just a example so I can ask my question . My question is this that I am capturing id from facebook , google or twitter . I am inserting into the database but the problem is this that when i store it in the cookie and use this cookie in the next page or any other page . By using the sql query whether the user has this id or not which is stored in cookie . As a developer , any user has knowledge about INSPECT ELEMENT , he or she can read my id so how to protect from hacking ? please can anyone help me ?
I don't want to store it in session, I want to store it in cookie only . Is there any to encrypt the id and in every page decrypt it use it . Is there any when the user refreshes the page , the timer will start again

You can store this id into session variable. Every time a user is login into site you fetch its id from data base and store into session variable in php. Using session you can get the value in any page.

Related

How can you make a personal page about every user?PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Yes, i looked for this question online, but I can not understand.
For example i know that when you log in you go to a link like :
site.com/Username
I know that you have to have a page for users in general like : user.php
but how exactly you put the name of the person at the account page when log in or the discription(do you read the name from the url and take other data from the database?).
I am new to php.
Please explain me
-Sorry for my english
The Best Way to do it is make a user.php page and when user login in
saves it's all data in session and when user open his profile/or
something else you can retrive data from session like user id and then
use your query to get the specific data against that user
You can store the username/id in $_SESSION['username'] or $_SESSION['id] like this. And can access the data of the user from the username/id. Hope this might help you.

How to destroy a session an hour or day after a user exit site [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have an admin page where some users can have access to but I want that whenever they leave the site or close the tab for about an hour or a day the session should be destroyed so as not to allow someone else.
The thing you are searching for is $_COOKIE. There you can define how long the Variable is saved etc. The only thing you will have to consider is that the values are stored locally and not on the server. If you want to achieve that, you can create a Cookie-Key system similar to the one PHP uses to save the Session data on the Server. In that Case the User would get a key, saved as a cookie and the data is stored on the server under that key.

Store retrieved infos from Database in Php session [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I was wondering if it was a good practice to store the infos we retrieved from a DB (more specificaly the user infos) inside a session, useful for the login for example :
e.g :
$sql="SELECT * FROM USER";
$result=$myConnexion->query($sql);
$line=$result->fetch_assoc();
$_SESSION['login']=$line['login'];
$_SESSION['name']=$line['name'];
...
It then would be easier to display infos, welcome messages and so on.
What do you think ?
Thank you for your time
It's perfectly fine. Make sure you only store Public info you might need later on, meaning don't store the password or the user's ID in the db.
Yes, it's fine, as long as you don't store sensitive data, like the password, or the user name. You can check this for more
Using PHP SESSION Variables to store MySQL query results

How can I pass result generated from mysql query on other page [duplicate]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a some forms that stores data in my page.
I want to find a way to temporarily save the data entered by the user in navigating and keep until the order is confirmed.
Can anyone help me?
This is exactly what sessions are for
While I was working on e-commerce sites we used to keep all the order data
in sessions until user confirms order by going to payment gateway.
You can use PHP Session as arrays and store your data temporary and then destroy the session.
$_SESSION['cart'][] = //you data here
Sessions and cookies are used for this purpose but sessions are more secure and reliable.

I want to create a website for polls/survey like this http://www.poll-maker.com/ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
but did not understand
The concept of generating a link &
more importantly how they save the data in database,do they save it like id of poll & yes/no click or done with other logic.
what will happen to the polls which are expired? will they remain in database or somewhere else?
please help
To handle URL you can use cURL.
But I have an easy method. You can use the concept of Query Strings.
To Create New Question
Store the new question in database.Give Each Question a unique ID.
Then After user submits the questions show him a link like:
http://do-survey.com?question=xzxsa
To store polls
Get question like:
if(isset($_GET['question']))
{
$question = $_GET['question'];
// Now you have the question unique id manipulate the database using this
}
this is not the place to ask such questions, but to make my answer at least remotely useful:
they're not generating a link. That link doesn't exist under the form of a file on the server. Take for example a database containing 'id' 'poll' 'var1' 'var2'.
You can make a php page that gets a param from the link, have it like mysite.com/poll?id=1
The php script will get the '1' as a param, then you SELECT * FROM table WHERE id=1 and you generate the contents via php with the data from the DB.

Categories