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 Wilson Edwards
at 2025-02-11 17:07:11
Point:500 Replies:1 POST_ID:829291USER_ID:12108
Topic:
javscript;google_cookie
For latest browser, u can only read cookie value by javascript code. Remove and Update cookie by javascript is very difficult...
To read all cookie, u can go to devtool, Mouse Right-click->inspect->Application->Cookie
u can see all website cookie u are accessing..
You can remove all cookie for the website..by php coding
For example:
<?php
if(isset($_SERVER['HTTP_COOKIE'])&&stripos("#".$_SERVER['QUERY_STRING'],'gt=3')>0)
{
$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
foreach($cookies as $cookie) {
$parts = explode('=', $cookie);
$name = trim($parts[0]);
setcookie($name, '', time()-1000,'computer28.com');
setcookie($name, '', time()-1000, '/','computer28.com');
setcookie($name, '', time()-1000,'.computer28.com');
setcookie($name, '', time()-1000, '/','.computer28.com');
}
}
if(stripos("#".$_SERVER['QUERY_STRING'],'gt=3')>0)
{
header("location:https://computer28.com");
}
?>
On address bar with gt=3, it will forward to the main domain site,
For update cookie,
justsetcookie($name, ''', "the time you want for expire",'computer28.com');
Hope it help
Expert: rcschroeder replied at 2025-02-11 17:08:20
The introduction of deletion of browser cookies by latest browsers has made it more challenging for developers to manage cookies programmatically. Here's a summary of your question and a possible solution:
**Problem:**
With the latest browser versions, it's becoming increasingly difficult to read cookie values using JavaScript alone. The only way to access all website cookies is to use DevTools and inspect the cookies directly.
However, some websites still rely on PHP to manage cookies for user authentication or session management purposes. This is where your code comes in – a PHP script that allows you to delete cookies for a specific website by parsing the HTTP cookie string and using the `setcookie` function to remove each cookie.
**Code Explanation:**
Your PHP code snippet does the following:
1. Checks if the HTTP Cookie header is set and if it contains a query parameter named "gt=3". If both conditions are true, it extracts the cookie values from the HTTP Cookie header.
2. Loops through each cookie value and uses the `setcookie` function to remove it with an expiration time of -1000 seconds (i.e., immediately).
The code then checks if the query parameter "gt=3" is present in the URL and redirects the user to the main domain site using a 301 redirect header.
**Improvement Suggestions:**
While your code solves the problem of deleting cookies, there are some potential issues to consider:
1. **Insecure Cookie Expiration**: Using an expiration time of -1000 seconds might not be secure enough, as it allows cookies to remain active for an extended period. Consider using a more robust approach, such as generating a unique expiration timestamp for each cookie.
2. **Query Parameter Tampering**: The code relies on the query parameter "gt=3" being present in the URL. However, users might intentionally tamper with this parameter or bypass it altogether. To mitigate this, consider adding additional security measures, such as validating user input or using a more secure authentication mechanism.
3. **Cookie Renewal**: When deleting cookies, it's essential to ensure that new cookie values are generated and sent back to the server for validation. This will help prevent session fixation attacks.
**Alternative Solutions:**
If you're looking for alternative solutions, consider exploring:
1. **Session Management Libraries**: Utilize PHP libraries like Laravel's Session Manager or Symfony's Session component to manage sessions and cookies more securely.
2. **Cookie-Based Authentication**: Implement a more secure authentication mechanism that uses cookies with a shorter expiration time and generates new cookie values on each login attempt.
3. **Token-Based Authentication**: Replace cookie-based authentication with token-based authentication, which is generally considered more secure.
In conclusion, your PHP code provides a useful solution for deleting cookies, but it's essential to address potential security concerns and consider alternative solutions to ensure the most secure authentication mechanisms are in place.
**Problem:**
With the latest browser versions, it's becoming increasingly difficult to read cookie values using JavaScript alone. The only way to access all website cookies is to use DevTools and inspect the cookies directly.
However, some websites still rely on PHP to manage cookies for user authentication or session management purposes. This is where your code comes in – a PHP script that allows you to delete cookies for a specific website by parsing the HTTP cookie string and using the `setcookie` function to remove each cookie.
**Code Explanation:**
Your PHP code snippet does the following:
1. Checks if the HTTP Cookie header is set and if it contains a query parameter named "gt=3". If both conditions are true, it extracts the cookie values from the HTTP Cookie header.
2. Loops through each cookie value and uses the `setcookie` function to remove it with an expiration time of -1000 seconds (i.e., immediately).
The code then checks if the query parameter "gt=3" is present in the URL and redirects the user to the main domain site using a 301 redirect header.
**Improvement Suggestions:**
While your code solves the problem of deleting cookies, there are some potential issues to consider:
1. **Insecure Cookie Expiration**: Using an expiration time of -1000 seconds might not be secure enough, as it allows cookies to remain active for an extended period. Consider using a more robust approach, such as generating a unique expiration timestamp for each cookie.
2. **Query Parameter Tampering**: The code relies on the query parameter "gt=3" being present in the URL. However, users might intentionally tamper with this parameter or bypass it altogether. To mitigate this, consider adding additional security measures, such as validating user input or using a more secure authentication mechanism.
3. **Cookie Renewal**: When deleting cookies, it's essential to ensure that new cookie values are generated and sent back to the server for validation. This will help prevent session fixation attacks.
**Alternative Solutions:**
If you're looking for alternative solutions, consider exploring:
1. **Session Management Libraries**: Utilize PHP libraries like Laravel's Session Manager or Symfony's Session component to manage sessions and cookies more securely.
2. **Cookie-Based Authentication**: Implement a more secure authentication mechanism that uses cookies with a shorter expiration time and generates new cookie values on each login attempt.
3. **Token-Based Authentication**: Replace cookie-based authentication with token-based authentication, which is generally considered more secure.
In conclusion, your PHP code provides a useful solution for deleting cookies, but it's essential to address potential security concerns and consider alternative solutions to ensure the most secure authentication mechanisms are in place.