Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] IF $_GET as startpage.

Experienced Elementalist
Joined
Mar 22, 2008
Messages
297
Reaction score
0
Firstly i'm gonna explain the hole situation: I wan't my HOLE site in just one page, and i know how to do that
PHP:
<a href="?photoshop">Photoshop</a>
<a href="?scripts">Scripts</a>
 
<?php

if(isset($_GET['photoshop'])) {
echo "This is the Photoshop page!
";
}

if(isset($_GET['scripts'])) {
echo "
This is the scripts page!

";
}
?>


This is how my wepage coding looks like:

PHP:
<html>
    <head>
        <link href="default.css" type="text/css" rel="stylesheet" />
        <title>Selaku.com - Hazzan's portfolio.</title>
    </head>
    <body spellcheck="false">
        <div class="main">
        <div class="gfx">
        <h1>Selaku.com</h1>
        </div>
        <div class="menu"><a href="?photoshop"><span>Photoshop</span></a>         <a href="?scripts"><span>Scripts</span></a></div>
        <?php
if(isset($_GET['start'])) {
echo "<div class=content>
<div class=item><h1>Welcome</h1><br>
Hey and welcome to my personal portfolio were i post, well kinda everything useful, so enjoy! :)
</div></div>
";
}

if(isset($_GET['photoshop'])) {
echo "<div class=content>
<div class=item><h1>Photoshop</h1>
This is the Photoshop page!
</div></div>
";
}

if(isset($_GET['scripts'])) {
echo "
<div class=content>
<div class=item><h1>Scripts</h1><br>
This is the scripts page!
</div></div>
";
}
?>
        <div class="footer">© 2006 <a href="index.html">Sitename.com</a>. Design by <a href="http://arcsin.se">Arcsin</a></div>
        </div>
    </body>
</html>

and this is the adress: hazzan.110mb.com

I want the $_GET called "start" to show up FIRST when ppl goes to my homepage, but now it shows nothing in the body.
 
duck you, I'm a dragon
Loyal Member
Joined
Apr 29, 2005
Messages
6,405
Reaction score
130
Your use of get is wrong, you create a new variable for every page. It should be that there is one variable with a different value for every page. So instead of ?photoshop and ?scripts use ?action=photoshop and ?action=scripts

Assuming you make the changes mentioned above, these scripts will work.

PHP:
<a href="?action=photoshop">Photoshop</a>
<a href="?action=scripts">Scripts</a>
 
<?php

if(isset($_GET['photoshop'])) {
echo "This is the Photoshop page!
";
}

if(isset($_GET['scripts'])) {
echo "
This is the scripts page!

";
}
?>

PHP:
<html>
    <head>
        <link href="default.css" type="text/css" rel="stylesheet" />
        <title>Selaku.com - Hazzan's portfolio.</title>
    </head>
    <body spellcheck="false">
        <div class="main">
        <div class="gfx">
        <h1>Selaku.com</h1>
        </div>
        <div class="menu"><a href="?photoshop"><span>Photoshop</span></a>         <a href="?scripts"><span>Scripts</span></a></div>
        <?php
if(!isset($_GET['action'] || $_GET['action']=="start") {
echo "<div class=content>
<div class=item><h1>Welcome</h1><br>
Hey and welcome to my personal portfolio were i post, well kinda everything useful, so enjoy! :)
</div></div>
";
}

if(isset($_GET['action'] == "photoshop")) {
echo "<div class=content>
<div class=item><h1>Photoshop</h1>
This is the Photoshop page!
</div></div>
";
}

if(isset($_GET['action'] == "scripts")) {
echo "
<div class=content>
<div class=item><h1>Scripts</h1><br>
This is the scripts page!
</div></div>
";
}
?>
        <div class="footer">© 2006 <a href="index.html">Sitename.com</a>. Design by <a href="http://arcsin.se">Arcsin</a></div>
        </div>
    </body>
</html>
 
Experienced Elementalist
Joined
Mar 22, 2008
Messages
297
Reaction score
0
I get the error message:

Parse error: syntax error, unexpected T_BOOLEAN_OR, expecting ',' or ')' in /www/110mb.com/h/a/z/z/a/n/_/_/hazzan/htdocs/index.php on line 13
 
Junior Spellweaver
Joined
Jun 17, 2007
Messages
116
Reaction score
1
or try using this little line :p

If the $_GET variable doesn't exist it will automaticly execute the "Start" part
PHP:
$action = (isset($_GET['action']) ? $_GET['action'] : "Start");

PHP:
<?php

if($action == 'Photoshop') {
echo "This is the Photoshop page!
";
}

