I have trouble with my php/html/mysql cms - php

I have some trouble with my cms. (My own cms)
If I write www.example.com/example It works fine but if I write www.example.com/example/ the /example's content dosent show. Only the header, navigationbare, sidebar and footer shows up.
I need to write php code in site_content (In the mysql table) currently I can only write html)
It seems that google's spiders cant find my pages. Any way I can create a sitemap for google (The sitemap needs to get updated automaticaly when I add a new page in the mysql table (sites)
Structure of mysql
DataBase: website
Table: Sites
site_id
site_link
site_title
site_content
My index.php
<html>
<?php
include_once 'includes/mysqlconnect.php';
$url=$_SERVER['REQUEST_URI'];
$query = mysql_query("SELECT * FROM sites WHERE site_link = '$url' OR site_link = '$url/'");
WHILE($rows = mysql_fetch_array($query)):
$site_id = $rows['site_id'];
$site_link = $rows['site_link'];
$site_title = $rows['site_title'];
$site_template = $rows['site_template'];
$site_content = $rows['site_content'];
endwhile;
?>
<head>
<meta charset="UTF-8">
<title>KasCraft | <?php echo $site_title;?></title>
<LINK rel="stylesheet" type="text/css" href="http://kascraft.com/themes/default.css">
</head>
<body class="body">
<div class="container-all">
<div><?php include_once 'includes/header.php';?>
</div>
<div class="container">
<div><?php include_once 'includes/navigationbar.php';?></div>
<div><?php include_once 'includes/rightsidebar.php';?></div>
<div class="content">
<?php echo $site_content;?>
</div>
<div>
<?php include_once 'includes/footer.php'; ?>
</div>
</div>
</div>
</body>
</html>
And my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Can anybody please help me??

It could be that your .htaccess is only looking at the root directory of the site. /example/ is a new directory. I use a similar script that does include subdirectories, maybe you can use this:
RewriteEngine On
#In case of these folder, halt and don't continue.
RewriteRule ^(images|javascripts|styles)($|/) - [L]
#In every other case (exept these extentions) open index.php.
RewriteRule !.(gif|htm|html|ico|jpg|jpeg|js|png|txt|xml)$ index.php
With 'write php code' I assume you mean saving php code to the database? That works in the same way as saving html code. However when you're loading it from the database again you can choose to display it as text or execute it as PHP code using eval(). Personally I'd look at including templates in PHP. Have a look at this: https://stackoverflow.com/a/19603372/3079918
How long ago did you submit your website? It can take a few weeks before Google picks it up. If you really need a sitemap, build a script that will load your pages from the database and build them into a .xml file. Have a look at http://www.google.com/webmasters/ on how to submit the sitemap to Google.

Related

Friendly URLs htaccess and php

hello stackoverflow community hopefully you understand what im trying to do
im working with pretty URLs with htaccess and php and i have seen in some pages that in the URL appear the title of the news something like...
http://www.samplePage.com/news/killer-shooter-in-new-york
i would like to know how i do that , im not that good in htaccess or friendly URLs but i try to do my best and this is the way that im doing it....
my .htaccess
Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9/]+)$ index.php?view=$1
my html
//after the header label i add this to include the content
<?php
if (isset($_GET["view"])) {
$view=explode("/",$_GET["view"]);
include"modules/".$view[0]."-view.php";
}else{
include"modules/home-view.php";
}
?>
now i got these links that take me to the news
<ul class="row news-list">
<?php $sql=$con->query("SELECT * FROM latest_news LIMIT 4");
while ($row=$sql->fetch_array()) { ?>
//note: the URLSERVER is the route for example http://localhost/projectNews/
<li class="grid_6">
<?php echo $row['post_title']?>
</li>
<?php } ?>
</ul>
the ouput of this is http://localhost/projectNews/news/4/
once i click the link what i would like to do is to add the title of the new after the id of the news like i explained before for example...
http://localhost/project/news/4/killer-shooter-in-new-york
can someone of you guys help me please? im a little bit of new on this, thanks!

