Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-13-2013, 11:28 PM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Backing up One Page is causing 404-Error

I am getting a really strange error that - for the life of me - I cannot track down...

Here is what is happening...

The user starts from his/her Inbox located here...

http://local.debbie/account/messages/incoming


The user click on a given Private Message in his/her Inbox and is taken to the PM to a URL similar to this...

http://local.debbie/account/view-pm/incoming/4


Next, the user decides he/she wants to back up to the Inbox, and so (on my Mac) chooses Command + Back-Arrow.


While the browser goes back one page to the Inbox, and everything loads just fine, in the background, the browser or my code is apparently throwing a 404-Error.

I know this because in my .htaccess file I have this code...

Code:
#Handle Page Not Found.
ErrorDocument 404 "/utilities/page-not-found.php"
...and that script is running which sends me an e-mail saying there was an issue.


Like a lot of things late in the game of developing my website, it is hard to troubleshoot if you don't have my entire code base, and yet I am hoping someone out there has seen something similar and may have som ideas of how to fix this?!

It would be a real bummer if I - as the Admin - get an e-mail every time someone backs up from a PM to their Inbox!!!!!

Any ideas??

Sincerely,


Debbie
doubledee is offline   Reply With Quote
Old 01-13-2013, 11:48 PM   PM User | #2
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Actually, it looks like the 404-Error may be occurring just when the PM page loads, versus backing up to it.


If I open up a new browser, and paste this in the Address Bar...

http://local.debbie/account/view-pm/incoming/4

...and hit <enter>, then I get an e-mailing saying there was a 404...


