Jump to content

Recommended Posts

The query string component of an URL starts with a question mark, and is normally followed by one or more name=value pairs, separated by ampersands. Those values can then be accessed in e.g. the PHP script, via $_GET['name']. In your example, a single name is only set, without any value. That could be useful if you only need a variable to be set or not set, regardless of any values. E.g.:

 

page.php?login

<?php
if (isset($_GET['login'])) {
//login page will be shown
}
?>

I have seen URLs that have a "?subject" added to the "page.php" part, and I was wondering what that did exactly, or what it meant?

 

(Sorry if this seems like a complete newbie question... I can't seem to find the answer just by googling it.)

 

like thebadbad said the value will be showen like this and you need to check if you "$_GET" anything:

<?php
if(isset($_GET['login'])){

echo "user login : ".$_GET['login'];

}

echo "<a href=\"?login=Blaatschaap\">test</a>";
?>

 

try that script self you also can use multi $_GET like this :

 

<?php
if(isset($_GET)){

$login = (isset($_GET['login']) ? $_GET['login'] : 'N/A');
$id = (isset($_GET['id']) ? $_GET['id'] : 'N/A');
$email = (isset($_GET['email']) ? $_GET['email'] : 'N/A');

echo "user login : ".$login."<br/>";
echo "user id : ".$id."<br/>";
echo "user email : ".$email;

}

echo "<a href=\"?login=Blaatschaap&id=13&email=norply@spam.no\">test</a>";
?>

 

~Blaatschaap

It can also allow you to partially create multiple webpages in one file..

 

Basically you can display different content with different requests in the url on one page. Comes in handy if you don't want a lot of files on your hosting to have multiple-web pages. No clutter. :)

It can also allow you to partially create multiple webpages in one file..

 

Basically you can display different content with different requests in the url on one page. Comes in handy if you don't want a lot of files on your hosting to have multiple-web pages. No clutter. :)

yup that's true then its handy to use switch also

 

~Blaatschaap

It can also allow you to partially create multiple webpages in one file..

 

Basically you can display different content with different requests in the url on one page. Comes in handy if you don't want a lot of files on your hosting to have multiple-web pages. No clutter. :)

 

You'd have a cluttered file? Personally if I were to pass the page name in like that I'd use templates, and a neat file structure.

It can also allow you to partially create multiple webpages in one file..

 

Basically you can display different content with different requests in the url on one page. Comes in handy if you don't want a lot of files on your hosting to have multiple-web pages. No clutter. :)

 

You'd have a cluttered file? Personally if I were to pass the page name in like that I'd use templates, and a neat file structure.

 

Well it depends how you set it up. To me I know exactly how I setup my pages so I always know what line to goto if need be to add a new entry, but that's just me. Beats editing a crap load of files.

Well in my line of work not as many as you would think people would do. Probably 20-30 pages minimal depends on what the file is meant for though.

 

Half of my pages I cut down with mysql queries & run half the page information from just a database which is just depending on the content again.

Something like:

 

switch($_GET['page'])
{
     case 1:
     $content = 'content 1';
     break;
     case 2:
     $content = 'content 2';
     break;
     default:
     $content = 'Default content..';
     break;
}

echo $content;

Ohh, okay. So how would I write the script to run multiple files in a single file?

Create 2 files content1.php and content2.php in same folder as index.php
This is index.php below
<html>
<head>
</head>
<body>
<a href="?page=content1">Content1</a><br>
<a href="?page=content2">Content2</a>
<?php
  if (isset($_GET['page']) && FileExists($_GET['page']) .'.php')){
     require_once($_GET['page']) .'.php');
  }else{
     echo 'Page requested not found.';
  }
?>
</body>
</html>

A common way I know of simply done is something like this

<html>
<head>
<title>My page contents!</title>
</head>
<body>
<?
if ($_GET['page'] == "news") {
?>
Hello, Lets talk about the news!
<?
}
elseif ($_GET['page'] == "cookies") {
?>
Cookies!
<?
} else  {
?>
Default homepage text here saying Ello! I am bruno!
<?
}
?>
</body>
</html>

i recommend this :

 

<a href="?p=home">Home</a> - <a href="?p=register">Register</a><br/>

<?php
$p = $_GET['p'];

switch($p)
{
     case "home":
     include "home.php";
     break;
     case "register":
     include "register.php";
     break;
     default:
     include "home.php";
     break;
}
?>

 

case "home" is like it gets ?p=home

try the script yourself!

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.