Jump to content
SomeoneSpecial99

[Help] Making a main index page

Recommended Posts

Im trying to create a index file for my site that receives arguments like this: "someonespecial99.com/?p=pagenamehere"

The thing i need help with is getting the ?p= function, Can anyone help me with this please? thx

Share this post


Link to post
Share on other sites

Good evening,

 

So you want to be able to display certain pages depending on $_GET variables passed via URL?

 

Kind regards,

 

Lab.

Share this post


Link to post
Share on other sites

Good evening,

 

So you want to be able to display certain pages depending on $_GET variables passed via URL?

 

Kind regards,

 

Lab.

Yes :)

Share this post


Link to post
Share on other sites

A simple example is to include a file:

 

simply:

 

include $_GET['p'] . '.php';

 

For security, there are restrictions, a simple way to restrict is to only allow a few names:

if(!isset($_GET['p']) {    $_GET['p'] = '';}switch($_GET['p']) {    case '';    case 'home':      include 'home.php';    break;    case 'about':        include 'about.php';    break;    case 'contact':        include 'contact.php';    break;    default:        // Send a 404 Not Found header        header('HTTP/1.0 404 Not Found');        include '404.php';}

Share this post


Link to post
Share on other sites

A simple example is to include a file: simply:

include $_GET['p'] . '.php';
For security, there are restrictions, a simple way to restrict is to only allow a few names:
if(!isset($_GET['p']) {    $_GET['p'] = '';}switch($_GET['p']) {    case '';    case 'home':      include 'home.php';    break;    case 'about':        include 'about.php';    break;    case 'contact':        include 'contact.php';    break;    default:        // Send a 404 Not Found header        header('HTTP/1.0 404 Not Found');        include '404.php';}

Sorry, Im still kinda new at php so I have 1 problem that has arose This is the code i used:

<?phpinclude $_GET['q'] . '.php';if(!isset($_GET['q']) {  // $q=$_GET["q"];    $_GET['q'] = '';}switch($_GET['q']) {    case '';    case 'home':      include 'home.html';    break;    case 'about':        include 'about.php';    break;    case 'contact':        include 'contact.php';    break;    default:        // Send a 404 Not Found header        header('HTTP/1.0 404 Not Found');        include '404.php';}?>

And this is the error (DreamWeaver said syntax error aswell)

Parse error: syntax error, unexpected '{' in /home/someone1/public_html/index.php on line 3

Any help please?

 

btw: this file is currently hosted at http://www.someonespecial99.com/index.php

Edited by SomeoneSpecial99

Share this post


Link to post
Share on other sites

if(!isset($_GET['q']) {

in this line of the code there is a missing ")" :

 

it should be:

 

if(!isset($_GET['q'])) {

Edited by astralaaron

Share this post


Link to post
Share on other sites

I forgot a closing parenthesis, as astralaaron pointed out.

 

It was an easy mistake to find, given the error messages. Learning to debug error messages on your own is an important skill. It tells you exactly where the error is occurring so you can look there and see what's wrong.

Share this post


Link to post
Share on other sites

if(!isset($_GET['q']) {in this line of the code there is a missing ")" : it should be: if(!isset($_GET['q'])) {

 

I forgot a closing parenthesis, as astralaaron pointed out. It was an easy mistake to find, given the error messages. Learning to debug error messages on your own is an important skill. It tells you exactly where the error is occurring so you can look there and see what's wrong.

 

Ok, now that I have raged at my debugging failure xD (I could see that problem but not see it ~_~)
I had a bug where the import occurred twice, But out of self debugging fixed it,
Thanks for all the help ;)

Share this post


Link to post
Share on other sites

Good evening,

 

Have you got it working?

 

Kind regards,

 

Lab.

Share this post


Link to post
Share on other sites

Good evening, Have you got it working? Kind regards, Lab.

Hi Lab,Yes, I have managed to get it fully working as expected,Thanks for the help everyone ;P

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...