if($action == 'Scripts') {
echo "
This is the scripts page!

";
}
?>

PHP:
<html>
    <head>
        <link href="default.css" type="text/css" rel="stylesheet" />
        <title>Selaku.com - Hazzan's portfolio.</title>
    </head>
    <body spellcheck="false">
        <div class="main">
        <div class="gfx">
        <h1>Selaku.com</h1>
        </div>
        <div class="menu"><a href="?photoshop"><span>Photoshop</span></a>         <a href="?scripts"><span>Scripts</span></a></div>
        <?php
if($action == 'Start') {
echo "<div class=content>
<div class=item><h1>Welcome</h1><br>
Hey and welcome to my personal portfolio were i post, well kinda everything useful, so enjoy! :)
</div></div>
";
}

if($action == 'Photoshop') {
echo "<div class=content>
<div class=item><h1>Photoshop</h1>
This is the Photoshop page!
</div></div>
";
}

if($action == 'Scripts') {
echo "
<div class=content>
<div class=item><h1>Scripts</h1><br>
This is the scripts page!
</div></div>
";
}
?>
        <div class="footer">© 2006 <a href="index.html">Sitename.com</a>. Design by <a href="http://arcsin.se">Arcsin</a></div>
        </div>
    </body>
</html>
 
Experienced Elementalist
Joined
Mar 22, 2008
Messages
297
Reaction score
0
Ok, thanks allot both of you!

Since you're l33t in php i have on more question; i've seen ppl having 404's. like if you go to hazzan.110mb.com/index.php?action=some_page_that_doesn't_exist a 404 shows up.

Maybe you know how to make that to? :)
 
Joined
Sep 10, 2006
Messages
2,813
Reaction score
1,416
Yes, but they were using includes. In way you're doing this, it's rather impossible/useless.

PHP:
<?php 
$page = $_GET['action'];
if (!empty($page) && file_exists('./includes/'.$page.'.php')) )
{
   $file = './pages/'.$page.'.php';
}
else
{
   $file = './pages/404.php';
}
include $file;
?>
 
Experienced Elementalist
Joined
Mar 22, 2008
Messages
297
Reaction score
0
So that don't work, okay.
Again, thanks allot for the help.
 
duck you, I'm a dragon
Loyal Member
Joined
Apr 29, 2005
Messages
6,405
Reaction score
130
Aww, all my extensive research was futile. :sad:
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
You can do it that way, but I would recomment against. Why would you want to put every page in one single file? What advantage would that have? I can only think of disadvantages.

Instead, make a top.php and bottom.php and include those for every page. You can, however, merge pages that a very much like eachother...but thats not what you have for simply site's like these.
 
Custom Title Activated
Loyal Member
Joined
Aug 8, 2004
Messages
3,892
Reaction score
20
if(isset($_GET['action'] == "scripts"))
A slight sidenote: this makes no sense whatsoever. ($_GET['action'] == "scripts") will always evaluate as either true or false since it is a boolean operation, and false is considered to be set. As such this should always return true - were it not for the compiler who'll throw a syntax error.

What you actually meant to write:
PHP:
if(isset($_GET['action'] && $_GET['action'] == "scripts"))

However since in PHP a comparison between a not-set variable is save, you can also shorten that to simply:
PHP:
if($_GET['action'] == "scripts")


All that being said, the way you've set up your site at the moment is ridiculous. One big file will take forever to load parse since it has to open all the code that isn't even used, no to mention you're mixing all your PHP and HTML in one file. Try looking into include() and require() :smile:
 
duck you, I'm a dragon
Loyal Member
Joined
Apr 29, 2005
Messages
6,405
Reaction score
130
I really shouldn't be phping when tired, makes me do all kinds of crazy things. :sad:
 
Experienced Elementalist
Joined
Mar 22, 2008
Messages
297
Reaction score
0
You can do it that way, but I would recomment against. Why would you want to put every page in one single file? What advantage would that have? I can only think of disadvantages.

Instead, make a top.php and bottom.php and include those for every page. You can, however, merge pages that a very much like eachother...but thats not what you have for simply site's like these.

That's what i am doing now, since i noticed that having everything in on page gets really messed up i switched to the include method. But i will use both methods.

like: i have resources.php but i have ?action=photoshop, ?action=dreamweaver and so on.
 
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,376
Reaction score
50
Ok, thanks allot both of you!

Since you're l33t in php i have on more question; i've seen ppl having 404's. like if you go to hazzan.110mb.com/index.php?action=some_page_that_doesn't_exist a 404 shows up.

Maybe you know how to make that to? :)

try to consider .htaccess error page rewrites.
 
Back
Top