Shoutbox

/?id=home - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: /?id=home (/showthread.php?tid=54114)

/?id=home by stoshrocket on 12-20-2005 at 10:54 PM

ok, before someone posts the google sign, i have genuinely looked for help from many webistes including phpfreaks.com, phpbuilder.com etc etc
the problem is i want use the ?id= tag to link between pages instead of the ususal <a href="/index.html">
any suggestions on some good tutorials (i dont want just a code thanks, i want to know how it works) or maybe if someone could explain? thanks!


RE: /?id=home by ShawnZ on 12-20-2005 at 10:58 PM

you would use $_GET['whatever'] to get what they put after "?whatever=" in the url, then you can just use some IF statements to associate that name with a page and include it. (if whatever==page1 then include index2.html or such) You can also include every page in a single php file and store them in variables, then just 'echo' them if whatever is equal to "pageX"

Note: NEVER EVER EVER EVER EVER let users include any page by filename (e.g. include($_GET['whatever']) -- bad idea) or let users echo any variable they want (e.g. echo(eval('$' . $_GET['whatever'])) -- also a bad idea) because you'll get hacked in under a second.


RE: /?id=home by CookieRevised on 12-20-2005 at 11:12 PM

What Shawnz said is for PHP. If you don't know PHP or want to do this without PHP (and thus only basic HTML and javascript), look up "anchors". Those are the things which start with "#". eg: http://www.blah.com/mypage.htm#here

You can do exactly the same with them as you can with PHP, though you need to write some small javascript code to parse the anchors (and thus react on them) as this use of anchors is a bit different than the default usage (which is jumping to a particular place on the page).

Though PHP is much more secure since people can't view the original source of the page and find out some (hidden) "anchors". Of course, with only HTML and javascript, the source can easly be viewed. But if it is just for jumping thru pages and/or redirecting and/or making some choices and/or parsing some variables to a specific page, than anchors and javascript can do this perfectly also.


RE: /?id=home by ShawnZ on 12-20-2005 at 11:59 PM

quote:
Originally posted by CookieRevised
What Shawnz said is for PHP. If you don't know PHP or want to do this without PHP (and thus only basic HTML and javascript), look up "anchors". Those are the things which start with "#". eg: http://www.blah.com/mypage.htm#here

You can do exactly the same with them as you can with PHP, though you need to write some small javascript code to parse the anchors (and thus react on them) as this use of anchors is a bit different than the default usage (which is jumping to a particular place on the page).

Though PHP is much more secure since people can't view the original source of the page and find out some (hidden) "anchors". Of course, with only HTML and javascript, the source can easly be viewed. But if it is just for jumping thru pages and/or redirecting and/or making some choices and/or parsing some variables to a specific page, than anchors and javascript can do this perfectly also.

Isn't this completly unrelated? He said ?id= and even specifically said PHP.
RE: /?id=home by CookieRevised on 12-21-2005 at 12:10 AM

[OFF TOPIC]
Nope, it is very related and for all we know he maybe didn't even know you can do it with html and javascript and thus asked the question as he did. Maybe he doesn't know PHP and maybe rather don't wanna use or learn it just for that, but only asked it in the way he did because he assumed it was only possible with PHP
(you would be surprised in how many people ask stuff like this in this way as they don't know which alternatives exist; or asking something slithly differentl/or too specific than what they actually mean, unwillingly).

Also the post is very relevant for anyone else who is searching for the subject and/or have the same questions and/or thought-process as I just described. For this, the post isn't only for answering his question, but also for answering the questions of people who might come across this thread (and maybe even don't know about PHP and/or javascript and/or the difference, etc).
(is also part of anticipating questions)
[/OFF TOPIC]


RE: /?id=home by ShawnZ on 12-21-2005 at 12:22 AM

quote:
Originally posted by CookieRevised
[OFF TOPIC]
No, it is very related and for all we know he maybe didn't even know you can do it with html and javascript and thus asked the question as he did. Maybe he doesn't know PHP and maybe rather don't wanna use or learn it just for that, but only asked it in the way he did because he assumed it was only possible with PHP (You would be surprised in how many people ask stuff like this in this way as they don't know which alternatives exist).

