Hello i have a question it may be stupid
i wanted to use php cookies but in the parameters of the function i shuld type the host name
to secure the cookies…in xampp serever i used localhost it worked but after uploading the website it doesnt work
what is the host name here or how can i get it ??
In PHP, use the
$_SERVER superglobal like this:
$hostname = $_SERVER['SERVER_NAME'];
$hostname as the hostname.
setcookie('cookie_name', 'cookie_value', time() + (86400 * 30), $_SERVER['SCRIPT_URI'], $_SERVER['SERVER_NAME'], true, false); //86400 is the number of seconds in a day.
I hope you are asking about
MySQLhost or server name which is equalent to localhost you mentioned above.
Here is the Admin reply for getting that.
Using a new database
After creating a database, you need to tell your script how to use it. In a configuration file or installation wizard, it will ask for a database hostname, database name, database username and database password. Here’s how you can find those settings.
For the database name, username and hostname:
Login to your control panel and go to MySQL Databases.
Find your new database under Current Databases.
Copy the MySQL DB Name, MySQL User Name and MySQL Host Name to the relevant configuration fields.
For the database password:
Login to the client area.
Click the account you created the database for.
Scroll down to Account Password and click Show next to the password field.
Copy the password from the field to the Database Password configuration field.
And that’s all there is to it! That’s all your script need to know to use the database.
i tried it didnt work this is the code
Does this help? Sorry I’m not good at
.php (learning basics though!):
PHP: $_SERVER - Manual
no i’m sorry
i’m asking to know the host name to use it in php cookies
i connected the website to database successfully
December 13, 2021, 3:56pm
What do you mean by “it didn’t work”? What do you actually see?
I connected to database successfully this is not the problem I’m asking for the host name to use in php cookies
i cant set the cookie because i want to know the host name
I think you should mention domain name instead of localhost.
.epizy.com in your case
Can you please share the code used for create cookie then only we can solve!
it didnt work this is the code
setcookie(‘TEST’, ‘cookie_value’, time() + (86400 * 30), “/”, “.epziy.com”, true, true);
Try like this
setcookie('test', 'lang-en', time() + 96400, '/', 'web-tec.epizy.com');
use proper and complete syntax:
setcookie( name, value, expire, path, domain, secure, httponly );
December 21, 2021, 5:11am
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.