SEO URL with multiple files.php

I have many hours trying to find the solution here but none looks like what I'm looking for ... I will give a long explanation and possibly someone will serve you what I have and not need to change it.
Table pages
Table products
File .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?route=$1&url=$2 [NC,L]
If I put in the browser: example.com/pages/contact
really we are in: example.com/pages.php?route=pages&url=contact
In the file pages.php
<?php require_once 'inc/header.php'; ?>
<section>
<div class="container">
<div class="row">
<?php
$route= $_GET["route"];
$url = $_GET["url"];
$results = DB::query("SELECT * FROM $route WHERE url='$url'");
foreach ($results as $row) { ?>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h2><?php echo $row['name']; ?></h2>
</div>
<?php } ?>
</div>
</div>
</section>
<?php require_once 'inc/footer.php'; ?>
The same goes for products.php, is the same code as all get by _GET
The problem I have:
I want to eliminate the $route in the URL, I want the URL looks like this:
example.com/contact or example.com/acer-one
Is how to do this, if the two designs are identical, ie, put everything in index.php, the problem is I need to use the two files to display a design or another.
Where do I begin? I modified it? It is a project I'm starting from scratch, so I can change anything.
Have a look at the following example structure:
Start by adding a table "routes" that just contains each possible url, along with a type (and every field that both pages and products have in common). This would also mean you can remove the url column (and the other common columns) from the pages and products table (or perhaps remove the table all together, if no relevant data is left). Something like this:
TABLE routes
id route type name
1 contact page Contact
2 acer1 product Acer 1
Add your main controller, probably index.php, that looks something like this:
<?php
$url = isset($_GET["url"]) ? $_GET["url"] : 'home';
// you should probably use prepared statements here, but that is a different topic
$result = DB::query("SELECT * FROM routes WHERE url='$url'" LIMIT 1);
if (! $result) {
// 404
}
// any other common logic can go here, like header and stuff
require_once 'inc/header.php';
// now load the type specific page
include $result['type'] . '.php';
// and continue with the shared logic
require_once 'inc/footer.php';
Change your .htaccess to send everything to index.php
RewriteRule ^(.*)$ index.php?url=$1 [NC,L]
Now you only need a single path element and no type in the url. And you could add a page with url home for when no path elements are provided. Plus you have the possibility to still work with deep links 'my/awesome/deep/linked/page', all you have to do as add that url to your routes table. Inventing a new page type would be very easy as well, just add a 'my-new-type.php' file for the custom logic and you are set.
The key is to have a single point of entry into your application, a so called frontcontroller. And keep your code DRY, Don't Repeat Yourself.

Changing address bar via htaccess

I want to change my address bar via htaccess.
My link is: http://englishforyou.ir/index.php?content=about
And I want to change it to http://englishforyou.ir/content/about.My htaccess code is:
RewriteEngine on <br>
RewriteRule ^content/([A-Za-z0-9-]+)/?$ index.php?content=$1 [NC]
But it doesn't work. You can test it here: englishforyou.ir
My index file is:
<?php
require_once 'includes/function.php';
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div>
test
About me
</div>
<?php loadContent('content', 'mainpage'); ?>
</body>
</html>
My function file is:
function loadContent($where, $default='') {
// Get the content from the url
// Sanitize it for security reasons
$content = filter_input(INPUT_GET, $where, FILTER_SANITIZE_STRING);
$default = filter_var($default, FILTER_SANITIZE_STRING);
// If there wasn't anything on the url, then use the default
$content = (empty($content)) ? $default : $content;
// If you found have content, then get it and pass it back
if ($content) {
// sanitize the data to prevent hacking.
$html = include $content.'.php';
return $html;
}
}
And my about me file is:
<div>
<h4>
This page is about me.
home
</h4>
</div>
Your .htaccess file is right and it is working.
You might have to refresh your browser without cache, or wait for it to refresh by itself.
If you are using Firefox or Chrome, use Ctrl+F5 to refresh overriding the cache.
Note: You just have to use the url http://englishforyou.ir/content/about instead of http://englishforyou.ir/index.php?content=about
EDIT
Add this line to your .htaccess to redirect from http://englishforyou.ir/index.php?content=about to http://englishforyou.ir/content/about
RewriteRule ^index\.php\?content\=(.*)$ /content/$1 [R=301,L]
Try something like this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.* - [L]
RewriteRule ^system/([^/]*)\.html$ system.php?route=$1
This translates the url http://www.domain.com/system/home.html to http://www.domain.com/system.php?route=home
And make sure you are allowed to use .htaccess