Also the post is very relevant for anyone else who is searching for the subject and/or have the same questions and/or thought-process as I just described. For this, the post isn't only for answering his question, but also for answering the questions of people who might come across this thread (and maybe even don't know about PHP and/or javascript and/or the difference, etc).
[/OFF TOPIC]

But come on? Using the location.hash for that kind of thing is laughable coding. In fact, I highly suggest Methos2 avoids the suggestion.
RE: /?id=home by surfichris on 12-21-2005 at 12:23 AM

[

quote:
Originally posted by CookieRevised
Nope, it is very related and for all we know he maybe didn't even know you can do it with html and javascript and thus asked the question as he did.
I'm sorry to say it, but whoever does that with Javascript is a moron.

Firstly, what happens when users have Javascript disabled?

Secondly, you'd be redirecting people AGAIN to a new page.
RE: RE: /?id=home by CookieRevised on 12-21-2005 at 12:35 AM

quote:
Originally posted by Chris Boulton
[
quote:
Originally posted by CookieRevised
Nope, it is very related and for all we know he maybe didn't even know you can do it with html and javascript and thus asked the question as he did.
I'm sorry to say it, but whoever does that with Javascript is a moron.
lol, well, I didn't say it was a perfectly sane way. I just said it is possible in case somebody wants it (or if PHP isn't available)...

(PS: and in some specific small cases, it is indeed sane to do though)

quote:
Originally posted by Chris Boulton
Firstly, what happens when users have Javascript disabled?
It wouldn't work... What happens if the creator hasn't access to a PHP enabled host?

quote:
Originally posted by Chris Boulton
Secondly, you'd be redirecting people AGAIN to a new page.
Highly depends on what you want to do. If it is only for redirecting, then yes (but isn't PHP doing this also in way?). But, just as in PHP, it can be used for far more things than only that.
RE: /?id=home by ShawnZ on 12-21-2005 at 12:36 AM

quote:
Originally posted by CookieRevised
It wouldn't work... What happens if the creator hasn't access to a PHP enabled host?

Well, at least there isn't a RISK involved in that.

quote:
Originally posted by CookieRevised
(but isn't PHP doing this also in way?)

Uh no?


RE: /?id=home by surfichris on 12-21-2005 at 12:40 AM

quote:
Originally posted by CookieRevised
What happens if the creator hasn't access to a PHP enabled host?
Well, obviously if the user is creating it then he'd know he has PHP. You can't just say "bah, everyone without JS don't matter" :P You can't make predications on your visitors like that :P
quote:
Originally posted by CookieRevised
If it is only for redirecting, then yes (but isn't PHP doing this also in way?). But, just as in PHP, it can be used for far more things than only that.
In PHP, I wouldn't make it redirect, i'd make it seem totally transparent to the user and use an include() function.

So something like:
code:
<?php
$action = ($_GET['action'] ? $_GET['action']; : $_POST['action']); // Assign $action based on if we're getting or posting.

switch($_GET['action'])
{
    case "test":
        include "test.php";
        break;
    default:
        include "home.php";
        break;
}
?>

(However, you have to expand on it - it only supports pages you've added to the switch..)
RE: /?id=home by CookieRevised on 12-21-2005 at 12:55 AM

quote:
Originally posted by Chris Boulton
quote:
Originally posted by CookieRevised
What happens if the creator hasn't access to a PHP enabled host?
Well, obviously if the user is creating it then he'd know he has PHP. You can't just say "bah, everyone without JS don't matter" :P You can't make predications on your visitors like that :P
Not all hosts include the ability to write php though. And some people who read this thread/question might wanna do the same on their (crappy) hosts.

quote:
Originally posted by Chris Boulton
quote:
Originally posted by CookieRevised
If it is only for redirecting, then yes (but isn't PHP doing this also in way?). But, just as in PHP, it can be used for far more things than only that.
In PHP, I wouldn't make it redirect, i'd make it seem totally transparent to the user and use an include() function.
yep, true, agreed, but I actually meant it as in:
in js:
1) the js script is loaded.... client side
2) depending on the switch the page is loaded.... client side
php:
1) the php script is loaded.... server side
2) depending on the switch the page is included, aka needs to be loaded also.... server side (if that is the only thing it is used for, because, again, I was not only talking about that specific use)

hence:
quote:
Originally posted by CookieRevised
(but isn't PHP doing this also in a way?)
If you only look at it as what is done server/client side, yep, only 1 thing gets loaded in php. But thus that was not what I meant with it though, sorry for being a bit vague there.

-----------------------------------


quote:
Originally posted by ShawnZ
But come on? Using the location.hash for that kind of thing is laughable coding. In fact, I highly suggest Methos2 avoids the suggestion.
1) using js for redirecting is perfectly sane (and frankly, quite often done all over the place, yes, even on these forums). Nothing laughable at all...
2) Using anchors for only redirecting is less sane though, but can sometimes be the only possible way. again, nothing laughable at all in those cases...

quote:
Originally posted by ShawnZ
quote:
Originally posted by CookieRevised
What happens if the creator hasn't access to a PHP enabled host?
Well, at least there isn't a RISK involved in that.
Who's talking about risk? In fact, if you only talk about this specific use, then there is less risk for the user if some creator did it in javascript than if the creator did it in php. As the user can see the source of the (javascript) page and thus can see and have a clue of what it does. If it was in php, the user can only guess what it will do and hope for the best...

-----------------------------------

But all this is going towards what's best to use. I never ever said anywhere that javascript is the best thing to use over php. I only gave an alternative, nothing more, nothing less.

So no this wasn't off topic as both methods are extremely closely related and are alternatives for eachother in some specific uses. And thus I posted what I posted to make the picture complete.

eg/analogy: If someone asks to create a plugin so he can attach text to a custom sound, and you make a post about quicktexts than that isn't off topic either. Though quick texts have got nothing to do with custom sounds (even less than what anchors have to do with php) and plugins, it provides an alternative way to what the user, and people who might come across the thread, wants. Although the original poster asked his question in relation to plugins, he don't nessecairly meant he wants a plugin to do it; as long as the job gets done. He might simply don't know another method....

edit: @rav0: that can be the exactly what people might want in some cases. Don't dismiss it simply because of that. Remember that these anchors, and the equivalent in php, can also be used for other stuff than a simple redirection (eg: to parse info to a page and set some form elements or whatever).

RE: /?id=home by rav0 on 12-21-2005 at 08:35 AM

Check out my thread about this. The method that -dt- posted is my choice, but there are more there as well.

CookieRevised, this is why not to use JavaScript to redirect.


RE: /?id=home by Stigmata on 12-21-2005 at 09:50 AM

http://shoutbox.menthix.net/showthread.php?tid=45...d=473328#pid473328


RE: /?id=home by absorbation on 12-21-2005 at 02:12 PM

I use ?id=home on my websites for the homepage it is a script that allowed a series of includes on a page, thus you dont have to update each page when you alter a design. The page extension must be in php.

Here is what I use on my websites:

<?PHP
error_reporting (E_ALL ^ E_NOTICE);
if(!$id){ $id = $HTTP_GET_VARS['id']; }

if($id=="" or $id=="home"){
    include("home.php");
}elseif($id=="asmiles"){
    include("animatedsmiles/index.php");
}elseif($id=="backgrounds"){
    include("backgrounds/index.php");
}elseif($id=="downloads"){
    include("downloads/pafiledb.php");
}elseif($id=="dp"){
    include("dp/index.php");
}elseif($id=="names"){
    include("names/index.php");
}elseif($id=="smiles"){
    include("smiles/index.php");
}elseif($id=="web"){
    include("web.php");
}
?>

(that's part of msgstuff)


you add this where your page content begins and in the includes you add the other pages, but just the basic code and not all the html and head tags.


RE: /?id=home by hmaster on 12-21-2005 at 02:39 PM

I use to have something similar to the if/else..

code:
//Page system

if(!isset($_GET['page']))
    {include('index.htm');}

elseif($_GET['page'] == "home"){include('index.htm');}
elseif($_GET['page'] == "news"){include('news.htm');}

//msn pages
elseif($_GET['page'] == "msn"){
    if(!isset($_GET['ver']))
    {include('msn.htm');}
      elseif($_GET['ver'] == "8")
    {include('msn/wlm.htm'); }
    elseif($_GET['ver'] == "7.5")
    {include('msn/7.5.htm'); }
    else{include "error.php";}
    }
       
elseif($_GET['page'] == "desktop"){include('desktop.htm');}
elseif($_GET['page'] == "downloads"){include('downloads.htm');}
elseif($_GET['page'] == "info"){include('info.php');}

elseif($_GET['page'] == "contact"){include('contact.htm');}
elseif($_GET['page'] == "contacted"){include('contact.php');}
elseif($_GET['page'] == "projects"){include('projects.htm');}

//w2m sec
elseif($_GET['page'] == "w2m"){
    if(!isset($_GET['sec']))
    {include('w2m/index.php');}
    elseif($_GET['sec'] == "start")
    {include('w2m/start.php'); }
    elseif($_GET['sec'] == "tut")
    {include('w2m/tut.php');}
   
    else{include "error.php";}
    }
   
//wdp sec
elseif($_GET['page'] == "wdp"){
    if(!isset($_GET['sec']))
    {include('wdp/dynamic.php');}
    elseif($_GET['sec'] == "dynamic")
    else{include "error.php";}
    }

else{include "error.php";}

But then I got too many pages so i changed it to switch/case:

code:
if(!isset($_GET['page'])) {include "index.htm";}
elseif($_GET['page'] == "msn" && !isset($_GET['ver'])) {include "msn.htm";}
elseif($_GET['page'] == "w2m" && !isset($_GET['sec'])) {include "w2m/index.php";}
elseif($_GET['page'] == "wdp" && !isset($_GET['sec'])) {include "wdp/dynamic.php";}
elseif($_GET['page'] == "projects" && !isset($_GET['id'])) {include "projects.htm";}
else {
switch ($_GET['page']) {
               
    case "home":
        include "index.htm"; break;
    case "news":
        include "news.htm"; break;
    case "desktop":
        include "desktop.htm"; break;
    case "comics":
        include "comics.htm"; break;
    case "downloads":
        include "downloads.htm"; break;
    case "contact":
        include "contact.htm"; break;
    case "info":
        include "info.php"; break;
    case "wdp":
        switch($_GET['page'] == "wdp" && @$_GET['sec']) {
        case "dyimg":
            include "wdp/dyimg.php"; break;
        case "dynamic":
            include "wdp/dynamic.php"; break; }
}
}

These are not all the pages, itll take too much space
RE: /?id=home by stoshrocket on 12-21-2005 at 03:32 PM

quote:
Originally posted by Absorbation
I use ?id=home on my websites for the homepage it is a script that allowed a series of includes on a page, thus you dont have to update each page when you alter a design. The page extension must be in php.

Here is what I use on my websites:

<?PHP
error_reporting (E_ALL ^ E_NOTICE);
if(!$id){ $id = $HTTP_GET_VARS['id']; }

if($id=="" or $id=="home"){
    include("home.php");
}elseif($id=="asmiles"){
    include("animatedsmiles/index.php");
}elseif($id=="backgrounds"){
    include("backgrounds/index.php");
}elseif($id=="downloads"){
    include("downloads/pafiledb.php");
}elseif($id=="dp"){
    include("dp/index.php");
}elseif($id=="names"){
    include("names/index.php");
}elseif($id=="smiles"){
    include("smiles/index.php");
}elseif($id=="web"){
    include("web.php");
}
?>

(that's part of msgstuff)


you add this where your page content begins and in the includes you add the other pages, but just the basic code and not all the html and head tags.

let me see if i understand this:: i create a template with this code in,  so that the content is not in and it will be the actual style then save it as a .php file, then create the very basic coding of different pages ie it would just be::

code:
<div class="body">
content filler
content filler
content filler
</div>


saving this as content.php (and using the id as "content")

then for the link would i put <a href="?id=content">... yes?
RE: /?id=home by absorbation on 12-21-2005 at 03:36 PM

quote:
Originally posted by Methos2
then for the link would i put <a href="?id=content">... yes?

Infact i'll show you the source code i use for http://www.absorbation.com

As you can see i start the php where the content starts, feel free to view the includes source to, to see how it works :)

(See Attachment)
RE: /?id=home by stoshrocket on 12-21-2005 at 03:40 PM

quote:
Originally posted by Absorbation
quote:
Originally posted by Methos2
then for the link would i put <a href="?id=content">... yes?

Infact i'll show you the source code i use for http://www.absorbation.com

As you can see i start the php where the content starts, feel free to view the includes source to, to see how it works :)

(See Attachment)


thankyou!! thanks to everyone, i understand it now, cheers!
RE: /?id=home by -dt- on 12-21-2005 at 03:54 PM

quote:
Originally posted by Absorbation

<?PHP
error_reporting (E_ALL ^ E_NOTICE);
if(!$id){ $id = $HTTP_GET_VARS['id']; }

if($id=="" or $id=="home"){
include("home.php");
}elseif($id=="asmiles"){
include("animatedsmiles/index.php");
}elseif($id=="backgrounds"){
include("backgrounds/index.php");
}elseif($id=="downloads"){
include("downloads/pafiledb.php");
}elseif($id=="dp"){
include("dp/index.php");
}elseif($id=="names"){
include("names/index.php");
}elseif($id=="smiles"){
include("smiles/index.php");
}elseif($id=="web"){
include("web.php");
}
?>
why not do
if(!$id){ $id = $HTTP_GET_VARS['id']; }
to
if(isset($_GET['id'])){ $id = $_GET['id']; }else { $id=''}


insted of changing error_reporting and removing notices , just fix your code.
A NOTICE == BAD CODE.
RE: /?id=home by stoshrocket on 12-21-2005 at 09:15 PM

am i understanding this right, for the template i have created the file needed and its working fine, although i still must not be doing something right, its not working::
for the include aea i have the following code under the <body> tag

code:
<body>

<div class="banner">
</div>

<div class="nav">
<a href="/?id=home">home</a>
<a href="/?id=graphics">graphics</a>
<a href="/?id=webdesign">web design</a>
<a href="/?id=projects">projects</a>
<a href="/?id=msn">msn</a>
</div>

<?PHP
error_reporting (E_ALL ^ E_NOTICE);
if(!$id){ $id = $HTTP_GET_VARS['id']; }

if($id=="" or $id=="home"){
    include("home.php");
}elseif($id=="graphics"){
    include("graphics.php");
}elseif($id=="webdesign"){
    include("design.php");
}elseif($id=="projects"){
    include("projects.php");
}elseif($id=="msn"){
    include("msn.php");
}elseif($id=="about"){
    include("about.php");
}elseif($id=="contact"){
    include("contact.php");

}
?>

</body>

and the file home.php consistis of only
code:
<div class="content">
<div class="dt">
<span class="dt"><script type="text/javascript">document.write(getdt())</script></span>
</div>

this is a test of the new site design, it isnt working

</div>


am i doing something wrong here? i cant see why it wouldnt work unless im doing the home.php file wrong, as i have compared my coding to absorbations..... :S
RE: /?id=home by absorbation on 12-21-2005 at 09:19 PM

looks fine here, what is wrong with it? have you place this test in a different direcotry because your links begin with a / going to the home direcotry :P


RE: /?id=home by stoshrocket on 12-21-2005 at 09:22 PM

ive put it under /mock, hold on, ill upload it and post a link so you can see then ill post the code that is behind it, the actual problem is that nothing is showing, it is as though there is nothing to show! hold on....


RE: /?id=home by absorbation on 12-21-2005 at 09:24 PM

that's your problem change the links to:

<div class="nav">
<a href="?id=home">home</a>
<a href="?id=graphics">graphics</a>
<a href="?id=webdesign">web design</a>
<a href="?id=projects">projects</a>
<a href="?id=msn">msn</a>
</div>


RE: /?id=home by stoshrocket on 12-21-2005 at 09:29 PM

quote:
Originally posted by Absorbation
that's your problem change the links to:

<div class="nav">
<a href="?id=home">home</a>
<a href="?id=graphics">graphics</a>
<a href="?id=webdesign">web design</a>
<a href="?id=projects">projects</a>
<a href="?id=msn">msn</a>
</div>

ive done that, but i think i know what it is.... i think you need to put in a <script...> tag or something, thats why its not reading it as php... maybe... anyways, here is the link if its not...

http://methos2.skarz.co.uk/mock/

the code is basically the same, ive just done what absorbation has told me and added a div to contain everything; the dt and content...
RE: /?id=home by absorbation on 12-21-2005 at 09:31 PM

click view source the php is not being excercuted is your page extension .php?


RE: /?id=home by stoshrocket on 12-21-2005 at 09:34 PM

quote:
Originally posted by Absorbation
click view source the php is not being excercuted is your page extension .php?

ermmm.... yes of course it is... oh look! the problem has magically fixed itself! 8-) lol :lol:

i feel so stupid making that mistake, lol :$