Codeigniter : how to pass hidden parameters in the url and make them available for parsing - .htaccess

I have an url like this :
www.domain.com/catalog/category_name/category_id/product_name/product_id
example :
www.domain.com/catalog/notebook/93/4_cpu_quad_core/56
and want it to turn into :
www.domain.com/catalog/category_name/product_name/
example :
www.domain.com/catalog/notebook/4_cpu_quad_core
The two ID parameters have to be passed to the application and parsed with PHP as I need it to get the correct category and product.
I have tried several ways using .htaccess and route.php config but no success !!
Can someone explain in simple manner how to pass these parameters to the web server while making these hidden in the url ?
I was just wondering if it is possible to pass hidden parameters in the url and make them available in the backend application (i.e. java or php).

Well! i wrote a function in the file system/core/uri.php
function assing_segment($num,$value)
{
$this->segments[$num] = $value;
return $this->segments[$n];
}
And call to this function either in the view or controller
$this->uri->assing_segment(5,$myvalue);
This will reassign segment 5 with my value

Can someone explain in simple manner how to pass these parameters to the web server while making these hidden in the url ?
There is no way to "hide" parts of the request. You can remove them, but then your application won't see them at all. For example, you can make all your URLs appear to be like www.domain.com/catalog/category_name/product_name/, but your php script isn't going to see anything about any IDs, since they're gone.

Related

How to handle urls in load runner?

I have created/recorded a script in Vugen, however the the URL of the site has been changed recently. Is there any way just by replacing the url with a parameter works?
I have tried by replacing url with parameters, the new URL is
http://xsx.xxx.xsx.xxx/test99
Yhe parameters I have tried are below:
NewUrl: http://xsx.xxx.xsx.xxx/
Newhos: test99
I have replaced all in the script and when I run it I get the following error:
Error -27651: Attempted read from an unconnected socket (empty response, no HTTP headers received). URL="http://xsx.xxx.xsx.xxx/scripts/uiServer.dll"
What is the solution for this? Should i record again with the new URL ?
Thanks.
Hope I've understood what you're asking for, so here goes. If it's only the URL that has changed and not the content of the site which you might require later on in your script that this is fairly simple to do.
As you have created the new parameters ensure that they are getting the data from the same DAT file. I.e. newurl.dat which contains the following:
newurl,newhost
http://xsx.xxx.xsx.xxx/,test99
and assign the parameters to the correct column and have the newhost set to sameline as newurl. This way it’s easier to maintain I believe.
Now that the parameters have been created and properly assigned in your script you’ll need to change the url your trying to change from:
http://xsx.xxx.xsx.xxx/oldtest to {newurl}{newhost}
this needs to be done for all instances where the change has occurred.
Hope this helps with your problem you’re having.
Are you certain that the build level has not also changed at the same time as the host? If so then your new instance may be out of synch with the request model of the scripts built using an earlier build. Developers have a habit of including items below the scenes that do affect the site visually but change the structure of the requests. The error you are receiving is common when you attempt to continue a conversation on a dead connection resulting from a missed dynamic session component which may have been added in the last build.
When in doubt quickly record the second site and take a look at the differences in the requests, even to the point of using WinDiff (included in LoadRunner) for this purpose.

Do I need to build a web form to use this web call?

When I replace the two options in this web call directly in the URL, I don't get the expected results.
https://secure.trademark-clearinghouse.com/tmch/public/labels?name=a%26b&jurisdiction=BX
Do I need to build a web form to use this web call?
Or am I replacing the options incorrectly?
Thanks.
Apparently you are using URL parameters to send some information
name=a%26b&jurisdiction=BX
means:
parameterName=parameterValue separed by "&" symbol.
in your case:
name="aɫb"
jurisdiction="BX"
If you want to just read that, will work without a form.
Any further explanation we will need more information about what do you want to do. But this symbol between the "a" and "b" is strange. As you can see here http://www.nicolas-hoffmann.net/utilitaires/codes-hexas-ascii-unicode-utf8-caracteres-usuels.php the code %26b is "ɫ" if you really want this in your data... it's okay.

Allow_url_include is there a way to allow includes from just one url

