Welcome Guest, Not a member yet? Register   Sign In
How to create our profile url
#11

[eluser]JasmineFlower[/eluser]
Hi,

I followed your instruction to create a hook.

but now i used local host server..
my folder name : projects
my codeigniter folder name : example

In my database table - user - have username & user_urlname fields.
for ex: username : jasmine, user_urlname: flower (created by user)

so i need url like this -> localhost/projects/example/flower

In my htaccess file having :

Code:
RewriteEngine on

RewriteBase /projects/example/

RewriteRule ^admin/$ index.php/admin/login/
RewriteRule ^admin$ index.php/admin/login/

RewriteCond $1 !^(index\.php|application/images|application/scripts|application/css|application/content|application/settings|favicon.ico)
RewriteRule ^(.*)$ index.php/$1


In my hooks,
Code:
$this->uri =substr($_SERVER['REQUSET_URI'],1);
.
In $this->uri gives the result = /projects/example/flower. but my database field user_urlname having data - flower.
how can i check by using query ?

suppose i change second parameter for the above code like this
Code:
$this->uri =substr($_SERVER['REQUSET_URI'],18);
. It gives the result =flower.

now the if condition is true but 404 error raising.
I don't know what mistake i made in that code, pls tell me to correct that error
#12

[eluser]toopay[/eluser]
Above class expected the first segment uri (after trailing slash) as user_url, and then if the condition match, it will told CI to re-route the requested uri to the '/user/index/id', which cause 404 error in your localhost environment!

I think, its best practice to set your development environment, as close as possible with 'live' environment. It will avoid errors like you stated above. I mean, first, you must have accesible url like 'local.yoursite.com' in your local computer.
#13

[eluser]toopay[/eluser]
If you don't know how to do that, here the quick way.

1. If you're using windows, first you must add your host name in 'C:\WINDOWS\system32\drivers\etc\hosts'. Open 'hosts' file, then add 1 line
Code:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost
# add your new host name
    127.0.0.1       local.jasmine.com
2. Suppose you have XAMPP installed on 'C:\xampp'. Open 'C:\xampp\apache\conf\extra', find file called 'httpd-vhosts.conf', and add this code after the very end line..
Code:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:\xampp\htdocs\projects\example\flower"
ServerName local.jasmine.com
    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
    </Directory>
    <Directory "C:\xampp\htdocs\projects\example\flower">
        
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all

    </Directory>

    
    <IfModule dir_module>
        DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
                       default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
                       home.php home.pl home.cgi home.asp home.shtml home.html home.htm
    </IfModule>

    
    <FilesMatch "^\.ht">
        Order allow,deny
        Deny from all
        Satisfy All
    </FilesMatch>
</VirtualHost>
3. Restart your apache, through XAMPP control panel, and try to access 'http://local.jasmine.com', it should pointing you to your codeigniter apps (if didn't, then there is an misconfiguration!).
4. Change your htaccess to
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
and i see you try to redirect some uri to admin page, do that by set a route
Code:
$route['admin/(:any)'] = "admin/login";
#14

[eluser]JasmineFlower[/eluser]
hi toopay,

Thank u so much. its working...

suppose if i change my domain name , i must change the system files..s correct

once again thank u
#15

[eluser]JasmineFlower[/eluser]
Hi,

I found another way without changing system config & server config files.

In my hooks file userlookup.php as below

Code:
&lt;?php
if (!defined('BASEPATH')) exit('No direct script access allowed');


class Userlookup
{
    protected $uri;
        
    protected $hostname;
    protected $username;
    protected $password;
    protected $database;

    public function __construct()
    {
        // Configure database connection
        $this->hostname = 'localhost';
        $this->username = 'username';
        $this->password = 'password';
        $this->database = 'dbname';
    }
        
    public function check_uri()
    {        
         $username  = substr($_SERVER['PATH_INFO'],1);            
         $url = explode("/",$username);
    
         // Connect to database, and check the user table
         mysql_connect($this->hostname, $this->username, $this->password) AND mysql_select_db($this->database);
         $res = mysql_query("SELECT url_name FROM users WHERE url_name='".$url[0]."'");
         if(mysql_num_rows($res) > 0)
         {
         if ($row = mysql_fetch_object($res))
         {            
            $_SERVER['PATH_INFO'] = '/controller name/method name/'.$_SERVER['PATH_INFO'];
         }
         mysql_free_result($res);
         }
    }    
    
}

?&gt;
#16

[eluser]frozenmaiden[/eluser]
I try your solution and it work well in sub domain, but why it raise 404 error on main domain?

For example i have http://test.com and http://shop.test.com

i want if people access http://test.com/myprofile it will redirect to http://shop.test.com/myprofile

and

http://shop.test.com/myprofile will redirect it to their user profile.

hooks in http://shop.test.com/myprofile works like a charm, but hooks http://test.com/myprofile raise 404

errors. T_T

Code:
$_SERVER['REQUEST_URI'] = '/p/r'.$_SERVER['REQUEST_URI'];
$_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'];
$_SERVER['QUERY_STRING'] = $_SERVER['REQUEST_URI'];
$_SERVER['REDIRECT_QUERY_STRING'] = $_SERVER['REQUEST_URI'];
$_SERVER['argv'][0] = $_SERVER['REQUEST_URI'];

i try to change all that server variable,but nothing to change,please help..

EDIT:
I solve the problems by myself, but get strange solution.. I change $config['uri_protocol']
on http://test.com to QUERY_STRING and it work perfectly.
That make me confuse,because on http://shop.test.com i set $config['uri_protocol'] to AUTO,
and no problems at all.:-S

NOTE: http://test.com and http://shop.test.com each have their own CI.
#17

[eluser]Amitabh Roy[/eluser]
It would be great to know if anybody have taken this a step forward and have implemented the following

Code:
http://www.example.com/username

http://www.example.com/username/feedback

http://www.example.com/username/contact

http://www.example.com/username/products

etc , which should pull up the data for the relevant function(feedback,contact,products) for the given user(username)




Theme © iAndrew 2016 - Forum software by © MyBB