View master layout not found

I'm new in laravel. However, I'm created blade templates and integrate with my offline index webpage. It consists of signin.html and signout.html. So below is the structure way of managing my files:
-views
--account
---signin.blade.php
---signup.blade.php
--includes
---head.blade.php
---footer.blade.php
--layouts
---master.blade.php
--home.blade.php
Home.blade.php
#extends('layouts.master');
Master.blade.php
<!DOCTYPE html>
<html>
<head>
#include('includes.head');
</head>
<body class="bg-info">
<!-- #include('includes.navigation'); -->
<!-- #extends('account.signin'); -->
<!-- #yield('content') -->
<!-- #yield('content') -->
#include('includes.footer');
</body>
</html>
The following two files will output the signin form in the page. I have no idea how they get into it. I didn't include anything. My public folder :
--assets
---css
---fonts
---images
---js
--index.php
--.htacess
Index.php
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
$app->run();
$app->shutdown();
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Route
Route::get('/', array (
'as' => 'home',
'uses' => 'HomeController#home'
));
Home Controller
public function home() {
return View::make('home');
}
Now if I'm open-up my localhost, View [includes.master] not found. Perhaps my storage folder still contains the template codes, but I tried to delete, it keep generate a new one.
Another problem is when I adding #extends('includes.master') into signin.blade.php or singup.blade.php at the top.
The localhost and localhost/account/signin or localhost/account/register will be Internal Server Error: 500 .
Well, Let me tell you something. What's the need to include your header from an external folder? Please follow this, your master layout should be like this:
<!DOCTYPE html>
<html>
<head>
//put your codes here , not the include function
</head>
<body class="bg-info">
#include('includes.navigation');
#extends('account.signin');
#yield('content')
#include('includes.footer');
</body>
</html>
home.blade.php should be like this:
#extends(layouts.master)
#section('content')
<p> Hello, this works </p>
#stop
Now let me if you need any further help.
Check views folder permissions. In my case there was a problem.
For this folder and all the files inside permissions should be 755.
Had the same issue, think that has something to do with blades caching of the view dir. I fixed it by changing the #extends(example.master) to another template and then back to wanted path. Worked without doing anything else, but as always first try php artisan view:clear.
Greets, Pat

Displaying dynamic content based on browser location

I had an idea of writing a page template in my index.php where the content section of the page will include the content dynamically by determining what url the browser is at and getting the content page based on that. There's a few issues though:
<?php
// /index.php
?>
<!-- html tags and menu/layout divs as needed go here -->
<section id="content">
<?php
function curPageURL()
{
$page = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
return $page;
}
$page = curPageURL();
switch ($page)
{
case "index.php":
include_once("includes/home.php");
break;
}
?>
</section>
<!-- footer and such goes here -->
Although this works, I'm having trouble applying the concept further. I just can't seem to get my head around how the navigation should work or how to apply this concept to other pages in my site...
If anyone can advise, I'd really appreciate it.
You could use a .htaccess file (put in the same directory as index.php).
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [L,QSA]
And then in index.php you can get the page with:
$page = $_GET['uri'];
So if you user goes to example.com/home then the page variable will be set to home.

Categories