Jump to content

isn't redirecting properly


freelance84

Recommended Posts

If you look at the following page, http://customcanvasuk.com/.

 

All the links on it will send you to another directory on that website e.g:

http://customcanvasuk.com/contact-us/

 

That URL will remain in the address bar as I am assuming that within the contact-us/ directory there is another index file.

 

 

However I am trying to achieve the same thing but without as much success.

The index.php in the public_html is a login page.

The user enters their details hits login and the details are sent to the login.php.

If all is correct the login.php uses header() to redirect them to another page.

This was working fine when I had all the files in the public_html, but now it doesn't.

 

if ($row[3] == '1')
{
header("location:http://www.site.net/adw/");
exit();
}

 

The above results a message from ff saying:

The page isn't redirecting properly

 

And the address bar reads:

 

 

Anybody know why?

I want the address bar to read:

 

Link to comment
Share on other sites

OK, I've now done a simple test.

 

1 Within the adw directory i renamed the index.php to something else

2. Then put a new file in named index.html

3. closed the browser and tried to login again.

 

It worked, the exact same header loaded the index.html.

 

I replace the index.php and deleted the index.html, and the once again it could not load.

 

Any ideas? (i know the .php file works just fine)

 

Link to comment
Share on other sites

Well, this is rather embarrassing, I've just realised a couple of the require_once() lines were still trying to get from the same directory as the index it was reading. Where they should be jumping back one step. I'm gonna change this and it should work.

 

Apologies.

 

 

Link to comment
Share on other sites

Failed opening required '/security/login.php'

 

The code to try and require is:

require_once '/security/login.php';

 

I've checked the spelling of the directories and that's fine.

 

The .php file trying to get the login is in the root directory, and the login.php is in "security" which is also in the root.

Link to comment
Share on other sites

Failed opening required '/security/login.php'

 

The code to try and require is:

require_once '/security/login.php';

 

I've checked the spelling of the directories and that's fine.

 

The .php file trying to get the login is in the root directory, and the login.php is in "security" which is also in the root.

 

I solved this via trial and error, and found removing the '/' from in front of the security worked.

 

Would someone be able to tell me what the correct way is to go forward and backward (directory wise) from within the public_html? I can't find it anywhere in my book or on google as i'm assuming this is assumed knowledge, only I don't know it  :confused:

Link to comment
Share on other sites

I always seem to get these backwards, but with the slash at the beginning of the path it indicates that the path should be relative from the root of the site. Without the slash the path should be relative from the current location/path.

 

If that is not what you are seeing, then it is the opposite.

Link to comment
Share on other sites

index.php is within folder "adw" in the public_html.

 

On load it must require_once a file named "functions.php" directly in the public_html.

 

I've tried using the following:

require_once '/functions.php';

 

but it returns

Fatal error: require_once() [function.require]: Failed opening required '/functions.php'

 

Any ideas?

Link to comment
Share on other sites

When referencing files, it uses the server filesystem.  If you start a file reference with a forward-slash, it references the root of the partition (eg. C:\ in windows).  If you want it relative to your current location, you need to either drop the initial forward-slash or start it ./.

 

As a test, run getcwd() and look at the output.  That is the directory of the script as the server filesystem sees it, rather than how the webserver sees it.  For example, if I echo getcwd() in http://www.mysite.com/test.php it gives /home2/[my_username]/public_html since that is where the file is stored on the server.

Link to comment
Share on other sites

 

Please pardon my not getting this, its really annoying me too.

 

 

Ok, I echo'd getcwd and it returned:

/home2/[my_username]/public_html

 

There is a folder in public_html named adw, therefore a php file echoing getcwd() should look like:

/home2/[my_username]/public_html/adw

 

The index.php within adw whose location should be:

/home2/[my_username]/public_html/adw/index.php

 

...requires a file whose location is:

/home2/[my_username]/public_html/functions.php

 

What should I be putting in the require_once()?

 

Should it be:

require_once (/home2/[my_username]/public_html/functions.php);

 

??

Link to comment
Share on other sites

It works!

 

Thanks for all your help!

 

A file in sub-folder test named "test" on public_html contains a file named "test1.php".

 

"test1.php" requires "functions.php" from a sub-folder named "testing" on public_html.

 

The following worked:

require_once ('../testing/functions.php');

 

I'm pretty sure this didn't work before, but it does now. I think there must be some more tangles in the actual index.php I was originally testing.

 

Either way I now understand a lot more on the subject.

 

Thanks once again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.