Jump to content

My included files are be affected by mod rewrite.


psymonic

Recommended Posts

Hello all,

 

Im going to post my .htaccess file here first so i can refer to it:

 

<IfModule mod_rewrite.c>

  RewriteEngine on

  RewriteCond %{REQUEST_FILENAME} !-f

  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

</IfModule>

 

A friend made this for me so im not really sure how it works or if this will be a simple fix.

 

The idea was for users to be able to go to say domain.com/register and this will send  a request to domain.com/index.php?page=register. Ok that all work fine. This thread title isn't 100% clear, i can  safely include files without calling multiple headers. But my problem is, that i have created a script which creates a captcha image. Say the script is called image.php. Inside the image.php script I created a session called $_SESSION['image']. Now to load the captcha image i use the line

 

<img src="image" alt="captcha" />

 

There is no .php becuase its not required due to the .htaccess.

 

So that loads the image successfully bujt when i put directly after that line

<?php echo $_SESSION['image']; ?>

 

The session has no value.

 

The crazy thing is if reload the pagethe session does exists. But instead of display a new session value (because a new captcha image has been created for that page), it displays the previous page session value.

 

Its almost as if, the session is not actually set until the end of the script is reached. which is very strange because my other sessions do not do this that are inside the script or that are created in included files.

 

I have also tried 1 more test, that would back up the idea of the script not running untill the end, which is:

 

in image.php i wrote content to a file and then on the main page used echo to display the content of the file and it did not display anything, however i checked the content of the file manually and it was there.

 

I would say im 99.9% sure this is due to the .htaccess file. Ive created many captcha system in the past but only one with this mod rewrite and its the only one i havent got working.

 

Sorry for my long post I was trying to be as specific as possible. If anyone know what may be causing this problem and can help me out then I will extremely greatful. If you need any more information then please ask and I will reply ASAP.

 

Thank You

Simon

 

 

 

Link to comment
Share on other sites

With the default "files" session handling, PHP loads the file and parses it into the SESSION superglobal at the beginning of the script.

 

 

So, then, at the end of the script (or when ever the content gets flushed to the browser), the client is making a second, unrelated request to the CAPTCHA image.  So, it's kind of impossible for PHP to know something is there when it hasn't been set yet.

Link to comment
Share on other sites

Thanks for your reply corbin,

 

Do you not think this is a mod rewrite issue? Ive worked on with PHP for 3-4 years now and have been used this same method to create captcha images for atleast 2 years and without mod rewrites it works perfectly every time. From my experience i have noticed that if you create a session on line 1 you should be able to access it in line 2 unlike cookies which cannot be accessed until the next page load.

 

I think I understand what your saying, but im sure with PHP if you call another script into the script your using, it will make the request then and there, it has to otherwise you wouldn't be able to access variables etc with have been set in a header for example.

 

I still feel strongly that this is a mod rewrite problem. If you or anyone else has any more ideas for a possible fix then Ill be extremely happy to hear them.

 

Thank You

Simon

Link to comment
Share on other sites

Hmmm,

 

As far as I am aware it should not matter if the session is set in an included file or one called thought the image source. I have used captcha scripts in the exact same way many times in the past but have never encountered this problem so surely it can't be a problem that the session is being set in a seperate request.

Link to comment
Share on other sites

Hey

 

I have fixed the problem, you were right corbin it was not a .htaccess error. Im totally gutted i wasted so much time on a stupid mistake, I really need to learn to take regular breaks. A fresh mind today and I found the problem in under 5 minutes.

 

The problem, on my old sites I always used capital letters on the captcha image and then convert whatever the user enter into upper case, but I decided this time to use a function i created to generate a random string, upper, lower and nums. I totally forgot about this and the font I am using looks the same in upper and lower case. So it all works now when I convert the captcha text and the user entered data to upper case.

 

If there is one thing I've learned from this its to have a break if you can't fix something with an hour or so, I just find it so hard to leave something which isn't working.

 

Well thanks for your time and advise corbin it is very much appreciated. Your a top guy.

 

Best Regards

Simon

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.