Codeigniter Url Problem on Server - php

I have some problem in codeigniter url segment problem in server..
In local server my web url is http:localhost/test/index.php/user/userGetData/3..if we want to get the 3 from url in controller function .
then we use $this->uri->?segment(3); it works.
But when uploaded on server we use url rewriting
$routes['getData'] = 'user/userGetData/$1'; and refresh the page after this change, server url look like http://www.test.com/getData/3
in controller function userGetData() $this->uri->segment(3); doesn't work.
How to fix this problem and same case in all function?

Are you sure $this->uri->?segment(3) it's work?
First, you need to change $config['base_url']
Use $this->uri->segment(2) to get data.

Related

webroot entire path in Yii2

I have some trouble with an Yii2 application.
I need to put into a variabile the complete webroot path of my application, in my case www.mysite.it/language/catalogue/. When I call the function to retrieve this information, I get www.mysite.it/application/web where application/web is the root of my project.
I have tried this function:
$home = Yii::$app->request->getAbsoluteUrl();
It is any way to do what I want?
Thanks in advance.
You should use yii\helpers\Url features
http://www.yiiframework.com/doc-2.0/yii-helpers-url.html
http://www.yiiframework.com/doc-2.0/guide-helper-url.html
and eg_ for home Url::home()
$absoluteHomeUrl = Url::home(true);
or for Url:to()
$url = Url::toRoute(['language/catalogue/']);
the use of the UrlHelpers prevent your code from different url result related
to your urlManager config (with or without pretty url)

codeigniter allow "http://" in get variable

My app is based on Codeigniter Framework
If I type the following url, I get 404 error :
http://example.com/mycontroller/func/?url=http://www.hello.com
but if type anything other that http it work normally, for example
http://example.com/mycontroller/func/?url=ptth://www.hello.com
EDIT:
I want to achieve this because I have a form that doesn't submit when I use the word http inside it, this form need to be stored into the database. I don't know why this happen at all but all I know is that if I can get the app to work the url form above it would probably work fix my problem with the form too as long as the problem looks similar Here's my other question
Why codeigniter doesn't allow the word http:// to be passed as a get variable and How can enable the word 'http://' to be able to pass through the URL ?
Make sure your config file has the following:
$config['enable_query_strings'] = true;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-=&?';
Note the ? added to permitted_uri_chars

How could I use PHP to get page by URL, which redirects to local path?

I'm trying to get page content by URL (e.g. 'http://example.com/page.html') using PHP, but remote server redirects it to another page (e.g. 'http://example.com/another-page.html') and when I try to execute code:
$p = file_get_contents('http://example.com/page.html');
echo $p;
browser returns 404 error:
The requested URL /another-page.html was not found on this server.
As I understand, instead of getting 'http://example.com/another-page.html', PHP tries to return 'another-page.html' from my localhost and of course there is no such page. Seems like remote server redirects using local address ('/another-page.html' instead of 'http://example.com/another-page.html') which is correct of course, but I don't know how to deal with it.
Could anybody advise me, how could I solve this problem?
Thanks in advance

Error with a "returnUrl" in URL params

I am working with the Yii Framework.
In a controller, after a model save, I'm trying to redirect the user to /module/controller/action and set a parameter (redirectUrl) to another URL. Here is my code:
$this->redirect(array('/module/controller/action/', 'redirectUrl'=>'/index.php/some/url/id/'.$id));
This seems to work well as I am redirected to:
http://localhost/index.php/module/controller/action/redirectUrl/%2Findex.php%2Fsome%2Furl%2Fid%2F11
But when I get there I get the following error:
Not Found
The requested URL
/index.php/module/controller/action/redirectUrl//index.php/some/url/id/11 was not found on this server.
The URL like /index.php/module/controller/action/redirectUrl/1234 works fine.
I don't understand what I am doing wrong here, URL seems to be correctly encoded. Any idea would be of great help!
Thanks
Your example URL is only passing 1234 as the parameter, not a full relative URL, e.g. /index.php/some/url/id/1234. I think what you want is:
$this->redirect(array('/module/controller/action/', 'redirectUrl'=>$id));
You could skip the URL rules on your server and minimally reduce load with:
$this->redirect('/module/controller/action/redirectUrl/' . $id);
$this->redirect($this->createUrl('/module/controller/action/',
array('redirectUrl'=>'/index.php/some/url/id/'.$id));
If this does not work do
$this->redirect($this->createUrl('/module/controller/action/',
array('redirectUrl'=>$id));
and then just add '/index.php/some/url/id/' in the action.
http://www.yiiframework.com/doc/api/1.1/CController#createUrl-detail

Help with moving codeigniter to a new server

I am having a bit of a problem. I am duplicating my website to a test environment on a new server with a new domain.
I have it working fine with the database etc but here is my error.
On the live site if I click suppliers it goes to the page fine If I click it on the test environment it does not work.
These are two links
http://wvtest.co.uk/
http://theweddingvine.com/
The code to create the link is as follows:
<?php
echo anchor('search', 'Suppliers');
?>
The file and the folders are the same. Is there something in codeigniter which can direct the link ?
Modify application/config/config.php and set:
$config['base_url'] = "http://{$_SERVER['HTTP_HOST']}/";
That will make your links work on either server.
have you specified the correct base_path for your testing server in application/config/config.php file?
Check that please, this is the case mostly in such problems.
You could change your base_url to
$config['base_url'] = 'http://wvtest.co.uk/';
or
$config['base_url'] = '/';

Categories