(I don't understand how a Page can load AND throw a 404-Error all at the same time?!)


Debbie
doubledee is offline   Reply With Quote
Old 01-14-2013, 03:07 AM   PM User | #3
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
I think I have the issue isolated, but still have no clue about what is wrong...

In my "view-pm.php" script which displays a Private Message, I have this snippet of code which builds the From: part of the message...

PHP Code:
    if ($msgView == 'incoming'){
        
$fromData "<a href='/account/profile/$fromUsername/about-me'>"
        
$fromUsername
        
"<img id='onlineStatus' src='/images/"
        
$fromMemberStatus[0]
        . 
"' width='10' alt='"
        
$fromMemberStatus[1]
        . 
"' /><br />"
        
"<img src='/uploads/"
        
$fromPhoto
        
"' width='80' />"
        
"</a>";

echo 
'$fromData = ' $fromData "<br />";
exit(); 

If I isolate this code, run the script, and view the output I get...

Code:
$fromData = <a href='/account/profile/username1/about-me'>username1<img id='onlineStatus' src='/images/Light_Gray_10.png' width='10' alt='Member Offline' /><br /><img src='/uploads/NoImage2_100x77.png' width='80' /></a><br />

Apparently this PHP and/or HTML is causing a 404-Error when my Private Message displays?!


What in the world is going on????


Debbie
doubledee is offline   Reply With Quote
Old 01-14-2013, 03:09 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That will ultimately come down to your rewrite rules. If I had to guess, one of them has a trailing / on it, and the rewrite engine either only handles it with the trailing front slash or doesn't handle it. One or the other would trigger an error since it is now looking for a directory which presumably doesn't exist.
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 03:10 AM   PM User | #5
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Quote:
Originally Posted by Fou-Lu View Post
That will ultimately come down to your rewrite rules. If I had to guess, one of them has a trailing / on it, and the rewrite engine either only handles it with the trailing front slash or doesn't handle it. One or the other would trigger an error since it is now looking for a directory which presumably doesn't exist.
Fou-Lu, did you see my latest post (i.e. Reply #3)??


Debbie
doubledee is offline   Reply With Quote
Old 01-14-2013, 03:18 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
And what is your question to go with that? It matches the output $from variable you have created.
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 03:32 AM   PM User | #7
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Quote:
Originally Posted by Fou-Lu View Post
And what is your question to go with that? It matches the output $from variable you have created.
I am wondering all the mod_rewrites I used - only a dozen really - are worth the trouble they can cause?!


Okay, I think I am making some progress thanks to your lead, so here is where I am stuck now...

In my Web Root I have a directory called "uploads" which holds Member's profile photos plus a png to handle if a photo is "pending approval" and one if the Member has no photo.

For whatever reason, I had the wrong filename in my code, and so I corrected below...
PHP Code:
    // Check for No Image.
    
if (is_null($fromPhoto)){
        
$fromPhoto "NoImageAvailable_100x77.png";
    }

    if (
is_null($toPhoto)){
        
$toPhoto "NoImageAvailable_100x77.png";
    } 

So, when I re-run my code with an exit() to isolate things, in View Source I see...

Code:
src='/uploads/NoImageAvailable_100x77.png'

If I type this in the URL I get a 404-Error...

local.debbie/uploads/NoImageAvailable_100x77.png


So to me that means that the HTML that is trying to display my "No Image Available" thumbnail is crashing things...


The best thing I can think, is that is very liberal mod_rewrite could be causing an issue...

Code:
#-------------------------------------------------------------------------------
#PRETTY:		finance/
#UGLY:			articles/index.php?section=finance

#Rewrite only if the request is not pointing to a real file (e.g. add-comment.php, index.php).
RewriteCond %{REQUEST_FILENAME} !-f

#Match any kind of Section.  PHP will decide if it's valid or not.
RewriteRule (.+)/$ articles/index.php?section=$1 [L]

Does that make sense??


Debbie
doubledee is offline   Reply With Quote
Old 01-14-2013, 03:36 AM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yeah, rewrites can cause havoc.

Are all of these rewrites like this? If so:
PHP Code:
RewriteRule (.+)/$ articles/index.php?section=$[L]
                ^ 
You require the / at the end of it. Without it it will consider it a directory.
Fou-Lu is offline   Reply With Quote
Old 01-14-2013, 03:50 AM   PM User | #9
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Quote:
Originally Posted by Fou-Lu View Post
Yeah, rewrites can cause havoc.
This is madness!!!

I think I figured out the culprit...

For some reason in my code I originally had...
Code:
$fromPhoto = "NoImage2_100x77.png";

Then I thought I noticed it should be...
Code:
$fromPhoto = "NoImageAvailable_100x76.png";

And after more errors I looked again and noticed that I needed...
Code:
$fromPhoto = "NoImageAvailable_100x77.png";

WTF?!


Quote:
Originally Posted by Fou-Lu View Post
Are all of these rewrites like this? If so:
PHP Code:
RewriteRule (.+)/$ articles/index.php?section=$[L]
                ^ 
You require the / at the end of it. Without it it will consider it a directory.
No, I just have it like that in one place, which is probably a whole long discussion in itself...

For each "Article Section" in my website, which is a "navigation tab" and a landing page containing a summary of each Article, right or wrong, I adopted this format in the URL...

http://local.debbie/finance/

http://local.debbie/legal/

http://local.debbie/management/


To me, it seemed like a good idea at the time, because ending a URL with a slash denotes that you are looking into a directory, and I guess my "Finance Landing page" is a "directory" of sorts?!

It's much too late to change that for v2.0, but if you think my convention is a bad idea or misleading, I guess I could re-work it for v3.0

Suggestions?

Thanks,


Debbie
doubledee is offline   Reply With Quote
Old 01-14-2013, 04:26 AM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Your rewrite can just take /? on it to make it optional.
The source image paths are irrelevant. Unless its somehow matching your rewrite rules which is very easy to do. Your current rules only check to see if a file matches, otherwise it goes ahead and rewrites. Assuming the style is overall the same, not matching a filepath for an image would attempt to rewrite it. I wouldn't think that would cause a 404 on a page though; all that should do is show a broken image link since the image itself is a 404.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:37 PM.


Advertisement
Log in to turn off these ads.