+1 warrenm, it's export
that needs to be quoted.
But this sort of thing isn't good form. With all that nested quoting it's barely readable, and because you've not JavaScript-string-literal-escaped or HTML-escaped either date
or PHP_SELF
, you've got HTML-injection bugs which may lead to cross-site-scripting security holes.
Never output a text string to HTML text content or attribute values without htmlspecialchars()
, and when you're building JS objects use json_encode()
to create the output because it will cope with string escaping problems and quoting object literal names for you.
From PHP 5.3, the JSON_HEX
options allow you to ensure all HTML-special characters are encoded as JavaScript string literal escapes, so you don't have to HTML-encode on top of JSON-encoding, which means you can use the same output function in both event handler attributes and <script>
blocks (which, being CDATA, have no HTML-escaping).
<?php
function j($o) {
echo json_encode($o, JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_QUOT);
};
$pars= array("export"=>"export", "date"=>$_POST['date']);
?>
onclick="postwith(<?php j($_SERVER['PHP_SELF']); ?>, <?php j($pars); ?>);"
Also consider breaking out the onclick
handler and assigning it from <script>
instead of using inline event handler attributes. This tends to be more readable.