php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38418 Javascript line interfering with setcookie()
Submitted: 2006-08-10 23:59 UTC Modified: 2006-08-11 09:05 UTC
From: steamboy at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.4.3 OS: Win 98, Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: steamboy at gmail dot com
New email:
PHP Version: OS:

 

 [2006-08-10 23:59 UTC] steamboy at gmail dot com
Description:
------------
I'm sorry, I could not check the bug with the latest version of php (only with 4.3.11), BUT before closing this topic, please try the code I posted because the bug is so peculiar, I would be surprised if it had been reported !

One line of javascript (displaying an html image tag with document.write), prevents the setcookie function to work correctly when the value is given with some conditional statements (using isset, or hiding an error with @).

Simply enter a word in the input field.

Reproduce code:
---------------
<?php

if (!isset($_POST['aa'])) {$ax='00';} else {$ax=$_POST['aa'];}

setcookie('test',$ax);
var_dump($ax);

?>

<script type="text/javascript"> document.write('<img src>') </script>

<form method="post" action="" name="test">
<input type="text" name="aa"><br><br>
<input type="submit" value="Ok">

</form>

Expected result:
----------------
It should set a cookie named 'test' with the value you have entered in the input field.

Actual result:
--------------
Instead it will set the '00' value to the cookie, even though dumping the variable produces the expected result, that is the content of the input field !

However, if you remove the javascript line, it will set the cookie with the correct value !

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-11 08:19 UTC] tony2001@php.net
PHP is server side language and it doesn't know about Javascript etc.
If your browser didn't sent POST data, there is nothing PHP can do about it.
 [2006-08-11 09:05 UTC] steamboy at gmail dot com
Sorry, my bad ! It appears to be a browser issue indeed (with Firefox 0.8).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 03:01:28 2024 UTC