Author |
Message |
Darrell3831
Worker


Joined: Feb 18, 2004
Posts: 244
|
Posted:
Wed Feb 01, 2006 12:52 pm |
|
Hi,
I'm writing my own module for nuke 7.6 and I have a programming question. I hope this is the right place to post this.
When a guest clicks on a link to your site from somewhere else that dosent exist on your site anymore they get the 404 error.
I know you can use htaccess to load a file instead of accepting the default file not found page. Simply creating an .html file is not very professional looking though, because it does not easily carry over with your same theme etc..
So I wrote a simple module for Nuke. 404_error.
You can see this little script in action by clicking on this link to a non-existent file on my server.
Only registered users can see links on this board! Get registered or login!
By making this a module all the rest of your nuke site is still there. Now they can search your site for whatever it was they wanted.
I'm slowly getting to my question.
As you can see, I have this part working. So I wanted to add some more functionality to it.
I am in the proccess of adding the ability to email the admin with information about the page not found. It's a function that can be turned on or off within the script.
I want to gather information for this report.
These work as expected for me:
Code:$ip = $_SERVER['REMOTE_ADDR'];
$servname = $_SERVER['SERVER_NAME'];
$httpref = $_SERVER['HTTP_REFERER'];
$httpagent = $_SERVER['HTTP_USER_AGENT'];
|
But, this one does not.
Code:$requri = $_SERVER['REQUEST_URI'];
|
For some reason the requested URI is that of the module. ie. It's the modules name and not the one that generated the 404 in the first place.
Finally, here's my question.
How do you catch and transfer the the requested URI from the htaccess file into the module?
Thanks,
Darrell |
_________________ http://www.psy-center.com |
|
|
 |
hitwalker
Sells PC To Pay For Divorce

Joined:
Posts: 5661
|
Posted:
Wed Feb 01, 2006 4:37 pm |
|
yes thats a common problem,the first who made the error module was disipal.
however...first mistake you make.. is that the htaccess only activates the 404 error module.
and because we use the 404 module the htaccess file refers to the module.
problem that rises is that if not called properly it will give the module name/url instead of the request uri.
Hope you can follow this.....lol
i had my problems with it as well.
Can you put the code here.... |
|
|
|
 |
Darrell3831

|
Posted:
Wed Feb 01, 2006 5:59 pm |
|
um,
You said the first to make the error module was disipal. Is that a person? I don't know what you mean by that.
I wrote this module from scratch myself.
I realize that the URI is the way it is because the htaccess file is calling it, or accessing it that way.
The code you asked for I assume is what is in the htaccess file??
Code:ErrorDocument 404 http://www.psy-center.com/modules.php?name=404_Error
|
What I was asking here is how can I tell what the original URI that caused the error.
Is there a way to catch/trap it in the htaccess file?
If there is a way that I don't know of that would be great. I could pass it along in the call.
Something like ?uri=blahblahblah appended to the end??
In the unlikely event your asking me how and I trying to get the URI in the error module I wrote, it's like I showed you up above.
Code: $requri = $_SERVER['REQUEST_URI'];
|
Thanks!
Darrell |
|
|
|
 |
hitwalker

|
Posted:
Wed Feb 01, 2006 6:11 pm |
|
well disipal is like www.disipal.net , the 404 error mod they made was called diserror.
I was just playing with my version to see if it still worked and it does.
I dont use it at this moment cause a general 404 is used now...
First you dont need to put in your whole url in the htaccess file.
I dont know how your code is put together but you have to make sure that all the info it grabs from the visitor is passed on to the module before the actual nukecode starts,so it probably goes in the module at the very start.
im not sure about your code,for example....mine starts at the very beginning right after the mainfile is included cause i grab the user id along with it as well so i can show him or her that he is recognized as well.
then i get all info maild,including all requests the person made. |
|
|
|
 |
Darrell3831

|
Posted:
Wed Feb 01, 2006 6:31 pm |
|
I guess I have a lot more studying to do.. I don't yet understand..
No matter where I put it in the module it still dosent work.
This is what I have so far, just experimenting with it..
Code:if ($notify_admin==1) {
$subject = "404 Error Report";
$mailheaders = "From: $from\n";
$mailheaders .= "Reply-To: $to\n\n";
$ip = $_SERVER['REMOTE_ADDR'];
$requri = $_SERVER['REQUEST_URI'];
$servname = $_SERVER['SERVER_NAME'];
$httpref = $_SERVER['HTTP_REFERER'];
$httpagent = $_SERVER['HTTP_USER_AGENT'];
$combine = "IP: ". $ip . " tried to load " . $servname . $requri ;
$today = date("D M j Y g:i:s a T");
$message = "$today \n
$combine \n
User Agent = $httpagent \n
$httpref \n
"._404_TURNOFF."\n";
mail($to, $subject, $message, $mailheaders);
}
|
|
|
|
|
 |
hitwalker

|
Posted:
Wed Feb 01, 2006 6:37 pm |
|
well thats how i got it working ...trying,playing,trying....
this is the part that grabs all the info...
here starts include mainfile
cookiedecode($user);
$username = $cookie[1];
if ($username == "") {
$username = "Guest";
}
$ip = getenv ("REMOTE_ADDR");
$requri = getenv ("REQUEST_URI");
$servname = getenv ("SERVER_NAME");
$httpref = getenv ("HTTP_REFERER");
$httpagent = getenv ("HTTP_USER_AGENT");
$combine = $ip . " tried to load " . $requri ;
$today = date("D M j Y g:i:s a T");
and this part basicly builds the mail report..
$to = "you@yoursite.com";
$subject = "root Error ";
$from = "From: admin@yoursite.com\r\n";
mail($to, $subject, $message2, $from);
echo $message; |
|
|
|
 |
hitwalker

|
Posted:
Wed Feb 01, 2006 6:38 pm |
|
just experiment a litle....you will get it fixed...  |
|
|
|
 |
|