This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Securing a remote ajax method call
Is there a way to retrieve the name of the javascript file that called a php script from within the PHP code?
Unfortunately, since I have to call a PHP script from Javascript (for Google maps) on a webpage, this 'invites' to retrieve my data by just calling the PHP script by hand. Checking for the script/file that invoked the PHP script would bring at least some protection.
You could set a session variable with some random value on the server when your page is opened, and add that variable in the query string to your php script.
Then in your javascript-called php script, you start the session and check the session variable against the query one.
Related
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 8 years ago.
I have a page with a java script that adds a row to a table. On the same page there is a PHP script that should read the table and add it to the database. How do I read the table using PHP ?
What you're thinking of will not directly work.
A Javascript script is executed on the client side only, whereas a PHP is executed on the server side only, and before the datas are sent to the client.
PHP can not directly read the table.
What you can do is use AJAX to send the data from the user's browser to a PHP script that'll use them.
You'll find more infos here.
PHP is serverside programing, the PHP code serves data to the client - PHP can't read from the client.
If you add a row using javascript, PHP has no way of getting that info.
You'll need to use Ajax to solve your specific problem.
You cannot "read the table" with PHP. You will have to send the data of the table to the server (and read it with PHP) using JavaScript or CGI.
A well-known technique to do this is called Ajax.
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 9 years ago.
I'm trying to connect to my SQL server via Javascript.
In order to do this, I have to execute some PHP code, but I'm having some trouble with that.
At the moment I use this code to execute a PHP script, without success
function testConnection()
{
$.get("script/SQL/testConnection.php");
}
How is it possible to execute some PHP code, or connect to the server and execute SQL queries?
Thanks
Matt
That $.get call you have is a relative URL. Let's say your user is on page domain.com/home/. If you use that code block, the user's browser is going to make a GET request to domain.com/home/script/SQL/testConnection.php. Is that what you are expecting?
What HTTP status code are you receiving back?
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 have a code and need help. I have a curl call with a bash sign like this
http://example.com.ua/script.php
clients send me data using a script but some send me the bash # which I need to save all the data to my database. When I get $_SERVER I don't see all the data how can get all the data?
for example:
I have
http://example.com.ua/script.php#code1234
I need to save:
example.com.ua/script.php#code1234
but I see
example.com.ua/script.php
PHP does not have access to the location hash, period.
You only have access to querystrings in PHP, and if you need to get the hash, you would have to use javascript to get it, and send it to your PHP script with ajax.
This question already has answers here:
pass value from page to another in PHP
(3 answers)
Closed 8 years ago.
i have a variable for displaying a msg at the end of a procces,
and that procces in includeed in different page , i wanted to manipulate that variable in the other page(the one i included the procces in it)
the problem is that the variable is intitiated at the beggining of the procces page,
so whenever i use that page , the variable will reset.
i tried different ways but nothing worked
it just output the value i assign it in the procces page
i tried making it global and modifying it but didnt work ..
Your PHP page doesn't remember anything at all, not by itself. When someone types your page in their browser, the server executes your script. PHP blindly executes it and doesn't try to remember anything.
Except if you use sessions, or some form of persistent storage such as a database. In your case, you want to use sessions: Take a look.
HTTP is a stateless protocoll and so is PHP: you can't read variables in one page request from the other. You need to use sessions for that, session_start() and $_SESSION.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Access a JavaScript variable from PHP
theVariable = String.fromCharCode(theVariable).toLowerCase();
is it possible to use theVariable in PHP codes ? How?
Not really... you can send it to a PHP script using AJAX or an HTML form. I strongly recommend you get a clearer understanding of what JavaScript is vs. PHP, particularly what it means that JavaScript runs on the client-side (i.e. in the browser), and PHP runs server-side.
Only if the the variable is sent via ajax to a PHP page. You see PHP is executed first, then the page is served to the client. Then the client executes the javascript. So the javascript is executed long after the PHP has been executed.
To use a variable that is in JavaScript in PHP, you have to send an Ajax request to a PHP page passing that variable in. This probably isn't the effect you're looking for.
JavaScript executes on the viewer's computer. PHP executes on the server. To send a JavaScript variable to PHP, you need to send some packet of information from the client to the server. This is done as a GET/POST request.
The only way to pass a variable from JavaScript to PHP is to pass it by an AJAX call.