Page 1 of 1

opening pages in one page

Posted: Tue Jul 07, 2009 9:16 am
by insight
I don't know how to explain this properly as I'm still noobish but I was wondering how I can get pages to open up in the index url.

For example, if I go to open a link instead of it being http://www.example.com/some/random/file/index.php it will open as http://www.example.com/index.php?file=randomfile or something along those lines.

And when I do this will the url commands in that random file work as say <a href="themes/sometheme/style.css"></a> or will I still have to type the ../../../themes/sometheme/style.css?

So far I've been using includes to include pages into a page (like include("includes/header.php") etc etc) but I'm having to constantly change the address for them to work (include("../../includes/header.php") etc).

Is there a way to open the pages in say one index page as explained above so I don't have to keep changing the details?

Any help would be greatly appreciated. I'm designing a new website and this would help me out a lot.

Re: opening pages in one page

Posted: Tue Jul 07, 2009 9:33 am
by peter162in
Your question is not clear.
for opening pages in index you can use frames
that is in HTML not in PHP

other wise in PHP try 'swicth' 'case'
something like this

switch($act)
{
case "home" :"index.php";
break;

case "login" :include("login.php");
break;
case "logout" :"index.php";
break;
case "register" :include("register_user.php");
break;
}

and use
<a href="index.php?act=login">< alt="login" " /></a></td>

Re: opening pages in one page

Posted: Tue Jul 07, 2009 9:42 am
by insight
peter162in wrote:snip!
Yes, sorry it's a little difficult to explain and I'm rather new to this. I'm not sure if iframes is what I'm looking for and I will look into the switches (actually saw it on tizag not so long ago). But I'll try to explain it a little better. What I'm after is this:

If I click on a link (say "Home" link) it will direct me to the home page which will be http://prodrift.exofire.net/index.php?file=News (<-- actual site, just using it as an example though). Now I understand the page is using includes, but the actual home page is located in http://prodrift.exofire.net/module/news/index.php. And if I view a comment on the page it will reload it and the new url will be http://prodrift.exofire.net/index.php?f ... news_id=15.

So all I need to do is use switches in the menu and it will open up the pages similar to this?

And damn your response was quick :D , I posted on two other forums a day ago and haven't got a response :cry:

Re: opening pages in one page

