template system.. rewrite/substr

Post here is you are having problems with any of the tutorials.
Post Reply
cordac
Posts: 3
Joined: Fri Sep 23, 2011 11:59 am
Location: Sweden, Norrköping

template system.. rewrite/substr

Post by cordac »

Hi

First of all, just wanna say thanks for creating a site that ppl with no skills whatsoever can understand!

Now. As the newb i am i have some issues trying to add a news-script i downloaded to the basic template system im using from this site.
I've searched but i didn't find anything(dont really know what i exactly should search for, but i tried).
I will learn this sometime, but atm i'm helpin a friend starting his site and can't solve this quickly.

I also did the redirect in my root folder:
DirectoryIndex index.html index.php index2.php
RewriteRule ^([a-zA-Z_]+)/?$ index2.php?page=$1 [QSA]
RewriteRule ^([a-zA-Z_]+)/?$ index.php?page=$1 [QSA]

Ok, so the problem..
Basicly, i get to the page where it lists the headlines of the posts error-free.
Hovering the link shows "http://www.url.se/index2.php?a=1" and thats my problem, wich i think is cause the rewrites and cause i use:
if (empty($_GET['page'])){
	header('Location: home');
	die();
}
$core_path = dirname(__FILE__);

$pages = scandir("{$core_path}/pages");
unset($pages[0], $pages[1]);

foreach ($pages as &$page){
	$page = substr($page, 0, strpos($page, '.'));
}

if (in_array($_GET['page'], $pages)){
	$include_file = "{$core_path}/pages/{$_GET['page']}.inc.php";
} else {
	$include_file = "{$core_path}/pages/home.inc.php";
}
This is the $_GET['page']
 else if ($_GET['page'] == "news"){
	$contact = 'aButton';
	$headline = 'Nytt hos oss';
}
($contact & $headline is for css and title)

I hope you understood my question(english isn't my native lang(doh)) and thanks for any help with my question.
goin php slowstyle, but gettin there.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: template system.. rewrite/substr

Post by jacek »

The rules you have will make any url like http://url.com/thing/ be the same as http://url.com/index2.php?page=thing if you browser to http://url.com/index2.php?page=thing it will still work as normal. I'm not really sure I understand your problem, can you explain a bit more ? If it's just that the topic headers show the wrong link, you just need to update the html on the page to use the nice link :)
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: template system.. rewrite/substr

Post by jacek »

cordac wrote:I really dont know how to get around this..
http://www.sfsc.se/news

thats the url for listing headlines.. when i click the link i get to the start again =)
The links point to a location that does not have a page variable in the URL, and since you have
if (empty($_GET['page'])){
        header('Location: home');
        die();
}
You get redirected to home.
Image
cordac
Posts: 3
Joined: Fri Sep 23, 2011 11:59 am
Location: Sweden, Norrköping

Re: template system.. rewrite/substr

Post by cordac »

jacek wrote:
cordac wrote:I really dont know how to get around this..
http://www.sfsc.se/news

thats the url for listing headlines.. when i click the link i get to the start again =)
The links point to a location that does not have a page variable in the URL, and since you have
if (empty($_GET['page'])){
        header('Location: home');
        die();
}
You get redirected to home.
Ok.. Is there a "easy" way to fix that? Atm, im really ill(cold with a big touch of dizzyness from time to time) and its seems i figure it out on my own :S(my brain goes syntax error when i try to think about php ;) )
goin php slowstyle, but gettin there.
cordac
Posts: 3
Joined: Fri Sep 23, 2011 11:59 am
Location: Sweden, Norrköping

Re: template system.. rewrite/substr

Post by cordac »

Ohh.. btw.. i think it gets the value.. it was just not posted by me.. this is my init file..
<?php

if (empty($_GET['page'])){
	header('Location: home');
	die();
}
$core_path = dirname(__FILE__);

$pages = scandir("{$core_path}/pages");
unset($pages[0], $pages[1]);

foreach ($pages as &$page){
	$page = substr($page, 0, strpos($page, '.'));
}

if (in_array($_GET['page'], $pages)){
	$include_file = "{$core_path}/pages/{$_GET['page']}.inc.php";
} else {
	$include_file = "{$core_path}/pages/home.inc.php";
}
// button default state
$index = "button";
$location = "button";
$about = "button";
$services = "button";
$contact = "button";
$news = "button";

// page gets the (css)value of aButton to make your current location visible 
if ($_GET['page'] == "home"){
	$index = 'aButton';
	$headline = 'Välkomna till Strömsfors Service Centers Hemsida';
} else if ($_GET['page'] == "location"){
	$location = 'aButton';
	$headline = 'Här kan ni hitta oss';
} else if ($_GET['page'] == "about"){
	$about = 'aButton';
	$headline = 'Detta är Strömsfors Servicecenter';
} else if ($_GET['page'] == "services"){
	$services = 'aButton';
	$headline = 'Här hittar ni våra tjänster';
} else if ($_GET['page'] == "contact"){
	$contact = 'aButton';
	$headline = 'Kontakta oss på Strömsfors Service Center';
} else if ($_GET['page'] == "news"){
	$news = 'aButton';
	$headline = 'nyheter';
}

?>
goin php slowstyle, but gettin there.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: template system.. rewrite/substr

Post by jacek »

You need to make the links include a page variable, so insead of http://www.sfsc.se/news?a=3 you want http://www.sfsc.se/news?page=news&a=3
Image
Post Reply