My URL: http://www.capstonehomes-mn.com/index.php?cID=127&ccm_token=1363683205:04db0d40a58c3559286c525f299e1fce".
This site was developed using concrete5. This url passing 2 query variables & calling to this page using jquery ajax form. This url doesnt display query variables & its value. what can be problem?.
I would like to get all query variable values in this screenshot: http://my.jetscreenshot.com/14061/20130319-prv0-77kb.jpgat the time of printing$_REQUEST`.
Some URLs working correctly.
My PHP code in target page:
print_r($_REQUEST);
echo $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] working correctly.
If I will paste this URL in browser address bar query variables working correctly. but not in ajax call.I'm seeing page not found in ajax call ( http://my.jetscreenshot.com/14061/20130319-iami-27kb.jpg )
Some frameworks using an own API for the request part. And in some cases they unset the global $_GET, $_POST and $_REQUEST variables.
If you look at the concrete5 documentation you can see that this framework uses such a API. I think if you use $req = Request::get(); then you can print the request variables.
Related
I'm having some issues with the PHP REST API of my app.
I'm submitting my parameters in the correct URL format: baseUrl?param1=val1¶m2=val2
However, the parameters are being filled into the $_GET array instead. I've looked into the $_SERVER array to see if there is something wrong there, but I can't see anything obvious.
$_SERVER['CONTENT_TYPE']="application/x-www-form-urlencoded"
$_SERVER['REQUEST_METHOD']="POST"
I've also checked my php.ini for post_max_size misconfig:
post_max_size=32M
I'm not able to figure what else could cause the parameters to be placed into $_GET
If it helps, I'm using XAMPP on Windows.
Also, using "Advanced REST client" for Chrome, I've noticed that regardless of the method, POST parameters are placed into $_GET if the parameters are in the URL, but if I move them into the REST client's Payload field, they show up as POST parameters.
You cannot get parameters via $_POST which are submitted in query-string. You can get them via $_GET array.
but if I move them into the REST client's Payload field, they show up as POST parameters., seeing your trouble, you can always get them with $_REQUEST
Just sharing a thought, The place from where you are initiating post request to backend, you have to use post method.
For example if you are using jquery
$.ajax ({ type: 'POST' })
If angular js
$http.post({ 'your code' });
i had some issues with understanding how to get javascript (client) variables transferred so they were acessible from php (serverside) as session : get an iframe's "src" value in PHP?
Now im in a situation where i use firebug to try to debug whats going on, but it just doesnt make sense :
i have this function to update an iframe and i want to pass on the page that that iframe is displaying :
function frameclick(pageurl)
{
$.post("session_write.php?",
{
frameurl : pageurl
}
$("#iFrame1").attr('src', pageurl);
console.log ('<?php echo "logout:".$langpath.$_SESSION['frameurl'];?>');
}
pageurl is ex. "/lang/en/new.htm" - and if i inspect it with firebug i also can see it says that it passes it correctly ( also with conversion of /).
my script serverside that its posted to is like this :
#session_write.php
<?php
session_start();
print_r($_GET['frameurl']);
if (isset($_GET['frameurl']))
{
$_SESSION['frameurl'] = $_GET['frameurl'];
print_r($_SESSION);
}
?>
Posting to that php script on the server will fail via the javascropt - $_SESSION['frameurl'] will be '', but if i ex. do it manually like this :
(http):
//localhost/phpmenu/session_write.php?frameurl=lang%2Fen%2Fnew.htm
then it will be correctly set in the $_SESSION["frameurl"] variable.
I simply cannot understand whats different between doing the javascript post and doing it manually in the browser and why its causing me this problem ?
anyone with an idea ? thanks
You are using .post, which executes a POST request, but when you type in the URL in the address bar, that is a GET request.
$_GET retrieves any params passed through GET, while $_POST retrieves any params passed through POST. So if you use .post with Javascript but try to retrieve with $_GET in PHP, it wouldn't work.
When you POST variables to a PHP file, $_GET is not set. Use $_POST['frameurl'] instead. Also, it looks like you're missing a close paren in frameclick to end the post call.
You are passing data via a
POST request and retrieving for all the GET requests. Use $_POST instead. You may also be interested in $_REQUEST
Erm... what the title says really; I have a PHP script executed by an AJAX call on page1. Can I access page1's current URL/URI from inside the PHP called by AJAX using standard $_GET, or do I need to pass the parameter I want along with the rest of the data to the AJAX page?
Thanks,
James
Referrer should do the trick
echo $_SERVER['HTTP_REFERER']
from within your php script
Just to get more specific:
Page1 makes a call to Page2. You'd then output the variable above to find the url of page1. If you need the url of page2, then you would use:
$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
You should check if these exist before trying to access them. I sometimes do this:
$server = array_merge(array('HTTP_HOST'=>null, 'REQUEST_URI'=>null, 'HTTP_REFERER'=>null), $_SERVER);
I would then access the variable "$server" instead of $_SERVER. Alternatively, you could use #$_SERVER[] too which will generally supress errors.
I am using jquery to post vars to a php script.
Is it possible to access these vars once the script has posted? If I post the data to the php script, is the only way to access it in the html/js that i posted it from, to send it back from the php script as json?
I cant seem to do it in JS, but even php will not work?, Sorry correction i can access the post vars in the php page, but not in the html/js page i posted from
Any ideas how to access posted vars from the page thats doing the posting?
update: yep to be a bit clearer, i am using a html page with javascript to post to a php page, i would like to access the posted vars in the html javascript page. I tried outputting $.post and $.ajax and these just show a long function.
Cheers
Ke
How are you submitting your elements to php page? If you are doing everything fine and using ajax (see jquery post method) for example, you can access the php variables normally with $_POST['var_name'].
Make sure that:
Your form method type is set to POST
Your ajax request goes successful
You have specified the correct path to your server side script
In PHP, the data should be accessible through the $_POST array, just like if you posted to the script using a form (whether you make an AJAX request or a normal request through your browser, the server behaves the same). If they're not there, perhaps you actually sent your data by GET instead (you could check $_REQUEST, but it's better, and more secure, to know what method your data will be coming in), or else your AJAX request failed.
I don't recommend using $_REQUEST to post something back to your site. If someone changes their $_REQUEST vars on you, then you have an opening for cross site scripting.
Push all your vars to $_SESSION and post them as you see fit but only after they have been purified. That way even if you make some modifications to them after the fact you can rely on the source, which is in the $_SESSION. However if you are trying to perform actions after a page has executed you are straying outside the boundaries of PHP's limitations. People do it all the time with things like Jquery but it doesn't make it right.
Warning: if you allow accessing and process of vars after PHP has finished printing the page, then you run the risk of enabling attacks on your code.
I assume that you are using $.ajax or $.post to do this.
Just keep your data in local variables. There i sno reason why you should lose the posted data, or your php not being able to access it.
If you post code, maybe someone can help better.
In your php function, you can use this:
function foo() {
//do something
echo json_encode($var);
}
I use .ajax, use dataType: "json". The success attribute would be:
$.ajax(
{
url: 'ajaxfile.php',
type: "POST",
data: ($("#myForm").serialize()),
dataType: "json",
success: function(data)
{
//Insert your logic to handle the vars from php
}
});
I'm trying to make a bookmarklet that will take the URL of the current page you are on, and send it to an application written using CodeIgniter.
The problem I keep running into is that I can't do a standard AJAX call, because it's cross-domain. It is disallowed, and I can't figure out a way to use the JSONP via $_GET method since CodeIgniter blows away the $_GET parameter.
At this point I'll take any suggestions on how to do this. Please note that I need to send a URL, and if it's to be passed via a URL itself it obviously needs to be encoded or something. This I also haven't figured out how to do, so any pointers on that end would be appreciated as well.
Codeigniter unsets $_GET but you can get the data from the query string. It is a little inefficient because PHP will probably end parsing the query string twice, but it should work:
parse_str($_SERVER['QUERY_STRING'], $get);
print_r($get);
All the GET variables should be accesible in the variable $get. See parse_str() documentation for some more information.
As an alternative you could url-encode the current URL and append it to what you are requesting e.g.
var url = 'http://example.com/bookmarklet/'
+ encodeURIComponent(window.location);
Then in Codeigniter do something like:
//you might have to call urldecode() on this value
$url = $this->uri->segment(0);
but you may find you then have this problem
It is possible to enable query strings in Codeigniter, but watch out for the caveats - you can't use the URL helper, for example.