Jump to content

[SOLVED] Making a site with ?action=...


Marius B

Recommended Posts

Hello.

 

As you see, I'm new here.

I started to look at websites and thought like: "Woah. Now I really want to learn PHP and CSS"

So I got some friends of me to help me get started.

 

But there is something I really want to know.

 

I don't get how people make the http://www.domain.com/index.php?action=blabla

As you see I made the ?action=blablabla bold.

That's what I'm wondering about.

 

Some help would be appreciated.

Link to comment
Share on other sites

Would it be possible to load another page with the GET method?

 

Example:

 

I'm on my index.php, and I'm pressing a button which will lead you to contact.php.

Instead of going to contact.php, would it be possible to like load the content from contact.php with this?

index.php?page=contact

Link to comment
Share on other sites

yes of course you could check at the top of your page similar to this...

 

<?php
if($_GET['page'] == 'contact')
{
     include("contact.php");
}
else
{
    //otherwise load default page
    include("default.php");
}

Link to comment
Share on other sites

Marius B

 

There are different application states, GET is one of them. Using GET allows you to submit data to a webserver for processing or simply maintain data from one page to another. However, there are limitations, that is using GET, you can only send a certain amount of data. I don't know the exact number about 300 something characters in the url. Also your data is clearly visible, so you would not send password using GET.

 

 

 

Link to comment
Share on other sites

I tried to add the code Bendude14 posted.

But my page keeps refreshing and then apache doesn't respond.

I know why it does, because it will check every time the site refresh.

Where should I add this code?

 

I added this right under <body>

 

	<?php
	if($_GET['page'] == 'home')
	{
		include("index.php");
	}
	else if($_GET['page'] == 'band')
	{
		include("band.php");
	}
	else if($_GET['page'] == 'media')
	{
		include("media.php");
	}
	else if($_GET['page'] == 'tour')
	{
		include("tour.php");
	}
	else if($_GET['page'] == 'releases')
	{
		include("releases.php");
	}
	else if($_GET['page'] == 'contact')
	{
		include("contact.php");
	}
	else
	{
		include("index.php");
	}
?>

Link to comment
Share on other sites

I tried to add the code Bendude14 posted.

But my page keeps refreshing and then apache doesn't respond.

I know why it does, because it will check every time the site refresh.

Where should I add this code?

 

I added this right under <body>

 

	<?php
	if($_GET['page'] == 'home')
	{
		include("index.php");
	}
	else if($_GET['page'] == 'band')
	{
		include("band.php");
	}
	else if($_GET['page'] == 'media')
	{
		include("media.php");
	}
	else if($_GET['page'] == 'tour')
	{
		include("tour.php");
	}
	else if($_GET['page'] == 'releases')
	{
		include("releases.php");
	}
	else if($_GET['page'] == 'contact')
	{
		include("contact.php");
	}
	else
	{
		include("index.php");
	}
?>

 

Add the code where you want to include those pages.  I.e if you were going to make a menu that would be the same on every page, you would want to put that block under the code for the menu

You could also look at a switch statement instead of using all those else..if (just my personal preference)

Link to comment
Share on other sites

Sorry, but I didn't understand what you were pointing to.

This is my code so far.

I bet all of you can see my problem now:

 

<html>
<link rel="stylesheet" type="text/css" href="./style.css" />
<head>
	<title>
		Marius' Page
	</title>
</head>
    
<?PHP
$toswitch = $_GET['page'];
switch($toswitch){
	case 'home':
		include("index.php");
	break;

	case 'band':
		include("band.php");
	break;

	case 'media':
		include("media.php");
	break;

	case 'tour':
		include("tour.php");
	break;

	case 'releases':
		include("releases.php");
	break;

	case 'contact':
		include("contact.php");
	break;

	default:
		include("index.php");
	break;
}
?>

<body>
	<div id="top"></div>
	<div id="banner">
		<img src="banner.png" alt="Banner"/>
	</div>
	<div id="bunn"></div>

	<div id="top"></div>
	<div id="menu">
		<p>
			<a href="index.php?page=home">Home</a> | 
			<a href="index.php?page=band">Band</a> | 
			<a href="index.php?page=media">Media</a> | 
			<a href="index.php?page=tour">Tour</a> | 
			<a href="index.php?page=releases">Releases</a> | 
			<a href="index.php?page=contact">Contact</a>
		</p>
	</div>
	<div id="bunn"></div>

	<div id="top"></div>
	<div id="main">
		<div id="tekst">
			Text
		</div>
	</div>
	<div id="bunn"></div>
