Welcome Guest, Not a member yet? Register   Sign In
Block functions from being called in URL...

1. How can I block functions from being called in the URL but i can call them with JQuery.
in this scenario, this method, "_functionname()" wont work when im trying to use AJAX with that function.

2. How can I completely block controllers from being accessed by URL, but only my jquery functions can access them.
for example, I have a controller called , "ajax.php". In it is functions that will be called with jquery, i dont want people to access it.

Any suggestions?


You can add show_404() function to it or make a new line at your config/routes.php like that:

$route['controller_name/blocked_function'] = "home";

This will redirect blocked places to home controller

[eluser]Eric Barnes[/eluser]
For CI 1.x you can add this to constants:
// Define Ajax Request
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

CI2 now has is_ajax() in the input library.

Then in your controller:
if (IS_AJAX)
  // do code

Omg... misunderstood the question.

[eluser]Eric Barnes[/eluser]
[quote author="Ochetski" date="1294709983"]Omg... misunderstood the question.[/quote]

It happens Smile

It didnt work, and im running codeigniter 1.7.2

i added that to the constants.php

i added the if (IS_AJAX)
in the function, now when im trying to submit my form it gives me a 500 Internal Server Error in firebug

this was the error.
and i am using sessions with this function

Fatal error: Call to undefined method CI_Session::user_data() in /Applications/MAMP/htdocs/cl/application/controllers/ajax.php on line 369

i just realized i spelled it user_data(), instead of userdata, lol my bad ill try again and post back with the results

Theme © iAndrew 2016 - Forum software by © MyBB