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.
Related
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!
I am trying to open a page on clicking on a link in my codeigniter application. This is the snippet of my attempt
at the controller level this is snippet
//load return policy
function returnpolicy()
{
$this->load->view("return_policy");
}
at the view level this is the snippet
<div class="toggle">
Return Policy
</div>
on clicking on the link it does not navigate to the page. please what am I missing. am new to codeigniter
You should understand the difference between site_url and base_url first
echo base_url(); // http://example.com/website
echo site_url(); // http://example.com/website/index.php
You can rewrite it as follows :
<?php echo site_url('controller/method');?>
In HMVC
<?php echo site_url('module/controller/method');?>
So in your case
Return Policy
you can use the URL helper this way to generate an <a> tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('gotopolicy/returnpolicy', 'Return Policy', 'class="toggle-title"') ?>
Possible issue could be of htaccess,
create a file .htaccess in your root CI folder
and add below contents to it
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Make $config['index_page'] = "";
try to remove class="toggle-title"
or try this
<div >
Return Policy
</div>
I have a menu like:
<ul>
<li>Home</li>
<li>Contect</li>
<li>References</li>
</ul>
And i would like to tell that the / use home.php, the /contact get method use the contact.php and the /references use the references.php and of course th active class also change when we are at the contact menupoint and so on....
Thanks for the help! Im new with php sorr..
Easiest way to do it:
create a file with a name .htaccess
RewriteEngine on
RewriteRule ^/([^/\.]+)/?$ index.php?page=$1 [L]
if your files are under another folder like `includes/contact.php``
RewriteEngine on
RewriteRule ^/includes/([^/\.]+)/?$ index.php?page=$1 [L]
getting your page via 'GET' in your index.php
$page = $_GET['page']; //contact.php
and test:
Contact
I have made small script in php what it does is it gets the url and redirects it to another website only domain name changes rest of the url remains same
here is my code
.htacess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]
index.php
<?php
$url = 'http://justfun4funny.com/';
if (isset($_REQUEST['path']))
{
$url.=$_REQUEST['path'];
}
//var_dump($url);
header( "refresh:0;url=$url" ); ?>
<html>
Please wait while article is being loaded
<h1 style="color:blue;font-size:30"><a rel="canonical" href="<?php echo $url ?>">Click Here to Continue</a></h1>
<div style='display:none'>
<iframe src="<?php echo $url?>"></iframe>
</div>
</html>
the problem i am facing is when i paste this url on my facebook status
http://viralresort.com/2801
it reads all the data for website including image .
http://viralresort.com/2660
but the above url is not recognized by facebook it shows blank data
Hi try entering the URL into facebook Debugger.
https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fjustfun4funny.com%2F2660
You can also ask Facebook to fetch new information for any URL. I hope this helps.
The debugger is a handy URL, you should keep. Sometimes Information takes time to get cached into facebook. You can additionally add og:type tag to pass information to facebook.
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.