Codeigniter site_url Function Not Working Properly - php

I'm using site_url function on my project but there is something weird. It gets my Ipv6.
For example, I'm echoing site_url() and this is what I get:
http://fe40::8a43:dfff:feb3:ecff/project/
Actually I did not try anything to solve it 'cause I couldn't find anything about this problem on web. I can't use base_url, I have to use site_url. Please don't suggest things like this.
Thanks in advance.

Taken from the comment:
Try assigning your
$config['base_url'] = '';
to a specific address.

Related

Include page depending url (php)

I'm looking for a php code that include php file depending the page url. (I know wordpess do something similar)
I got this stupid code, but I'm sure I'm missing something..
$url = explode('/', trim(($_SERVER['REQUEST_URI']), '/'));
if ($url[0]==urlencode ('news))
require_once 'cpt/category/news-page.php';
if ($url[0]==urlencode ('home))
require_once 'cpt/category/home-page.php';
$current_url = $_SERVER['REQUEST_URI'];
if (strpos($current_url,"my-current-url")) {
require_once 'cpt/category/news-page.php';
}else if(strpos($current_url,"my-current-url")){
require_once 'cpt/category/news-page.php';
}
Here is a short example it might help you.
I've se the url of the page as $current_url. and we do a simple IF string poses something like "your url" and if it does then it does what you need.
Hoped that it helps, pretty sure you can set it up to work for you.
The best way is to use an Front Controller Pattern. All requests go through index.php, and then you can use a routing component to parse the url for you. See http://symfony.com/doc/current/components/routing.html for a good router. It ships with Symfony, but will work independently.
You could use some things like this: yoururl.php?act=news&para=latest
if($_GET['act']=='news')
{
require_once("cpt/category/news-page.php");
}

http0.0000000.000000www .. On Wordpress Log Out Redirect

I try to create a logout link which redirect to home url. I've tried this function:
wp_logout_url(site_url)
but, the output resulting strange prefix.
http://example.com/wp-login.php?action=logout&redirect_to=http0.0000000.000000www.example.com&_wpnonce=f2c0bef0b0
then I trying to hardcode the site_url(), but that prefix still exist and redirecting to wrong url.
How to solve it?
Thanks,
Wildan
I need to put urldecode() function. don't know why. So, it'll look like:
urldecode(wp_logout_url(site_url))

Unusual base url in Codeigniter with Chrome

I found it is unusual with the latest stable version of CI (3.03),
I tried echo base_url() and it returns some unusual thing,
**Note: ** I have loaded the URL helper .
The following code
$this->load->helper('url');
echo base_url();
returns http://127.0.0.1/ (I have used http://localhost/ to interpret the application) in Firefox.
And:
http://::1/ (Same I have used http://localhost/ ) in Chrome ?
Help me guys in fixing this.
Please remove base_url form the config file if you set there,
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/";
In your config, use define. like below:
define('base_url', 'http://localhost/your_project name/');
And then try
echo base_url() ;
Make sure you have set a base url
$config['base_url'] = 'http://localhost/project/';
Some times for me that is issue.
In older versions of CI you use to be able to leave that blank but.
Now it is recommended that you do not leave that base_url blank.
And I would auto load the url helper as it is the most common one.

php document url with parameters in url does not work

I´ve got an url like this www.example.com/v=12345. This will go to my index.php site on my webserver and the variable 'v' is used to do some javascript stuff, which works fine.
Now i want to link to the document 'newsite.php" like this or similar: www.example.com/newsite.php/v=12345. This does not work since the css does not work anymore and i don't know why.. If i do it like www.example.com/newsite.phpv=12345 , the variable is read correctly but it opens the index.php again.. How can i do this correctly?
Thanks guys!
You should pass php variable in url as parameter like this:
www.example.com?v=12345
and in your php just get this value by:
$_GET['v']
It should solve your problems :)
Variables need the seperator ? between url and variable. And if you have more Variables, the variables are seperated with a &
Example:
www.domain.com/?v=123
www.domain.com/script.php?v=123
www.domain.com/?v=123&y=456
And every variable will be available via $_GET[]
$_GET['v']
$_GET['y']

get URL in php IN INCLUDE FILE

i have some problem i try to get the uri in php.
I'm using:
$_SERVER['REQUEST_URI']
It works just fine if i do it in the index.php, but, i NEED to get the url in a include file, but, when i do it, it takes the FILE adress, i mean, it shows something like this
adress bar: www.webpage.com/index.php
$_SERVER['REQUEST_URI'] output: webpage/includefile.php
I am explaining myself here? Thanks!
How are you including the file? If it's being included via an HTTP reference then it's actually being served as a page and the functionality you are seeing is correct. If the include path is a local file, you shouldn't be seeing this behaviour
Found this whilst trying to solve the same issue.
My solution that worked is to use $_SERVER['HTTP_REFERER']
This worked well in that it also included the parameters (e.g. ?this=that&foo=bar)
Maybe somewhere in your code (or in another include file) the value is overwritten.

Categories