Getting variable in iframe - php

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?

Related

How can I redirect to a PHP page with an <a> tag? Also how can I pass an ID number through the URL with it?

For my PHP project I am using a post method for the form and I want to be able to redirect to a PHP page with an <a> tag.
This is the code that I want to use to redirect, but I don't know how to make it work with the <a> tag.
$query_string = ['item' => $_SESSION['items']];
$url_query = http_build_query($query_string);
header("location:detailPage.php?$url_query");
Also, How can I pass an ID number through the URL from the current page to a different PHP page?
You can use html tag with embedded php code
TEXT
in detailPage.php you will call it like
if(isset($_GET['id'])//getting id from url using $_GET request
{
$id = $_GET['id'];//storing in php variable
}
I hope this will help you. If there is anything wrong kindly let me know

Passing a $_SESSION using <a href> outside php tags

I'm working with PHP and in this instance I want to pass $_SESSION which I've already assigned with my currentUser object. This works fine.
I've used the header function to pass variables between pages such as header('Location: example.php?uID='.$uID) and then using GET to receive this value.
However, instead of using a header to automatically redirect, I want to use a href so that the user has to click on a link, which then initiates the redirect.
The problem is that I use the anchor (<a>) inside the PHP tags and I can't pass variables using it inside the HTML tags.
I'd be very grateful for the solution and happy to elaborate. Thank you!
You can do it that way :
//assuming that the user id is stored in the 'uID' field of $_SESSION
Redirect me !

Access global variable in <iframe>

I have a page that is included as an iframe in my site. I need to supply the searched keyword to that page for DFP attribute and so I am setting the searched keyword as a global variable and now I need to retrieve the global variable in that iframe. So is it possible, and if so, how?
You can not access global variable in iframe because both will be separate request to server.
Either you need to pass variable as paramater in iframe src or you need to bind session variable in parent page and use that session value in iframe page.
You don't access this global variable in iframe because of limited scope. You can pass this variable in quarystring parameter. As like for example :-
<?php
var $param="test";
echo "<iframe src='test.php?param=".$param."'></iframe>";
?>
I hope it may helps!!

How can I capture/pass a keyword through a URL and pass it to a PHP page

I'm looking to pass a keyword from a HTML page to a PHP page through the URL string.
See example below to what I'm saying:
mysite.com/index.html?keyword=Google
the "Keyword" is Google and it needs to go over to my Thank you page.
mysite.com/thankyou.php
the code I use on my "thankyou" page is:
<?php $id = $_GET['keyword']; echo $id;?>
NOTE: I've visited and tried the links I found on the stackflow site... but none of them seem to work (asleast from what I've done with them). Am I missing any other thing when it comes to the code?
How do I get the current URL and then get the last words
how can i get the url if it is like this <keyword>?
How to pass a keyword from URL but keep it hidden? (Adwords)
If you could PLEASE provide a functioning example on a http://jsfiddle.net page so I can see how it works.
You need to have the get variable on the php page url, not the index.html page.
Example:
mysite.com/thankyou.php?keyword=Google
Alternatively you could write a html <form> and make a <input type="hidden" name="keyword" value="Google"> and grab it from POST instead of GET with PHP.
<?php $id = $_POST['keyword']; ?>

PHP run in iframe

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'] ?>

Categories