thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Clean URLs error FIX #101

Open creptor opened 9 years ago

creptor commented 9 years ago

This issue is common so I'll bring some steps on how to fix it. First of all, some notes:

NOTES:

Guide:

<IfModule mod_rewrite.c>
    RewriteEngine On
    Options -Indexes
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
function get_path(){
  $path = array();
  if(isset($_SERVER['REQUEST_URI'])){
    $request_path = explode('?', $_SERVER['REQUEST_URI']);
    $path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/');
    $path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
    $path['call'] = utf8_decode($path['call_utf8']);
    if($path['call'] == basename($_SERVER['PHP_SELF'])){
      $path['call'] = '';
    }
    $path['call_parts'] = explode('/', $path['call']);
    $path['query_utf8'] = urldecode($request_path[1]);
    $path['query'] = utf8_decode(urldecode($request_path[1]));
    $vars = explode('&', $path['query']);
    foreach($vars as $var){
      $t = explode('=', $var);
      $path['query_vars'][$t[0]] = $t[1];
    }
  }
return $path;
}
include('config/connection.php');
include('functions/sandbox.php');
include('functions/data.php');
$path = get_path();
$page = data_post($dbc, $path['call_parts'][0]);
$view = data_post_type($dbc, $page['type']);
if(!isset($path['call_parts'][0]) || $path['call_parts'][0] == '' ) {
    header('Location: home');
}

If you clomplete this task, the cleans urls should now work, if they work but you don't see the page, then check the index.php, it should have this <?php include('views/'.$view['name'].'.php');?> and your data.php (inside functions) should have this:

function data_post_type($dbc, $id){
    $stmt = $dbc->query("SELECT * FROM post_types WHERE id = $id");
    $data = $stmt->fetch_assoc();
    return $data;
}
function data_post($dbc, $id){
    if(is_numeric($id)){
        $stmt = $dbc->prepare('SELECT * FROM posts WHERE id = ?');
        $stmt->bind_param('i', $id);
    }else{
        $stmt = $dbc->prepare('SELECT * FROM posts WHERE slug = ?');
        $stmt->bind_param('s', $id);
    }
    $stmt->execute();
    $res = $stmt->get_result();
    $data = $res->fetch_assoc();
    $data['body_nohtml'] = strip_tags($data['body']);
    if($data['body'] == $data['body_nohtml']){
        $data['body_formatted'] = '<p>'.$data['body'].'</p>';
    }else{
        $data['body_formatted'] = $data['body'];    
    }
    return $data;
}

NOTE: If is still not showing up, check that your database has the table post (for the pages) and post_types (for the page types), if not add them or remane the ones you have. Create a new issue if you have any problems

creptor commented 9 years ago

Sry I made an mistake. I fixed this post for the wamp users.

Chriswilldo commented 9 years ago

Ok so installed the new xampp but I messed it up. How do you properly install it? Because I uninstalled the old one and installed the new one after but it still had the original xampp folder so i called the new one xampp new. Afterwards I pasted my website folder from the old htdocs and put it in the new htdocs. Now this shows up when I try to open my website: new xammp

thedigicraft commented 9 years ago

You need to make sure you give your mysql user the correct permission to use the database.

Chriswilldo commented 9 years ago

sigh.. I'm gonna have to rebuild my mysqli again from scratch. It seems that I may have deleted it when trying to install the new xampp :'|. It's my fault. i should of asked on how to properly install it first

Chriswilldo commented 9 years ago

You know what, I'm just gonna start over. Because i can't figure out what to do here and I'd rather just have a fresh start. Plus I forgot how to do a lot of things so redoing everything will help me remember. I'm gonna try my best to finish to redo it in a week or two.

creptor commented 9 years ago

@Chriswilldo maybe you should try to use your root user. It's literally named 'root' by default and there shouldn't be any problems in localhost things :smile:, also it should work with other users, but in localhost you shouldn't have problems with that. So the dbconnection file should be like this:

<?php
    //database connection info:
    $host = "127.0.0.1";//or localhost ,either should work
    $database = "{DB TABLE NAME HERE}";
    $user = "root";
    $password = "";
    $dbc = mysqli_connect($host, $user, $password, $database) or die(' An error ocurred when contacting the database, please try again.');
?>