Welcome Guest, Not a member yet? Register   Sign In
Problem with IF structure
#1

[eluser]payamka[/eluser]
Hi
In my project the default controller name is home.and in the index method of home controller i have a if like this:

Code:
if(isset($_COOKIE['U_N'])){
   print "something";
}else{
   print "anoyjer thing";
}

if in url i write index.php like -localhost/project/index.php- it works fine but without index.php it does not work correctly.In case -localhost/project- if cookie is set or not the result is print "anoyjer thing".

Where is the problem?
#2

[eluser]Pert[/eluser]
Assuming this is not issue with URL rewriting, when you set your cookie, what domain / path do you set for it?

For security purposes you can limit where cookie can be read from, and it might be it's not allowed to be accessible by "subfolders".

Are you using custom or CodeIgniter cookie methods?
#3

[eluser]payamka[/eluser]
I using setcookie in php.I cant use CI methods.
if I set / in fourth parameter it works correctly.
#4

[eluser]Pert[/eluser]
Yes, if set to <b>/</b> it will be allowed throughout the site, otherwise it will only be allowed for said URL.

Because when you do not rewrite URL, everything runs through index.php, for browser this is always the same location, even when you add controllers and methods as GET variable, and if you do use URL rewrite, everything becomes different location for browser, if you see what I mean.

Sorted then? Smile
#5

[eluser]payamka[/eluser]
So if remove index.php by rewrite url,it become correct?
#6

[eluser]Pert[/eluser]
You should always set path to / for cookies. Otherwise rewritten URLs won't have access to any of the cookies set in other controllers.
#7

[eluser]payamka[/eluser]
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB