Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-05-10 18:26:00
Point:500 Replies:6 POST_ID:828501USER_ID:11059
Topic:
Hypertext Markup Language (HTML);PHP Scripting Language;JavaScript
I have tutorial at http://www.w3schools.com/php/php_cookies.asp to create my
first cookie, "Login", by php code.I have question. After I create "Login" cookie name
and its value by setcookie() in php, where is it stored or saved into my server system?
what is the file name to store cookie in my server ?
And the last question is the tuturial said:
"A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values"
SO my question is whether browser will also save my cookie "Login" into my window XP CP location at
C:Documents and SettingAdministoratorLocal SettingsTemporary Internet Files folder ?
I have checked by Firefox's option and show cookie , that cookie path is at
C:Documents and SettingAdministoratorLocal SettingsTemporary Internet Files folder.
But I could not find any cookie file generated from my domain, for example, www.mydomain.com or mydomain.com, Why ?
I have seen in the folder there is a lot cookie file related to what the website I visited before. How those
website generated the cookie file in my at C:Documents and SettingAdministoratorLocal SettingsTemporary Internet Files folder ?
Please advise
Duncan
first cookie, "Login", by php code.I have question. After I create "Login" cookie name
and its value by setcookie() in php, where is it stored or saved into my server system?
what is the file name to store cookie in my server ?
And the last question is the tuturial said:
"A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values"
SO my question is whether browser will also save my cookie "Login" into my window XP CP location at
C:Documents and SettingAdministoratorLocal SettingsTemporary Internet Files folder ?
I have checked by Firefox's option and show cookie , that cookie path is at
C:Documents and SettingAdministoratorLocal SettingsTemporary Internet Files folder.
But I could not find any cookie file generated from my domain, for example, www.mydomain.com or mydomain.com, Why ?
I have seen in the folder there is a lot cookie file related to what the website I visited before. How those
website generated the cookie file in my at C:Documents and SettingAdministoratorLocal SettingsTemporary Internet Files folder ?
Please advise
Duncan
//setcookie()==================<html><body><?php$value = "mycookieloginvalue";// send a simple cookiesetcookie("Login",$value);?></body></html>//Read Cookie=================<html><body><?php// Print a cookieecho $_COOKIE["Install"];//setcookie("user", "Alex Porter", time()+3600);// A way to view all cookiesprint_r($_COOKIE);echoforeach($_COOKIE as $cookie){ echo $cookie.'<br>';}?></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:
Expert: imantas replied at 2024-05-11 14:52:02
Sorry, session_start was the function I was talking about. It's just that some time went by since I've programmed with PHP, so I forgot the name. Should've google it before posting.
Author: duncanb7 replied at 2024-05-11 09:46:43
Dear Imants,
there is no session_open function in php
there is only session_start(0 in php.
Please advise
there is no session_open function in php
there is only session_start(0 in php.
Please advise
Author: duncanb7 replied at 2024-05-11 08:49:44
Thanks for your reply for
a good start
a good start
Assisted Solution
Expert: Ray Paseur replied at 2024-05-11 04:43:18
167 points EXCELLENT
Please see this link:
http://us2.php.net/manual-lookup.php?pattern=session_open%28%29
The correct function is session_start() and it usually sets a cookie.
If you are interested in learning about login concepts, this article will be helpful, I hope.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
If you are interested in learning how cookies work, install this script and run it to see what PHP does with the data. Please read the comments carefully. Cookies are not intuitive - the $_COOKIE array is not modified by setcookie(), and the cookies set in one HTTP request are not available until the next HTTP request. This is confusing for many programmers who are trying to use cookies for the first time!
Best regards, ~Ray
http://us2.php.net/manual-lookup.php?pattern=session_open%28%29
The correct function is session_start() and it usually sets a cookie.
If you are interested in learning about login concepts, this article will be helpful, I hope.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
If you are interested in learning how cookies work, install this script and run it to see what PHP does with the data. Please read the comments carefully. Cookies are not intuitive - the $_COOKIE array is not modified by setcookie(), and the cookies set in one HTTP request are not available until the next HTTP request. This is confusing for many programmers who are trying to use cookies for the first time!
Best regards, ~Ray
<?php // RAY_cookie_example.php// RECEIVE FORM INPUT AND SET A COOKIE WITH THE NAME AND VALUES FROM THE FORM// MAN PAGE: http://php.net/manual/en/function.setcookie.php// TO SEE COOKIES IN FIREFOX, FOLLOW SOMETHING LIKE TOOLS => OPTIONS => PRIVACY => SHOW COOKIES (OR "REMOVE INDIVIDUAL")define('COOKIE_LIFE', 60*60*24); // A 24-HOUR DAY IN SECONDS ( = 86,400 )// IF THE FORM HAS BEEN POSTEDif (!empty($_POST)){ // TIDY UP THE POST INPUT - CLEAN AND NOT MORE THAN 16 BYTES $name = substr(clean_string($_POST["name"]),0,16); $data = substr(clean_string($_POST["data"]),0,16); // BE SURE WE HAVE USEFUL INFORMATION if ( ($name == '') || ($data == '') ) die("MISSING INPUT: PLEASE <a href="{$_SERVER['PHP_SELF']}">TRY AGAIN</a>"); // CHOOSE THE COOKIE NAME AND VALUE $cookie_name = $name; $cookie_value = $data; // ESTABLISH THE COOKIE LIFE - CHOOSE ONE OF THESE FOR THE COOKIE // USE THIS TO MAKE COOKIE EXPIRE AT END OF BROWSER LIFE $cookie_expires = 0; // USE THIS TO MAKE A PERSISTENT COOKIE. DEFINE COOKIE_LIFE IN SECONDS. date('Z') IS UTC OFFSET IN SECONDS $cookie_expires = time() + date('Z') + COOKIE_LIFE; // MAKE THE COOKIE AVAILABLE TO ALL DIRECTORY PATHS IN THE WWW ROOT $cookie_path = '/'; // MAKE THE COOKIE AVAILABLE TO ALL SUBDOMAINS - DOMAIN NAME STARTS WITH DOT AND OMITS WWW (OR OTHER SUBDOMAINS). $x = explode('.', strtolower($_SERVER["HTTP_HOST"])); $y = count($x); if ($y == 1) // MAYBE 'localhost'? { $cookie_domain = $x[0]; } else // SOMETHING LIKE 'www2.atf70.whitehouse.gov'? { // USE THE LAST TWO POSITIONS TO MAKE THE HOST DOMAIN $cookie_domain = '.' . $x[$y-2] . '.' . $x[$y-1]; } // MAKE THE COOKIE AVAILABLE TO HTTP, NOT JUST HTTPS $cookie_secure = FALSE; // HIDE COOKIE FROM JAVASCRIPT (PHP 5.2+) $cookie_http = TRUE; // SET THE COOKIE if (setcookie($cookie_name, $cookie_value, $cookie_expires, $cookie_path, $cookie_domain, $cookie_secure, $cookie_http)) { echo "<br/>SUCCESS! THE COOKIE HAS BEEN SET AND WILL BE AVAILABLE TO THE NEXT PAGE LOAD"; } else { echo "<br/>FAILURE! THE COOKIE WAS NOT SET AS EXPECTED"; } // AT THIS POINT, THE COOKIE HAS BEEN SET, BUT IT IS _NOT_ AVAILABLE TO THIS SCRIPT. // THE COOKIE WILL NOT BE AVAILABLE TO OUR SERVER UNTIL THE NEXT SCRIPT! // THIS IS BECAUSE THE BROWSER SENDS THE COOKIE TO OUR SCRIPT BEFORE OUR SCRIPT STARTS RUNNING. echo '<pre>$_COOKIE CONTAINS '; var_dump($_COOKIE); echo "</pre>"; echo '<pre>$_POST CONTAINS '; var_dump($_POST); echo "</pre>"; echo "<br/>THE COOKIE HAS BEEN SET WITH THESE VALUES:"; echo "<br/>COOKIE NAME: $cookie_name"; echo "<br/>COOKIE VALUE: $cookie_value"; echo "<br/>COOKIE EXPIRES: $cookie_expires "; echo " == " . date('r') . ""; echo "<br/>COOKIE PATH: $cookie_path"; echo "<br/>COOKIE DOMAIN: $cookie_domain"; echo "<br/>COOKIE SECURE: "; var_dump($cookie_secure); echo ""; echo "<br/>COOKIE HTTP: "; var_dump($cookie_http); echo ""; echo "<br/>"; echo "<br/>TO SEE THE COOKIES, IF ANY, <a href="{$_SERVER['PHP_SELF']}">CLICK HERE</a>"; echo "<br/>";}// END OF SETTING THE COOKIE - DROP OUT OF PHP INTO HTML TO CREATE THE FORM?><form method="post">COOKIE NAME: <input name="name" /><br/>COOKIE DATA: <input name="data" /><br/><input type="submit" /></form><?php// SHOW THE COOKIE ARRAY, IF ANYecho '<pre>$_COOKIE CONTAINS '; var_dump($_COOKIE); echo "</pre>";// UNRELATED FUNCTION TO FORCE A STRING TO CHARACTERS ONLYfunction clean_string($string){ return trim(preg_replace('/[^A-Z0-9_]/i', '', $string));}// SHOW THE SCRIPT CODE// die(highlight_file(__FILE__, TRUE)); 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:91:92:93:94:95:96:97:98:99:100:101:102:103:104:105:106:107:108:109:110:111:112:113:114:115:116:117:118:119:120:121:122:123:
Assisted Solution
Expert: imantas replied at 2024-05-10 23:53:31
166 points EXCELLENT
setcookie() doesn't save your cookie on the server, it just sends it to the browser. If you want to store cookies on your server, try using session_open() (google for it), which creates a session and lets you store some data (PHP will take care of storage):
Set some data
Set some data
<?phpsession_open();$_SESSION['message'] = 'This message will be passed to another script';?> 1:2:3:4:
Read the data
session_open();echo isset($_SESSION['message']) ? $_SESSION['message'] : "You did not visit the script that sets the message"; 1:2:
Additionally, php will automatically set and read cookie named 'PHPSESSID' (default). You can also store your own cookies in $_SESSION or any other data related to the user.
Accepted Solution
Expert: Dave Baldwin replied at 2024-05-10 21:21:06
167 points EXCELLENT
You're looking in the wrong place for Firefox cookies. They are stored in your Firefox profile in a file called "cookies.sqlite". In Firefox, you can also go to Tools -> Options -> Privacy and view your cookies there.
"C:Documents and SettingAdministratorLocal SettingsTemporary Internet Files" is for Microsoft Internet Explorer. Your personal cookies from IE will be under your user name in something like "C:Documents and SettingYourUserNameLocal SettingsTemporary Internet Files".
"C:Documents and SettingAdministratorLocal SettingsTemporary Internet Files" is for Microsoft Internet Explorer. Your personal cookies from IE will be under your user name in something like "C:Documents and SettingYourUserNameLocal SettingsTemporary Internet Files".