[PHP] IF $_GET as startpage.
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 Code:
<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 Code:
<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.
Re: [PHP] IF $_GET as startpage.
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 Code:
<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 Code:
<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>
Re: [PHP] IF $_GET as startpage.
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
Re: [PHP] IF $_GET as startpage.
or try using this little line :P
If the $_GET variable doesn't exist it will automaticly execute the "Start" part
PHP Code:
$action = (isset($_GET['action']) ? $_GET['action'] : "Start");
PHP Code:
<?php
if($action == 'Photoshop') {
echo "This is the Photoshop page!
";
}
if($action == 'Scripts') {
echo "
This is the scripts page!
";
}
?>
PHP Code:
<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>
Re: [PHP] IF $_GET as startpage.
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? :)
Re: [PHP] IF $_GET as startpage.
Yes, but they were using includes. In way you're doing this, it's rather impossible/useless.
PHP Code:
<?php
$page = $_GET['action'];
if (!empty($page) && file_exists('./includes/'.$page.'.php')) )
{
$file = './pages/'.$page.'.php';
}
else
{
$file = './pages/404.php';
}
include $file;
?>
Re: [PHP] IF $_GET as startpage.
So that don't work, okay.
Again, thanks allot for the help.
Re: [PHP] IF $_GET as startpage.
Re: [PHP] IF $_GET as startpage.
Here's a tutorial on custom error messages. It might be still a bit too advanced for you though.
http://www.forum.ragezone.com/showthread.php?t=212603
Re: [PHP] IF $_GET as startpage.
That's not what he was actually asking for, $_GET will never go 404, when it's basically doing nothing but echoing..
Re: [PHP] IF $_GET as startpage.
Aww, all my extensive research was futile. :sad:
Re: [PHP] IF $_GET as startpage.
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.
Re: [PHP] IF $_GET as startpage.
Quote:
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 Code:
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 Code:
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:
Re: [PHP] IF $_GET as startpage.
I really shouldn't be phping when tired, makes me do all kinds of crazy things. :sad:
Re: [PHP] IF $_GET as startpage.
Quote:
Originally Posted by
Daevius
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.
Re: [PHP] IF $_GET as startpage.
Quote:
Originally Posted by
Illusion
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.
Re: [PHP] IF $_GET as startpage.
Useless, as index.php?something=something won't ever(when $_GET is assigned just to echoing something on same page) provide any error.. Are you even reading the thread before posting?