403 FORBIDDEN ajax calling script [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
JavaScript URL encode
some scripts working fine started to give me this error.
It is probably due to some special chars inside the string passed.
Ajax is calling this:
.../ControllerAjaxSpecifiche.php?Material=100%%20poliester&product=Maglia (trikot)
this way it says 403 forbidden error
removing the % and () it works
.../ControllerAjaxSpecifiche.php?Material=100%20poliester&product=Maglia trikot
How I can solve this problem?
I tried passing those variables as post, buit it did not works, and I continue having same problem.

Try urlencode() (php) or encodeURI() encodeURIComponent() (js) before passing the values. This should escape any harmful characters

You need to use urlencode to format your links correctly

Related

how to pass variables in url with an ID section using PHP? [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
I can do this:
home
But when I have a link with an Id, I can't pass variables:
home <--!this doesn't work of course -->
Thanks a lot!
When using PHP you can not use '#' in the URL, it will not be passed to the server.
You can use urlencode in order to encode the non-alphanumeric characters.
Use window.location.hash in javascript
<script>alert(window.location.hash);</script>
And the parse_url() function in PHP
<?php echo parse_url("home.php?var=home#sectionID",PHP_URL_FRAGMENT);?>
your HTML will be..
home
Declare a variable with $home dollar sign, i think you getting confused with JavaScript variable and PHP. To retrieve the variable values on a new page use $_GET['ID'].
Hope this helps.

How to print address url including # [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
I want to echo exact url : http://domain.com/mystuff.html#123456
but it only print http://domain.com/mystuff.html how to include the #123456 ? so become http://domain.com/mystuff.html#123456
my code so far
$urladdress = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];
You cannot. The fragment identifier is handled entirely client side so the browser will not send it to the server.
(The nearest you could come would be to (after the page has loaded) use JavaScript to sent it to the server in another request.)
you cannot get it using php, you can get it done by javascritp. use this test script to check your result.
<script>
alert(document.URL);
var urlDetail = document.URL;//you can use this variable to print in your web page.
</script>
Found the answer:
text

Using a Javascript variable inside a php block [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Pass a PHP string to a Javascript variable (including escaping newlines)
Access a JavaScript variable from PHP
I have a Javascript function that takes in one variable. The function has some php code inside it. I want to use this variable inside the php section of the function. I couldn't get it to work. How is it done?
The issue is that your PHP code is being rendered on the server before being served to the client. I would recommend either converting the PHP code into Javascript code or creating an AJAX call to the PHP function.
Start reading about AJAX! You will likely need to rewrite some of the code you have written but what you are attempting to accomplish is not really possible otherwise.
try with it
<script>
var whatever = "<?php echo $phpVar ?>";
</script>

php array to javascript [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Pass a PHP string to a Javascript variable (including escaping newlines)
I have a PHP array that I want to use in a javascript script. I suppose that I will have to convert it to a string that can be understood by javascript, and embed the string inside the script. What is the best way to accomplish this.
EDIT - This is for initial load of the page, not subsequent AJAX call
$textMessages = array();
You could use JSON.
json_encode and json_decode on the server side and JSON.stringify and JSON.parse on the client side. Both client side functions are natively built-into modern browsers but if you need to support legacy browsers you could include the json2.js script to your page.
json_encode(). Put in a PHP array, receive a string representation of a JS array.
JSON is perfect for this.
echo json_encode($textMessages);

How to pass # in url params? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
# in url getting ignored in php 5.2
I have following link on webpage. Here I am sending return(/profile?id=6#contacts) as url param to return back after operation complete. But it is sending only /profile?id=6 to verify.php script.
http://example.com/verify.php?id=1&sessionId=6&return=/profile.php?id=6#contacts
I know that hash value is not passed to server but I want to know that is there any way to pass compelete return param to server with # value.
Thanks
You need to urlencode() the entire return parameter.

Categories