I created iframe where source is my PHP file, the file should display data from GET method the code is:
<?php
if (isset($_GET["phpMap"])){
var $response = $_GET["phpMap"];
echo $response;
}
?>
but when i run button that send data to that iframe nothing happens.
Plz correct your code as follow,
remove "var"
<iframe src="iframe.php?phpMap='google'" ></iframe>
in iframe.php put code
if (isset($_GET["phpMap"])){$response = $_GET["phpMap"]; echo $response; }
If data is sent using POST then you should update your code and change $_GET[] to $_POST[]
You also dont need to declare your variable like that outside of a Class.
$response = $_POST['phpmap'];
You can also troubleshoot by adding print_r['$_POST'] or print_r['$_GET'] at the top of the script to see what variables if any are coming over. Firebug is also good for capturing POST/GET transmissions and allowing you to see the values being passed back and forth.
You have to change the $_GET into $_POST then it should work with a button click.
If you need to send data from outside of the iframe into the iframe you need to make sure that you write query strings in theurl of the iframe source:
<iframe src="yourfile.php?var=someting"></iframe>
Like that you can recieve the valeue of $var in the script with
<?php $variable = $_GET['var'] ?>
Related
I am working on a project where i need to access clean URL's always i.e no parameters can be passed in the URL for getting values on another page.
Can anyone please suggest an alternative other than 'Form Submit' method.
Thanks In Advance.
Use $_SESSION for this purpose.
Using $_SESSION you can use variable in multiple pages wherever you want.
// assigning variable
$_SESSION['name']="variable";
//retrieving
echo $_SESSION['name'];
write session_start() at the top of page wherever you want $_SESSION variable
For Clean URL's i prefer you may use HTTP POST Method. Hope that helps.
<form name="frmApp" method="POST" action="/action.php">
</form>
Else, you can use AJAX with jQuery to submit the values to another page.
$.ajax({url:"action.php",success:function(result){
$("div").html(result);
}});
Check out w3schools to get started with AJAX : http://www.w3schools.com/jquery/jquery_ajax.asp
No support for SESSION since i don't like writing php code inside my web page.
Sessions can help, or ajax call.
for using clean url you can use post method in form
<form name='' method='POST' action=''>
You can try mapping resources to the url.
Suppose you want to get mailing address of a customer then you can write.
http://[baseurl]/[customerId]/mailingaddress.
Read more here
Let's say I have set up a PHP variable like this:
$phpurl = $_GET["url"]
where url value will be from GET variable query. The value of "url" will be some sort of html page link with some content like "myContent.html" I want to load.
How can I get this "url" value, which I have assigned to the variable "$phpurl"
and use it in the Ajax/Jquery page load request?
$('.content').load(' ** need the value of "$phpurl" to be placed here ** ');
Hope the question is clear. I am pretty new into programming. Thanks.
EDIT:
$('.content').load('<?php echo json_encode($phpurl); ?>');
will do
You'll want to take precaution to escape the value properly
<script type="text/javascript>
var url = decodeURIComponent('<?php echo rawurlencode($phpurl) ?>');
</script>
Or you could try something like https://github.com/allmarkedup/jQuery-URL-Parser
// requires no PHP at all!
var url = $.url(window.location).attr('url');
$('.content').load(url);
As a generic rule you should properly escape variables when you move them between two realms, in this case from PHP to JavaScript.
This is especially true if you don't have full control over the variable contents, such as those coming from $_GET, $_POST, etc.
This is a safe bet, using json_encode() to form a proper JavaScript value:
$('.content').load(<?php echo json_encode($phpurl); ?>);
here is the code??
posting code:
$.post('get.php',{selected:"aaaa"},function(return){alert(return);});
when i check the values of "selected" value using
<?php
$r=$_POST['selected'];
echo $r;
?>
is displays the value "aaaa" correctly..
this code works fine...
<?php
$r=$_POST['selected'];
?>
var answer="<?php echo "welcome" ?>";
when we echo the value"welcome" it is stored in the variable answer.and i could print that...
but when i put like this....
<?php
$r=$_POST['selected'];
?>
var answer="<?php echo $r ?>";
an empty value is stored in answer... and nothing gets displayed....
whether specifying $r inside " " is not right... how to specify that......
Assuming that the php code you are showing, is located in get.php, there is no use of using javascript in that same file. If you want to get the returned value in a javascript variable in your page, you need to use the first php snippet and use the return value in your .post function:
javascript in original page:
$.post('get.php',{selected:"aaaa"},function(data){
var answer = data;
});
get.php
<?php
$r=$_POST['selected'];
echo $r;
?>
$_POST['selected'] is probably empty to start with. Make sure you're sending a nonempty value for selected, and that you're using POST. (The easiest way is to look in your browser's developer tools for the initial request).
Note that directly outputting user input into the page introduces a Cross-Site Scripting Vulnerability: The input "; alert("evil"); can show that. Assuming you're using UTF-8 all around, you can write:
var answer = <?php echo json_encode($_POST['selected']); ?>
Also, there are often better ways to transfer data from php to JavaScript, including XHR requests/JSON or data-* attributes.
I'm passing a varaible to a iframe but can't seem to access this variable via the global get variable.
<iframe src="uploadContract.php?clientid={$clientid}" frameborder="0" height="95"></iframe>
in uploadContract.php I try to access the variable like $_GET['clientid'];
Somehow I can't seem to get the value via the Get global
What am I doing wrong?
What I noticed is that this iframe is within another frame, if I display the iframe not within a frame it actually works. How can I get this to work within a frame?
Check in the html that the src is really what you think it is.
Then try var_dump($_GET); from uploadContract.php
I doubt that the problem is in the code snippet that you present here. Are you sure that $clientid has a valid value when you try to use it in the above snippet?
Here is the code:
$('#sousmenu a').click (function (){
startSlideshow(<?php echo json_encode(glob("photos-" .$_GET["folder"]. "/*.jpg"));?>);
return false;
});
The question is I like the HREF to change and get caught by PHP, now it doesn't do anything, but writing the ?folder=portraits works.
Here is the page.
**** Simpler *****
Maybe I am not clear, it happens sometimes!
I want the link href to be send to this PHP function,
<?php echo json_encode(glob("photos-" .(i what the href link). "/*.jpg"));?>
so clicking on the link animaux will send animaux to the glob() PHP function and will get all the .jpg files in the photos-animaux folder.
Clicking on the portraits will send the photo-portraits, etc.
If you want to modify the URL and have the added/changed variable picked by PHP interpreter you have to reload your page. Just altering the URL doesn't do anything because JS is executed after PHP processing.
If your site is on http://example.com and you wish a myparam with value test to be passed to PHP you should add something like this in your JS:
document.location = 'http://example.com?myparam=test';
This will reload your page adding a new param which can be accessed in PHP by simply using $_GET['myparam'] variable.
You may also want to consider using AJAX to dynamically changing the contents of your page without having to refresh the whole page, but that's a little bit more complicated.
Look at the source in your browser.
Php is server-side, and that means you need to use ajax or reload whole page to get a response.
There is a nice ajax part of tutorial on jquery website, after reading it you should be able to do what you want: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Rate_me:_Using_Ajax