I know there's a bunch of these topics out there, but all the answers are simply not working for me. I've tried everything I could find, and I'm still right where I started. I'm trying to pass a variable through a URL:
link
When clicking on the "link", it redirects me to the appropriate page (test2.php), but leaves the value blank (resulting in localhost/test2.php?one=). This means I can no longer see what variable was being sent.
$one = $_GET['one'];
echo $one;
How can I properly send the variable from test.php to test2.php?
Remove quotes from the href value:
link
<!-- ^^^ - quotes missing here -->
you closed the href try this :
link
Related
Is it possible to have a link submit to self with GET variables in it?
<a href='#?id=1234&c=2' data-toggle='modal' data-target='#mymodal'></a>
Then when clicked the URL would look like this -
example.com/test.php?msg=hello#?id=1234&c=2
But it doesn't work / PHP doesn't see any of the variables after the #.
I have the following code on the same page (for testing) -
echo $_GET['id'];
And I want it to echo 1234
Is there another way to do this?
Thanks!
If you want the query params you should put them before "#" and not after. When You put them after it, then your php script "won't see" them. Check out this answer on superuser for more.
Also your url example "example.com/test.php?msg=hello#?id=1234&c=2" has 2 "?" in it and it should not.
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 !
I need some help on passing a url php variable onto the next page. I've tried searching throughout the site for help and I've spent a lot of time trying to figure this out with no luck. Basically I need to be able to change the paypal link button id on page 2 with the url variable from page 1.
The variable is initially passed along with the URL: http://www.example.com?p=paypalbuttonid
I would like to store and pass that "p" variable on to the next page. I don't want to pass the variable onto page 2 with a link. I would prefer to store the variable and recall it on page 2.
Page 1 code (above html):
<?php
session_start();
$_SESSION['paypal'] = $_GET['p'];
?>
Page 2 code (above html):
<?php
session_start();
$p = $_SESSION['paypal'];
?>
I'm calling the variable in a link on page 2 (body):
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=<?php echo $p ;?>" target="_blank" class="btn">
I'm not sure what I'm dong wrong but I'm a complete newbie to PHP so please help! The variable shows up blank in the URL on page 2. Thank you! - Chad
First, you should make sure you dont have any output before session_start(), it is safe to put session_start () at the top of the page , especially if you use php code in .html, since you may have output without awareness, and session wont work if you have anything output to the browser before session_start()
according to php.net:
To use cookie-based sessions, session_start() must be called before outputing anything to the browser.
and you should check if you cookie is enabled.
Secondly, var_dump ($_SESSION); to see if you can get anything
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); ?>);
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'] ?>