allow_url_include is there a way to allow includes from just one Url. maybe with Htaccess or in the PHP?
No. To fetch the contents of a URL, use file_get_contents(). Then, to send the result back to the waiting browser, just use echo().
$contents = file_get_contents('http://www.example.com/');
echo( $contents );
The above will require that you set config allow_url_fopen=1 (which is already set by default).
If you were to use include, instead of the approach I've shown above, there would be one major difference: include also executes any PHP code it finds inside the fetched document. In general, this is a really dangerous thing to allow unless you know that you control 100% of the contents of the document being included.
That said: if you do want code that works exactly like include, you can do something like the following (which is safer because it only fetches a single URL, and it doesn't require you to enable allow_url_include).
$contents = file_get_contents('http://www.example.com/');
eval('?>'.$contents);
If you choose do this, be certain that you control the full contents of the remote URL. If someone else controls that file, they will be able to execute arbitrary code on your server. Don't let that happen.
Well why you need that, you have control over the code, you can just use one url in while including. Beside using allow_url_include is very dangerous. If you still want to use, you can do it this way.
Make a custom function (A rough code)
function url_include($url){
//now check if $url is the one you want to be included
if($url=="http://www.mysite.com/file.php"){
include($url);
}else{
//show error or something.
}
}
now use this url_include("http://www.mysite.com/file.php"); in your page to include url.
Hope this helps

question title in url like stackoverflow

Id like to make a url similar to stackoverflow where the user can type in a textbox and then on refresh a url is created. like the url to this question uses the title i typed in. id like to make that effect on my own site. thanks. I think this may have to incorporate a .htaccess file??
You may notice that the words from the title in the question URL don't affect where the URL goes. The following link goes to the same place: https://stackoverflow.com/questions/6366169/foo-bar-baz
All you need to do is make your server process respond to the URL in the correct way. How you do this will depend on your chosen server architecture and/or programming language. Using .htaccess is unrelated.
maybe this link will help you understand how you can achieve your goal https://docs.djangoproject.com/en/dev/topics/http/urls/ (django)
http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/ (php)
other web frameworks operate in similar way
in the given example you can interpret the url http://stackoverflow.com/posts/9701416/edit like this:
if you find "posts" in the url the next part of the url (9701416) is a parameter and the last part is the action so your main controller will load a post with id 9701416 and it will be loaded in edit mode (it doesn't mean there's a sub directory questions with sub directory 6366169 with a file "post")

Passing an urlencoded URL as parameter to a controller / action at CakePHP

I'm fairly new on CakePHP and because of so, there are some basic things that I used to do with Zend Framework that I'm beaten up with Cake.
I'm working on a project where I have to pass a named parameter to a controller / action. Setting up the route and passing the parameter is fairly simple, my problem is when the parameter is a urlencoded url.
For example: http://www.cakephp.com/controller/action/http%3A%2F%2Fwww.google.com regardless of the controller and action setup, will throw a 404, but passing /controller/action/http://www.google.com work in some way, the only problem is that it identifies the http as a named parameter. In another way, if I do /controller/action?url=http://www.google.com it will work.
The work around that I had used for this is to pass the value as a base64 encoded string, but it brings some limitations. For instance, if it is an API, there is no way that you can guarantee that the system using the API can encode base64 a string.
Anyway the best solution would be still passing a url encoded string to a named parameter. Question is, why CakePHP does not accept a urlencoded string as a parameter and why does it throws a 404?
Thanks all in advance.
I have added a work around this issue. The previous answer that pointed to a post actually answered why it was happening and one of the solutions. What happens is that the workaround for .htaccess on Apache is a bit dangerous because it will disable a security criteria.
There are 2 ways to work this out via code (and I'm using both):
Send all urls as base64 encoded strings
Accept the urls as named params, but, as you will notice, it converts any http:// to http:/, so is necessary to correctly identify when this happens and only then correct the string.
It is far from being a beautiful solution, but it is definitely a practical one.
I stumbled upon this same problem in Cakephp 4.x
Apparantly you can create a custom route with ** that will disable the default urldecoding. Fixing the problem.
So right now I throw a base64_encode(Security::encrypt($val)) value into the Router::url() function. This will url_encode the params by default so it becomes a valid/working url.
Cakephp then urldecodes by default, which is good. But it does it twice? Causing it to split up the params if there is a / present. Which isn't good.
So in my routes.php I added:
$builder->connect('/orders/callback/**', ['controller' => 'orders', 'action' => 'callback']);
Kinda annoying how this works, but it works now. Works like a charm in 4.x and cost me the entire afternoon. Just leaving this here in case anyone else has this problem. (and for future me).
Source: https://github.com/cakephp/cakephp/issues/4723#issuecomment-56912905

Resources