Posted: Tue Jul 07, 2009 10:26 am
by insight
Nobody has an answer? :(

Re: opening pages in one page

Posted: Tue Jul 07, 2009 12:19 pm
by Skara
I think what you're asking about is mod_rewrite.

If I understand you correctly..
This is what you want in the address bar:
http://prodrift.exofire.net/module/news/index.php
but this is what is what you actually want to load:
http://prodrift.exofire.net/index.php?file=News

This isn't related to php, really. Code your site as if http://prodrift.exofire.net/index.php?file=News is the only thing you have to worry about.

Then...
Edit your .htaccess file to rewrite your urls the way you want.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

I'm really bad at this, but this is something like what you'll want..

Code: Select all

RewriteEngine On
RewriteRule /module/(.*)/index\.php /index.php?file=$1 [L]
I might have gotten that wrong, but it's at least close.

Re: opening pages in one page

Posted: Tue Jul 07, 2009 9:22 pm
by insight
Skara wrote:I think what you're asking about is mod_rewrite.

If I understand you correctly..
This is what you want in the address bar:
http://prodrift.exofire.net/module/news/index.php
but this is what is what you actually want to load:
http://prodrift.exofire.net/index.php?file=News

This isn't related to php, really. Code your site as if http://prodrift.exofire.net/index.php?file=News is the only thing you have to worry about.

Then...
Edit your .htaccess file to rewrite your urls the way you want.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

I'm really bad at this, but this is something like what you'll want..

Code: Select all

RewriteEngine On
RewriteRule /module/(.*)/index\.php /index.php?file=$1 [L]
I might have gotten that wrong, but it's at least close.
lol no, but close. And in fact I believe I have it slightly wrong myself. The site I referenced has blocks and modules. Each block has it's own set of code. For example the menu block will contain details about the menu and will be included in all pages. The login block will contain login details (login scripts) to login and will be included. However the content area is a module and the one I linked is part of the news module. It's probably best if I draw up a picture so you can better understand :lol: .

OK here's a quick drawing:
Image

OK now the default webpage will be something like http://www.insight.atbhost.com/index.php and it will provide you with a webpage similar to the drawing above. Now when I click on a link in the menu bar it will reload the page and everything will remain the same except the contents area. For example, if I click on Link 2 it will reload the page and show the module Link 2 is linked to (http://www.insight.atbhost.com/modules/link-2/index.php) but in the address bar it will show http://www.insight.atbhost/index.php?file=link-2.

I hope that explained it a little better.

EDIT: What I mean is that I want the page to SHOW http://www.insight.atbhost.com/index.php?file=link-2. I believe link-2 will be the folder name so I'm guessing I will have to use something like $ModName = basename(dirname(__FILE__)); But don't know how to implement it into my script so the page will show index.php?file=lin-2.

Re: opening pages in one page

Posted: Tue Jul 07, 2009 10:36 pm
by Skara
Ok, I'm still not positive I understand what you want, but I think maybe... something like this setup?

Code: Select all

//stats.php:
display_stats(); //blah blah woof woof
//shoutbox.php:
display_shoutbox();
//news.php:
display_news();
//etc...
 
//------------------------------------------
 
//index.php:
//wrap it all in in a nice table and you're done:
require_once('stats.php');
require_once('shoutbox.php');
switch ($_GET['file']) {
    case 'news': require_once('news.php'); break;
    case 'link-2': require_once('link-2.php'); break;
 
    //or if you're talking about actually displaying a separate html page here that's already been parsed...
    case 'news': echo file_get_contents('http://www.insight.atbhost.com/modules/link-2/index.php'); break;
}
On an unrelated note, please don't use frames. They're seven ways deprecated. No one uses them because they're bad. :P If you really just want only a portion of a page to load, you can accomplish this through ajax.

Is that basically what you're wanting?

Re: opening pages in one page

Posted: Tue Jul 07, 2009 10:57 pm
by insight
Skara wrote:Ok, I'm still not positive I understand what you want, but I think maybe... something like this setup?

Code: Select all

//stats.php:
display_stats(); //blah blah woof woof
//shoutbox.php:
display_shoutbox();
//news.php:
display_news();
//etc...
 
//------------------------------------------
 
//index.php:
//wrap it all in in a nice table and you're done:
require_once('stats.php');
require_once('shoutbox.php');
switch ($_GET['file']) {
    case 'news': require_once('news.php'); break;
    case 'link-2': require_once('link-2.php'); break;
 
    //or if you're talking about actually displaying a separate html page here that's already been parsed...
    case 'news': echo file_get_contents('http://www.insight.atbhost.com/modules/link-2/index.php'); break;
}
On an unrelated note, please don't use frames. They're seven ways deprecated. No one uses them because they're bad. :P If you really just want only a portion of a page to load, you can accomplish this through ajax.

Is that basically what you're wanting?
Kinda. It would be awesome to make a website based of Ajax but the problem is that it would put a ton of strain on the server if I have a lot of users/visitors and I already plan to have an Ajax shoutbox installed. I honestly don't know how to explain it any better unfortunetely :( , but what I want is for when people click on a link in my website it will load the contents of the php file (html page or whatever you want to call it) from http://www.insight.atbhost.com/modules/link-2/index.php. But in the address bar it will show http://www.insight.atbhost.com/index.php?file=link-2, and if anybody want to visit that page by direct link then all they have to do is enter http://www.insight.atbhost.com/index.php?file=link-2 and it will automatically load the page with the contents from link-2/index.php.

I take it file_get_contents will do that then? if so then how can I make is so when someone clicks on a link it will reload the page with the contents from link-2/index.php into the contents area of the page?

But speaking of Ajax, if you don't have many users on the website will an Ajax based website put a lot of strain on the server? But come to think of it doesn't Ajax only get text from a file not load it's contents?

Re: opening pages in one page

Posted: Tue Jul 07, 2009 10:59 pm
by Skara
I'm not familiar with ajax. I've never had the need to use it.

With the code I gave you, you need simply to code the link as
<a href="?file=link-2">Link 2</a>

What am I missing? Why is this difficult?

Re: opening pages in one page

Posted: Tue Jul 07, 2009 11:41 pm
by insight
Skara wrote:I'm not familiar with ajax. I've never had the need to use it.

With the code I gave you, you need simply to code the link as
<a href="?file=link-2">Link 2</a>

What am I missing? Why is this difficult?
It probably isn't, infact it's probably easy, I'm just trying to understand it that's all. But the problem I see with your code is that I have to type ?file=link-2, it doesn't get the name from the folder which is what I want. If I change the name of the folder then I will have to change the name of the link. I would rather the link do it automatically.

For example in the modules/link-2/index.php I'll have something like this written in it:

Code: Select all

$ModName = basename(dirname(__FILE__));
Now if I echo that it will give me the name of the folder which is link-2

Now I add $ModName to the link and it will look something like:

Code: Select all

?file=$ModName
But this will be put in another index.php file altogether like includes/blocks/block_menu.php (block_menu.php being the block used for the menu which will contain links to different pages, all links will be stored in the database that way admins can easily create new links). Here let me get a couple pages so I can show you what I mean.

http://prodrift.exofire.net/includes/bl ... k_menu.php

Code: Select all

<?php 
// -------------------------------------------------------------------------//
// Nuked-KlaN - PHP Portal                                                  //
// http://www.nuked-klan.org                                                //
// -------------------------------------------------------------------------//
// This program is free software. you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License.           //
// -------------------------------------------------------------------------//
if (eregi("block_menu.php", $_SERVER['PHP_SELF']))
{
    die ("You cannot open this page directly");
} 
 
function affich_block_menu($blok)
{
    $blok['content'] = stripslashes(block_link($blok['content']));
    return $blok;
} 
 
function block_link($content)
{
    global $user;
 
    $link = explode('NEWLINE', $content);
    $screen = "<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
 
    foreach ($link as $link)
    {
        list($url, $title, $comment, $nivo, $blank) = explode('|', $link);
        $url = preg_replace("/\[(.*?)\]/si", "index.php?file=\\1", $url);
        $nivuser = $user[1];
        $title = stripslashes($title);
        $comment = stripslashes($comment);
        $title = htmlentities($title, ENT_NOQUOTES);
        $title = eregi_replace("<", "<", $title);
        $title = eregi_replace(">", ">", $title);
        $comment = htmlentities($comment);
    $url = htmlentities($url);
 
        if (!$nivuser)$nivuser = 0;
        if ($nivuser >= $nivo)
        {
            if ($url <> "" && $title <> "" && $blank == 0)
                $screen .= "<tr><td><a href=\"" . $url . "\" title=\"" . $comment . "\" style=\"padding-left: 10px;\" class=\"menu\">" . $title . "</a></td></tr>\n";
 
            if ($url <> "" && $title <> "" && $blank == 1)
                $screen .= "<tr><td><a href=\"" . $url . "\" title=\"" . $comment . "\" class=\"menu\" style=\"padding-left: 10px;\" onclick=\"window.open(this.href); return false;\">" . $title . "</a></td></tr>\n";
 
            if ($url == "" && $title <> "" && $comment == "")
                $screen .= "<tr><td><div style=\"padding-left: 20px;\" class=\"titlemenu\">" . $title . "</div></td></tr>\n";
        } 
    } 
    $screen .= "</table>\n";
    return $screen;
} 
 
function edit_block_menu($bid)
{
    global $nuked, $language;
 
    $sql = mysql_query("SELECT active, position, titre, module, content, type, nivo, page FROM " . BLOCK_TABLE . " WHERE bid = '" . $bid . "'");
    list($active, $position, $titre, $modul, $content, $type, $nivo, $pages) = mysql_fetch_array($sql);
    $titre = stripslashes($titre);
    $content = stripslashes($content);
    $titre = htmlentities($titre);
    $content = htmlentities($content);
 
    if ($active == 1) $checked1 = "selected=\"selected\"";
    else if ($active == 2) $checked2 = "selected=\"selected\"";
    else $checked0 = "selected=\"selected\"";
 
    echo "<a href=\"#\" onclick=\"javascript&#058;window.open('help/" . $language . "/block.html','Help','toolbar=0,location=0,directories=0,status=0,scrollbars=1,resizable=0,copyhistory=0,menuBar=0,width=350,height=300');return(false)\">\n"
    . "<img style=\"border: 0;\" src=\"help/help.gif\" alt=\"\" title=\"" . _HELP . "\" /></a><div style=\"text-align: center;\"><h3>" . _ADMINBLOCK . "</h3></div>\n"
    . "<form method=\"post\" action=\"index.php?file=Admin&page=block&op=modif_block\">\n"
    . "<table style=\"margin-left: auto;margin-right: auto;text-align: left;\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n"
    . "<tr><td><b>" . _TITLE . "</b></td><td><b>" . _BLOCK . "</b></td><td><b>" . _POSITION . "</b></td><td><b>" . _LEVEL . "</b></td></tr>\n"
    . "<tr><td align=\"center\"><input type=\"text\" name=\"titre\" size=\"40\" value=\"" . $titre . "\" /></td>\n"
    . "<td align=\"center\"><select name=\"active\">\n"
    . "<option value=\"1\" " . $checked1 . ">" . _LEFT . "</option>\n"
    . "<option value=\"2\" " . $checked2 . ">" . _RIGHT . "</option>\n"
    . "<option value=\"0\" " . $checked0 . ">" . _OFF . "</option></select></td>\n"
    . "<td align=\"center\"><input type=\"text\" name=\"position\" size=\"2\" value=\"" . $position . "\" /></td>\n"
    . "<td align=\"center\"><select name=\"nivo\"><option>" . $nivo . "</option>\n"
    . "<option>0</option>\n"
    . "<option>1</option>\n"
    . "<option>2</option>\n"
    . "<option>3</option>\n"
    . "<option>4</option>\n"
    . "<option>5</option>\n"
    . "<option>6</option>\n"
    . "<option>7</option>\n"
    . "<option>8</option>\n"
    . "<option>9</option></select></td></tr>\n"
    . "<tr><td colspan=\"4\" align=\"center\"><br /><input type=\"button\" value=\"" . _EDITMENU . "\" onclick=\"javascript&#058;window.location='index.php?file=Admin&page=menu&op=edit_menu&bid=" . $bid . "'\" /></td></tr>\n"
    . "<tr><td colspan=\"4\">&nbsp;</td></tr><tr><td colspan=\"4\" align=\"center\"><b>" . _PAGESELECT . " :</b></td></tr><tr><td colspan=\"4\">&nbsp;</td></tr>\n"
    . "<tr><td colspan=\"4\" align=\"center\"><select name=\"pages[]\" size=\"8\" multiple=\"multiple\">\n";
 
    select_mod2($pages);
 
    echo "</select></td></tr><tr><td colspan=\"4\" align=\"center\"><br />\n"
    . "<input type=\"hidden\" name=\"type\" value=\"" . $type . "\" />\n"
    . "<input type=\"hidden\" name=\"bid\" value=\"" . $bid . "\" />\n"
    . "<input type=\"hidden\" name=\"content\" value=\"$content\" />\n"
    . "<input type=\"submit\" name=\"send\" value=\"" . _MODIFBLOCK . "\" />\n"
    . "</td></tr></table>\n"
    . "<div style=\"text-align: center;\"><br />[ <a href=\"index.php?file=Admin&page=block\"><b>" . _BACK . "</b></a> ]</div></form><br />\n";
 
}  
 
?>
http://prodrift.exofire.net/modules/News/index.php

Code: Select all

<?php 
// -------------------------------------------------------------------------//
// Nuked-KlaN - PHP Portal                                                  //
// http://www.nuked-klan.org                                                //
// -------------------------------------------------------------------------//
// This program is free software. you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License.           //
// -------------------------------------------------------------------------//
if (!defined("INDEX_CHECK"))
{
    die ("<div style=\"text-align: center;\">You cannot open this page directly</div>");
} 
 
global $nuked, $language, $user;
translate("modules/News/lang/" . $language . ".lang.php");
 
// Inclusion système Captcha
include_once("Includes/nkCaptcha.php");
 
// On determine si le captcha est actif ou non
if (_NKCAPTCHA == "off") $captcha = 0;
else if (_NKCAPTCHA == "auto" && $user[1] > 0)  $captcha = 0;
else if (_NKCAPTCHA == "auto" && isset($_COOKIE[$cookie_captcha])) $captcha = 0;
else $captcha = 1;
 
if (!$user)
{
    $visiteur = 0;
} 
else
{
    $visiteur = $user[1];
} 
$ModName = basename(dirname(__FILE__));
$level_access = nivo_mod($ModName);
if ($visiteur >= $level_access && $level_access > -1)
{
    compteur("News");
 
    function index()
    {
        global $op, $news_id, $cat_id, $nuked, $file, $language, $p;
 
        $max_news = $nuked['max_news'];
        $day = time();
 
        if ($op == "categorie")
        {
            $where = "WHERE cat = '" . $cat_id . "' AND " . $day . " >= date";
        } 
        else if ($op == "suite" || $op == "index_comment")
        {
            $where = "WHERE id = '" . $news_id . "' AND " . $day . " >= date";
        } 
        else
        {
            $where = "WHERE " . $day . " >= date";
        } 
 
        $sql_nbnews = mysql_query("SELECT id FROM " . NEWS_TABLE . " " . $where);
        $nb_news = mysql_num_rows($sql_nbnews);
 
        if (!$p) $p = 1;
        $start = $p * $max_news - $max_news;
 
        if ($op == "categorie")
        {
            $sql = mysql_query("SELECT id, auteur, auteur_id, date, titre, texte, suite, cat, bbcodeoff, smileyoff FROM " . NEWS_TABLE . " WHERE cat = '" . $cat_id . "' AND " . $day . " >= date ORDER BY date DESC LIMIT " . $start . ", " . $max_news);
        } 
 
        else if ($op == "suite")
        {
            $sql = mysql_query("SELECT id, auteur, auteur_id, date, titre, texte, suite, cat, bbcodeoff, smileyoff FROM " . NEWS_TABLE . " WHERE id = '" . $news_id . "'");
        } 
 
        else if ($op == "index_comment")
        {
            $sql = mysql_query("SELECT id, auteur, auteur_id, date, titre, texte, suite, cat, bbcodeoff, smileyoff FROM " . NEWS_TABLE . " WHERE id = '" . $news_id . "'");
        } 
 
        else
        {
            $sql = mysql_query("SELECT id, auteur, auteur_id, date, titre, texte, suite, cat, bbcodeoff, smileyoff FROM " . NEWS_TABLE . " WHERE " . $day . " >= date ORDER BY date DESC LIMIT " . $start . ", " . $max_news);
        } 
 
        while (list($nid, $autor, $autor_id, $date, $titre, $texte, $suite, $cid, $bbcodeoff, $smileyoff) = mysql_fetch_array($sql))
        {
            $titre = stripslashes($titre);
            $texte = stripslashes($texte);
            $suite = stripslashes($suite);
            $autor = stripslashes($autor);
            $titre = htmlentities($titre);
 
            if ($bbcodeoff == 0)
            {
                $texte = htmlentities($texte);
                $texte = BBcode($texte);
            } 
            else
            {
                $texte = htmlentities($texte, ENT_NOQUOTES);
                $texte = eregi_replace("<", "<", $texte);
                $texte = eregi_replace(">", ">", $texte);
            }
 
            if ($smileyoff == 0)
            {
                $texte = icon($texte);
            } 
 
            $sql2 = mysql_query("SELECT im_id FROM " . COMMENT_TABLE . " WHERE im_id = '" . $nid . "' AND module = 'news'");
            $nb_comment = mysql_num_rows($sql2);
 
            $sql3 = mysql_query("SELECT titre, image FROM " . NEWS_CAT_TABLE . " WHERE nid = '" . $cid . "'");
            list($categorie, $image) = mysql_fetch_array($sql3);
            $categorie = stripslashes($categorie);
 
            if ($autor_id != "")
            {
            $sql4 = mysql_query("SELECT pseudo FROM " . USER_TABLE . " WHERE id = '" . $autor_id . "'");
            $test = mysql_num_rows($sql4);
            }
 
            if ($autor_id != "" && $test > 0)
            {
            list($auteur) = mysql_fetch_array($sql4);
            $auteur = stripslashes($auteur);
            } 
            else
            {
                $auteur = $autor;
            } 
 
            if ($language == "french")
            {
                $data['date'] = strftime("%A %d %B %Y", $date);
            } 
            else
            {
                $data['date'] = strftime("%A %B %d %Y", $date);
            } 
 
            $data['id'] = $nid;
            $data['titre'] = $titre;
            $data['auteur'] = $auteur;
            $data['heure'] = strftime("%H:%M", $date);
            $data['nb_comment'] = $nb_comment;
            $data['printpage'] = "<a href=\"index.php?file=News&nuked_nude=index&op=pdf&news_id=" . $nid . "\" onclick=\"window.open(this.href); return false;\"><img style=\"border: 0;\" src=\"images/pdf.gif\" alt=\"\" title=\"" . _PDF . "\" /></a>";
            $data['friend'] = "<a href=\"index.php?file=News&op=sendfriend&news_id=" . $nid . "\"><img style=\"border: 0;\" src=\"images/friend.gif\" alt=\"\" title=\"" . _FSEND . "\" /></a>";
 
            if ($image != "")
            {
                $data['image'] = "<a href=\"index.php?file=News&op=categorie&cat_id=" . $cid . "\"><img style=\"float: right;border: 0;\" src=\"" . $image . "\" alt=\"\" title=\"" . $categorie . "\" /></a>";
            } 
            else
            {
                $data['image'] = "";
            } 
 
            if ($op == "suite" || $op == "index_comment" && $suite != "")
            {
 
                if ($bbcodeoff == 0)
                {
                    $suite = htmlentities($suite);
                    $suite = BBcode($suite);
                } 
                else
                {
                    $suite = htmlentities($suite, ENT_NOQUOTES);
                    $suite = eregi_replace("<", "<", $suite);
                    $suite = eregi_replace(">", ">", $suite);
                }
 
                if ($smileyoff == 0)
                {
                    $suite = icon($suite);
                } 
 
                $data['texte'] = $texte . "<br /><br />" . $suite;
            } 
 
            else if ($suite != "")
            {
                $data['texte'] = $texte . "<div style=\"text-align: right;\"><a href=\"index.php?file=News&op=suite&news_id=" . $nid . "\">" . _READMORE . "</a></div>";
            } 
 
            else
            {
                $data['texte'] = $texte;
            } 
 
            news($data);
        } 
        if ($op == "categorie")
        {
            $url = "index.php?file=News&op=categorie&cat_id=" . $cat_id;
        } 
        else
        {
            $url = "index.php?file=News";
        } 
        if ($nb_news > $max_news)
        {
            echo "&nbsp;";
            number($nb_news, $max_news, $url);
            echo "<br /><br />";
        } 
    } 
 
    function index_comment($news_id)
    {
        global $user, $visiteur;
 
        if ($visiteur >= admin_mod("News"))
        {
            echo"<script type=\"text/javascript\">\n"
            ."<!--\n"
            ."\n"
            . "function delnews(id)\n"
            . "{\n"
            . "if (confirm('" . _DELTHISNEWS . " ?'))\n"
            . "{document.location.href = 'index.php?file=News&page=admin&op=do_del&news_id='+id;}\n"
            . "}\n"
            . "\n"
            . "// -->\n"
            . "</script>\n";
 
            echo "<div style=\"text-align: right;\"><a href=\"index.php?file=News&page=admin&op=edit&news_id=" . $news_id . "\"><img style=\"border: 0;\" src=\"images/edition.gif\" alt=\"\" title=\"" . _EDIT . "\" /></a>"
            . "&nbsp;<a href=\"javascript&#058;delnews('" . $news_id . "');\"><img style=\"border: 0;\" src=\"images/delete.gif\" alt=\"\" title=\"" . _DEL . "\" /></a></div>\n";
        } 
 
        index();
        include ("modules/Comment/index.php");
        com_index("news", $news_id);
    } 
 
    function suite($news_id)
    {
        global $user, $visiteur;
 
        if ($visiteur >= admin_mod("News"))
        {
            echo"<script type=\"text/javascript\">\n"
            ."<!--\n"
            ."\n"
            . "function delnews(id)\n"
            . "{\n"
            . "if (confirm('" . _DELTHISNEWS . " ?'))\n"
            . "{document.location.href = 'index.php?file=News&page=admin&op=do_del&news_id='+id;}\n"
            . "}\n"
            . "\n"
            . "// -->\n"
            . "</script>\n";
 
            echo "<div style=\"text-align: right;\"><a href=\"index.php?file=News&page=admin&op=edit&news_id=" . $news_id . "\"><img style=\"border: 0;\" src=\"images/edition.gif\" alt=\"\" title=\"" . _EDIT . "\" /></a>"
            . "&nbsp;<a href=\"javascript&#058;delnews('" . $news_id . "');\"><img style=\"border: 0;\" src=\"images/delete.gif\" alt=\"\" title=\"" . _DEL . "\" /></a></div>\n";
        } 
 
        index();
        include ("modules/Comment/index.php");
        com_index("news", $news_id);
    } 
 
    function categorie($cat_id)
    {
        index();
    } 
 
    function sujet()
    {
        global $nuked;
 
        opentable();
 
        echo "<br /><div style=\"text-align: center;\"><big><b>" . _SUBJECTNEWS . "</b></big></div><br /><br />\n"
        . "<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\">\n";
 
        $sql = mysql_query("SELECT nid, titre, description, image FROM " . NEWS_CAT_TABLE . " ORDER BY titre");
        while (list($id, $titre, $description, $image) = mysql_fetch_array($sql))
        {
            $titre = stripslashes($titre);
            $titre = htmlentities($titre);
            $description = stripslashes($description);
            $description = htmlentities($description);
            $description = BBcode($description);
    
            echo "<tr>";
 
            if ($image != "")
            {
                echo "<td><a href=\"index.php?file=News&op=categorie&cat_id=" . $id . "\">"
                . "<img style=\"border: 0;\" src=\"" . $image . "\" align=\"left\" alt=\"\" title=\"" . _SEENEWS . "&nbsp;" . $titre . "\" /></a></td>\n";
            } 
 
            echo "<td><b>" . $titre . " :</b><br />" . $description . "</td></tr><tr><td colspan=\"2\">&nbsp;</td></tr>\n";
        } 
        echo "</table><br /><br /><div style=\"text-align: center;\"><small><i>( " . _CLICSCREEN . " )</i></small></div><br />\n";
 
        closetable();
    } 
 
    function pdf($news_id)
    {
        global $nuked, $language;
 
        if ($language == "french" && ereg("WIN", PHP_OS)) setlocale (LC_TIME, "french");
        else if ($language == "french" && ereg("BSD", PHP_OS)) setlocale (LC_TIME, "fr_FR.ISO8859-1");
        else if ($language == "french") setlocale (LC_TIME, "fr_FR");
        else setlocale (LC_TIME, $language);
 
        $sql = mysql_query("SELECT auteur, auteur_id, date, titre, texte, suite, bbcodeoff, smileyoff FROM " . NEWS_TABLE . " WHERE id = '" . $news_id . "'");
        list($autor, $autor_id, $date, $title, $content, $suite, $bbcodeoff, $smileyoff) = mysql_fetch_row($sql);
        $title = stripslashes($title);
        $content = stripslashes($content);
        $suite = stripslashes($suite);
        $autor = stripslashes($autor);
        $heure = strftime("%H:%M", $date);
        $text = $content . "<br><br>" . $suite;
 
        if ($autor_id != "")
        {
            $sql2 = mysql_query("SELECT pseudo FROM " . USER_TABLE . " WHERE id = '" . $autor_id . "'");
            $test = mysql_num_rows($sql2);
        }
 
        if ($autor_id != "" && $test > 0)
        {
            list($auteur) = mysql_fetch_array($sql2);
            $auteur = stripslashes($auteur);
            $auteur = @html_entity_decode($auteur);
        } 
        else
        {
            $auteur = $autor;
        } 
 
        if ($language == "french")
        {
            $date = strftime("%A %d %B %Y", $date);
        } 
        else
        {
            $date = strftime("%A %B %d %Y", $date);
        } 
 
        $posted = "<font size=\"1\">" . _NEWSPOSTBY . " <a href=\"" . $nuked['url'] . "/index.php?file=Members&op=detail&autor=" . $auteur . "\">" . $auteur . "</a> " . _THE . " " . $date . " " . _AT . " " . $heure . "</font><br><br>";
 
        $text = str_replace("

Code: Select all

", "<code><b>Code :</b><br>", $text);
        $text = str_replace("
", "</code>", $text);        $text = str_replace("[/quote]", "</quote>", $text);        $text = str_replace("
", "<quote><b>Citation : </b><br />", $text);        $text = preg_replace("/\
(.*?)\ wrote:/i", "<quote><b>\\1 " . _HASWROTE . " :</b><br />", $text);         if ($bbcodeoff == 0)        {            $text = preg_replace("/\[color=(.*?)\](.*?)\[\/color\]/i", "<font color=\"\\1\">\\2</font>", $text);            $text = preg_replace("/\[size=(.*?)\](.*?)\[\/size\]/i", "<font size=\"\\1\">\\2</font>", $text);            $text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/i", "<font face=\"\\1\">\\2</font>", $text);            $text = preg_replace("/\[align=(.*?)\](.*?)\[\/align\]/i", "<p align=\"\\1\">\\2</p>", $text);            $text = str_replace("", "<b>", $text);            $text = str_replace("", "</b>", $text);            $text = str_replace("", "<i>", $text);            $text = str_replace("", "</i>", $text);            $text = str_replace("", "<u>", $text);            $text = str_replace("", "</u>", $text);            $text = str_replace("[li]", "<li>", $text);            $text = str_replace("[/li]", "</li>", $text);            $text = str_replace("[center]", "<center>", $text);            $text = str_replace("[/center]", "</center>", $text);            $text = str_replace("[strike]", "<strike>", $text);            $text = str_replace("[/strike]", "</strike>", $text);            $text = str_replace("[blink]", "", $text);            $text = str_replace("[/blink]", "", $text);            $text = str_replace("[flip]", "", $text);            $text = str_replace("[/flip]", "", $text);            $text = str_replace("[blur]", "", $text);            $text = str_replace("[/blur]", "", $text);            $text = preg_replace("/\[glow\](.*?)\[\/glow\]/i", "", $text);            $text = preg_replace("/\[glow=(.*?)\](.*?)\[\/glow\]/i", "", $text);            $text = preg_replace("/\[shadow\](.*?)\[\/shadow\]/i", "", $text);            $text = preg_replace("/\[shadow=(.*?)\](.*?)\[\/shadow\]/i", "", $text);            $text = preg_replace("/\[email\](.*?)\[\/email\]/i", "<a href=\"mailto:\\1\">\\1</a>", $text);            $text = preg_replace("/\[email=(.*?)\](.*?)\[\/email\]/i", "<a href=\"mailto:\\1\">\\2</a>", $text);            $text = preg_replace("/\[img\](.*?)\[\/img\]/i", "<img src=\"\\1\" border=\"0\">", $text);            $text = preg_replace("/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/i", "<img width=\"\\1\" height=\"\\2\" src=\"\\3\" border=\"0\">", $text);            $text = preg_replace("/\[flash\](.*?)\[\/flash\]/i", "", $text);            $text = preg_replace("/\[flash=(.*?)x(.*?)\](.*?)\[\/flash\]/i","", $text);            $text = preg_replace("/\[url\]www.(.*?)\[\/url\]/i", "<a href=\"http://www.\\1\" target=\"_blank\">\\1</a>", $text);            $text = preg_replace("/\[url\](.*?)\[\/url\]/i", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $text);            $text = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/i", "<a href=\"\\1\" target=\"_blank\">\\2</a>", $text);             $text = str_replace("\r", "", $text);            $text = str_replace("\n", "<br />", $text);            $text = ltrim($text);        }         if ($smileyoff == 0)        {            $text = icon($text);        }          $text = str_replace("<font color=\"red;\">", "<font color=\"#FF0000\">", $text);        $text = str_replace("<font color=\"darkred\">", "<font color=\"#8B0000\">", $text);        $text = str_replace("<font color=\"blue\">", "<font color=\"#0000FF\">", $text);        $text = str_replace("<font color=\"darkblue\">", "<font color=\"#00008B\">", $text);        $text = str_replace("<font color=\"orange\">", "<font color=\"#FFA500\">", $text);        $text = str_replace("<font color=\"orange\">", "<font color=\"#FFA500\">", $text);        $text = str_replace("<font color=\"brown\">", "<font color=\"#A52A2A\">", $text);        $text = str_replace("<font color=\"yellow\">", "<font color=\"#FFFF00\">", $text);        $text = str_replace("<font color=\"green\">", "<font color=\"#008000\">", $text);        $text = str_replace("<font color=\"violet\">", "<font color=\"#EE82EE\">", $text);        $text = str_replace("<font color=\"olive\">", "<font color=\"#808000\">", $text);        $text = str_replace("<font color=\"cyan\">", "<font color=\"#00FFFF\">", $text);        $text = str_replace("<font color=\"indigo\">", "<font color=\"#4B0082\">", $text);        $text = str_replace("<font color=\"white\">", "<font color=\"#FFFFFF\">", $text);        $text = str_replace("<font color=\"black\">", "<font color=\"#000000\">", $text);         $text = str_replace(""", "\"", $text);        $text = str_replace("'", "\'", $text);        $text = str_replace("&agrave;", "à", $text);        $text = str_replace("&acirc;", "â", $text);        $text = str_replace("&eacute;", "é", $text);        $text = str_replace("&egrave;", "è", $text);        $text = str_replace("&ecirc;", "ê", $text);        $text = str_replace("&ucirc;", "û", $text);         $texte = $posted . $text;         $articleurl = $nuked['url'] . "/index.php?file=News&op=index_comment&news_id=" . $news_id;         include ('Includes/html2fpdf/html2fpdf.php');        $sitename = $nuked['name'] . " - " . $nuked['slogan'];        $sitename  = @html_entity_decode($sitename);         $texte = "<h1>".$title."</h1><hr />".$texte."<hr />".$sitename."<br />".$articleurl;        $file = $sitename."_".$title;        $file = str_replace(' ','_',$file);        $file .= ".pdf";                $pdf = new HTML2FPDF();        $pdf->AddPage();        $pdf->header();        $pdf->WriteHTML($texte);        $pdf->Output($file,D);    }       function sendfriend($news_id)    {        global $nuked, $user, $captcha;         opentable();         echo "<script type=\"text/javascript\">\n"        ."<!--\n"        ."\n"        . "function verifchamps()\n"        . "{\n"        . "\n"        . "if (document.getElementById('sf_pseudo').value.length == 0)\n"        . "{\n"        . "alert('" . _NONICK . "');\n"        . "return false;\n"        . "}\n"        . "\n"        . "if (document.getElementById('sf_mail').value.indexOf('@') == -1)\n"        . "{\n"        . "alert('" . _BADMAIL . "');\n"        . "return false;\n"        . "}\n"        . "\n"        . "return true;\n"        . "}\n"        ."\n"        . "// -->\n"        . "</script>\n";         $sql = mysql_query("SELECT titre FROM " . NEWS_TABLE . " WHERE id = '" . $news_id . "'");        list($title) = mysql_fetch_array($sql);        $title = stripslashes($title);        $title = stripslashes($title);         echo "<form method=\"post\" action=\"index.php?file=News\" onsubmit=\"return verifchamps()\">\n"        . "<table style=\"margin-left: auto;margin-right: auto;text-align: left;\" width=\"60%\" cellspacing=\"1\" cellpadding=\"1\" border=\"0\">\n"        . "<tr><td align=\"center\"><br /><big><b>" . _FSEND . "</b></big><br /><br />" . _YOUSUBMIT . " :<br /><br />\n"        . "<b>" . $title . "</b><br /><br /></td></tr><tr><td align=\"left\">\n"        . "<b>" . _YNICK . " : </b>&nbsp;<input type=\"text\" id=\"sf_pseudo\" name=\"pseudo\" value=\"" . $user[2] . "\" size=\"20\" /></td></tr>\n"        . "<tr><td><b>" . _FMAIL . " : </b>&nbsp;<input type=\"text\" id=\"sf_mail\" name=\"mail\" value=\"mail@gmail.com\" size=\"25\" /></td></tr>\n"        . "<tr><td><b>" . _YCOMMENT . " : </b><br /><textarea name=\"comment\" cols=\"60\" rows=\"10\"></textarea></td></tr>\n";                if ($captcha == 1) create_captcha(1);                echo "<tr><td align=\"center\"><input type=\"hidden\" name=\"op\" value=\"sendnews\" />\n"        . "<input type=\"hidden\" name=\"news_id\" value=\"" . $news_id . "\" />\n"        ." <input type=\"hidden\" name=\"title\" value=\"" . $title . "\" />\n"        ." <input type=\"submit\" value=\"" . _SEND . "\" /></td></tr></table></form><br />\n";         closetable();    }      function sendnews($title, $news_id, $comment, $mail, $pseudo)    {        global $nuked, $user_ip, $captcha;                opentable();                if ($captcha == 1 && $_POST['code_confirm'] != crypt_captcha($_POST['code']))        {            echo "<div style=\"text-align: center;\"><br /><br />" . _BADCODECONFIRM . "<br /><br /><a href=\"javascript&#058;history.back()\">[ <b>" . _BACK . "</b> ]</a></div>";        }         else         {            $date2 = time();            $date2 = strftime("%x %H:%M", $date2);             $title = stripslashes($title);            $comment = stripslashes($comment);             $mail = trim($mail);            $pseudo = trim($pseudo);             $subject = $nuked['name'] . ", " . $date2;            $corps = $pseudo . " (IP : " . $user_ip . ") " . _READNEWS . " " . $title . ", " . _NEWSURL . "\r\n" . $nuked['url'] . "/index.php?file=News&op=index_comment&news_id=" . $news_id . "\r\n\r\n" . _YCOMMENT . " : " . $comment . "\r\n\r\n\r\n" . $nuked['name'] . " - " . $nuked['slogan'];            $from = "From: " . $nuked['name'] . " <" . $nuked['mail'] . ">\r\nReply-To: " . $nuked['mail'];             $subject = @html_entity_decode($subject);            $corps = @html_entity_decode($corps);            $from = @html_entity_decode($from);              mail($mail, $subject, $corps, $from);             echo "<div style=\"text-align: center;\"><br />" . _SENDFMAIL . "<br /><br /></div>";            redirect("index.php?file=News", 2);        }        closetable();    }      switch ($op)    {        case"index":            index();            break;         case"index_comment":            index_comment($news_id);            break;         case"suite":            suite($news_id);            break;         case"categorie":            categorie($cat_id);            break;         case"sujet":            sujet();            break;         case"pdf":            pdf($news_id);            break;         case"sendfriend":            sendfriend($news_id);            break;         case"sendnews":            sendnews($title, $news_id, $comment, $mail, $pseudo);            break;         default:            index();            break;    }  } else if ($level_access == -1){    opentable();    echo "<br /><br /><div style=\"text-align: center;\">" . _MODULEOFF . "<br /><br /><a href=\"javascript&#058;history.back()\"><b>" . _BACK . "</b></a><br /><br /></div>";    closetable();} else if ($level_access == 1 && $visiteur == 0){    opentable();    echo "<br /><br /><div style=\"text-align: center;\">" . _USERENTRANCE . "<br /><br /><b><a href=\"index.php?file=User&op=login_screen\">" . _LOGINUSER . "</a> | <a href=\"index.php?file=User&op=reg_screen\">" . _REGISTERUSER . "</a></b><br /><br /></div>";    closetable();} else{    opentable();    echo "<br /><br /><div style=\"text-align: center;\">" . _NOENTRANCE . "<br /><br /><a href=\"javascript&#058;history.back()\"><b>" . _BACK . "</b></a><br /><br /></div>";    closetable();}  ?> 

Now when someone opens up a link the the News page it will open the link up as http://www.prodrift.exofire.net/index.php?file=News (News being the name of the folder the index.php file is in which is what I want). And when users open that link it will load the page with all the contents of News/index.php shown in the contents area of the page.

As you can see in the second script they are using "$ModName = basename(dirname(__FILE__));" to get the folder name which I can only assume they are applying to the links.

Anyways I can't talk anymore, have to take my pop somewhere. But any help would be greatly appreciated. I do hope your understanding what I mean. It's not exactly easy to explain :P considering I'm a php noob. But I'm also a quick learner, I tend to learn the more advanced stuff faster then the basic stuff.

Re: opening pages in one page

Posted: Wed Jul 08, 2009 1:25 am
by insight
OK, let's try this another way.

If a user tries to access a page directly by going directly to http://www.insight.atbhost.com/modules/link-2/index.php they will get a message saying they cannot view this page directly. In order for the user to view the page they must load it through http://insight.atbhost.com/index.php?file=link-2.

Like the code says below:

Code: Select all

if (!defined("INDEX_CHECK"))
{
    die ("<div style=\"text-align: center;\">You cannot open this page directly</div>");
}
The code will be placed in the http://www.insight.atbhost.com/modules/link-2/index.php file.

When I add this code to my php file and include it in the http://www.insight.atbhost.com/index.php file I get "You cannot open this page directly" in the contents area. How do I make it so I can view it in the index.php file as say (.com/index.php?file=link-2) but if a user tries to open it directly (by going to .com/modules/link-2/index.php) they will get that message.