oelna / microblog

A simple-ish PHP app that stores status updates as small posts in a SQLite database.
MIT License
55 stars 7 forks source link

Can't manage to run on Localhost (Mamp) #25

Open foxnoodles opened 1 year ago

foxnoodles commented 1 year ago

@oelna I'm getting too many redirects error.

DB file was automatically created so at least it ran through some of it.

.htaccess looks like this. I've only added RewriteCond %{SERVER_PORT} 8888. because the default url for mamp is localhost:8888 but the error persists even without my line.

AddCharset UTF-8 .xml
AddCharset UTF-8 .json

AddType application/atom+xml .xml
AddType application/json .json

<Files ~ "\.db$">
  <IfModule !mod_authz_core.c>
    Order allow,deny
    Deny from all
  </IfModule>
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /microblog

# friendly URLs
RewriteRule ^feed/json/?$ feed/feed.json [L]
RewriteRule ^feed/atom/?$ feed/feed.xml [L]

RewriteCond %{SERVER_PORT} 8888
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
</IfModule>

Error log says: RewriteCond: bad flag delimiters

Any ideas?

foxnoodles commented 1 year ago

Hello?

oelna commented 1 year ago

I'm sorry, I can't really look into this right now. You could try removing (or commenting out) all of the htaccess, to see if it runs, and add the lines back in one by one, which is what I would do. I don't have a MAMP setup right now, but I'll leave this issue open. In case you find out what caused the issue, I'll gladly update the htaccess to reflect your changes. Sorry I can't be of more help right now. I'll look into it when I can.

foxnoodles commented 1 year ago

Found it. templates/timeline.inc.php line 18 to 21 causes redirect loop. For some reason there is a check to redirect to home page if there are no posts. That obviously causes a loop.

if(empty($posts)) {
        header('Location: '.$config['url']);
        die();
    }
oelna commented 1 year ago

Ah, thanks for the info though. This looks like a much more reasonable change to take on. I guess the initial setup process has not been revisited for a while now. I'll keep it in mind!

foxnoodles commented 1 year ago

No probs! Also, I'm having problems with login/logout on Mamp. For som reason it does not want to set/unset the cookie time. The it out of the sudden logges in but does not want to logout. Weird. I've checked the cookie value and it somehow gets stuck. No idea why. Checked PHP setup and there's nothing out of the ordinary.

foxnoodles commented 1 year ago

Ok I've figured that one out as well. FYI Cookie does not get set because of this check (found in 3 files) $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;

localhost should be edited to match your setup. in my case it was localhost:8888

ivan-avalos commented 1 year ago

Ok I've figured that one out as well. FYI Cookie does not get set because of this check (found in 3 files) $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;

localhost should be edited to match your setup. in my case it was localhost:8888

It should be changed to:

$domain = ($_SERVER['SERVER_NAME'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;