Jump to content

$_GET returns wrong vars


Dudditz

Recommended Posts

I recently moved a small script from a server with php5.2.4 to one with php5.2.5

and certain areas have stopped working.

After some debugging I went back to square one and set up 2 files as follows:

.htaccess

RewriteEngine On
RewriteRule ^(.+)/(.+)/(.+).png /image.php?type=$1&style=$2&tag=$3

image.php

<?php
echo $_GET['type'];
?>

 

For some reason, the type will add a file extension if there is a file name existing in the directory

threrfore returning the wrong data to my script.

If there is no file by the type it will display properly.

example: if $_GET['type'] is image in the url mydomain.wer/image/some/picture.png

            the $_GET will return image.php instead of image since there exists an image.php file in directory.

 

Its like the server is searching the directory for a file by that name instead of just returning the url part like its supposed to.

Does anyone know why this is happening?

thanks

 

Link to comment
Share on other sites

I am not that a big regexp expert.

Try first to see the phpinfo() difference on these 2 webservers (previous and new one).

Also try

RewriteRule ^(.+)/(.+)/(.+)\.png /image.php?type=$1&style=$2&tag=$3

instead of

RewriteRule ^(.+)/(.+)/(.+).png /image.php?type=$1&style=$2&tag=$3

Link to comment
Share on other sites

I am not that a big regexp expert.

Try first to see the phpinfo() difference on these 2 webservers (previous and new one).

Also try

RewriteRule ^(.+)/(.+)/(.+)\.png /image.php?type=$1&style=$2&tag=$3

instead of

RewriteRule ^(.+)/(.+)/(.+).png /image.php?type=$1&style=$2&tag=$3

 

I'll look into the php differences but the RewriteRule change did not solve the issue.

For now, I have simply renamed the image.php to image1.php and it works

When I echo $_GET['type']; with any name in that url location that has the same name of a file within the directory,

it will echo the filename instead of the $_GET from url.

If I put example in the url, it will echo example until I create an example.ext in which it will then echo example.ext

Driving me nuts but I will rename filenames for temporary measure.

Link to comment
Share on other sites

You might want to apply a rewrite condition:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/(.+)/(.+)\.png /image.php?type=$1&style=$2&tag=$3

Also it may because you're using (.+) which I believe is greedy. What you should do is use character ranges:

 

Full code

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)/([a-z]+)/([a-z]+)\.png$ /image.php?type=$1&style=$2&tag=$3 [NC]

 

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.