</body>

</html>

Link to comment
Share on other sites

It's commonly used with database. Say you have multiple pages of information, all somewhat the same format.

 

 

for example a member profile page.

 

 

blabla.php?user=fred

 

then you can make a sql query using $_GET['user'] (which would = fred) and get all the information on fred providing how you set the variables on the page.

 

Although beware, as any user can manipulate the URL, there are security issues which should be looked up and taken care of in order to well secure your url and sql queries...

Link to comment
Share on other sites

Sorry, but I didn't understand what you were pointing to.

This is my code so far.

I bet all of you can see my problem now:

 

<html>
<link rel="stylesheet" type="text/css" href="./style.css" />
<head>
	<title>
		Marius' Page
	</title>
</head>
    
<?PHP
$toswitch = $_GET['page'];
switch($toswitch){
	case 'home':
		include("index.php");
	break;

	case 'band':
		include("band.php");
	break;

	case 'media':
		include("media.php");
	break;

	case 'tour':
		include("tour.php");
	break;

	case 'releases':
		include("releases.php");
	break;

	case 'contact':
		include("contact.php");
	break;

	default:
		include("index.php");
	break;
}
?>

<body>
	<div id="top"></div>
	<div id="banner">
		<img src="banner.png" alt="Banner"/>
	</div>
	<div id="bunn"></div>

	<div id="top"></div>
	<div id="menu">
		<p>
			<a href="index.php?page=home">Home</a> | 
			<a href="index.php?page=band">Band</a> | 
			<a href="index.php?page=media">Media</a> | 
			<a href="index.php?page=tour">Tour</a> | 
			<a href="index.php?page=releases">Releases</a> | 
			<a href="index.php?page=contact">Contact</a>
		</p>
	</div>
	<div id="bunn"></div>

	<div id="top"></div>
	<div id="main">
		<div id="tekst">
			Text
		</div>
	</div>
	<div id="bunn"></div>
</body>

</html>

 

What you have now is a code that will include the information before the page.

 

The easiest way would be to put the switch statement where you want the included page to go.

 

In your code, I would imagine the information should go into the main section or like this:

 

<html>
<link rel="stylesheet" type="text/css" href="./style.css" />
<head>
	<title>
		Marius' Page
	</title>
</head>
<body>
	<div id="top"></div>
	<div id="banner">
		<img src="banner.png" alt="Banner"/>
	</div>
	<div id="bunn"></div>

	<div id="top"></div>
	<div id="menu">
		<p>
			<a href="index.php?page=home">Home</a> | 
			<a href="index.php?page=band">Band</a> | 
			<a href="index.php?page=media">Media</a> | 
			<a href="index.php?page=tour">Tour</a> | 
			<a href="index.php?page=releases">Releases</a> | 
			<a href="index.php?page=contact">Contact</a>
		</p>
	</div>
	<div id="bunn"></div>

	<div id="top"></div>
	<div id="main">
<?PHP
$toswitch = $_GET['page'];
switch($toswitch){
	case 'home':
		include("index.php");
	break;

	case 'band':
		include("band.php");
	break;

	case 'media':
		include("media.php");
	break;

	case 'tour':
		include("tour.php");
	break;

	case 'releases':
		include("releases.php");
	break;

	case 'contact':
		include("contact.php");
	break;

	default:
		include("index.php");
	break;
}
?>
		<div id="tekst">
			Text
		</div>
	</div>
	<div id="bunn"></div>
</body>

</html>

 

But I really don't know what those sections are for, so put it where you want, but as soon as that php code runs, it gets put into page.

Link to comment
Share on other sites

It's commonly used with database. Say you have multiple pages of information, all somewhat the same format.

 

 

for example a member profile page.

 

 

blabla.php?user=fred

 

then you can make a sql query using $_GET['user'] (which would = fred) and get all the information on fred providing how you set the variables on the page.

 

Although beware, as any user can manipulate the URL, there are security issues which should be looked up and taken care of in order to well secure your url and sql queries...

Ah, I see.

Thanks for the information.

And thanks to bmw2213, syed and bendude14 for additional information.

 

* Marked as solved *

Link to comment
Share on other sites

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.