Jump to content

Very new to php- need help with creating pages like name.php?=test


Recommended Posts

I have almost no knowledge in PHP but willing to learn now. Right now I want to know how to pages with the links like www.domain.com/test.php?=test (so it hides the initial page link)

 

For example, you can see this done in

http://www.desi-nation.info

when you hover over the links of the channels. Any tutorial links or explanations here would be greatly appreciated.

 

Thank you.

test.php?test=whatever

 

does not "hide" any links

 

all that does is send the value "whatever" to the file "test.php"

 

and this value is accessed within test.php as $_GET['test'] the variable assigned in the url "test=whatever"

I have almost no knowledge in PHP but willing to learn now. Right now I want to know how to pages with the links like www.domain.com/test.php?=test (so it hides the initial page link)

 

I do this a bit in various pages, and the way I do it is basically this... Oh this is from a hidden, password protected database editing screen - the users only ever read the data on "static" pages, not write it, so I wanted a single page with, in this case, about 15 options including view, edit, delete and add to 2 different databases. Theres other ways to do it, but this works for me. Each option 1, 2 etc is basically a fully self-contained section other than a header & footer for the page.

 

<?php

 

//Common header items like checking database connectivity etc, laying out any default page layouts etc

//as well as lots of comments so I know what I was thinking when I come back months later lol.

 

$pid=$_GET['pid'];

 

//This gets the pid variable from the called page. In my case I  have about 15 value for it, and some

//pages also have secondary bits such as pid=3 below

 

 

if ($pid=='1') {

// Code for Page ID = 1

}

 

 

 

if ($pid=='2') {

//Code for Page ID = 2

}

 

 

if ($pid=='3') {

$alphindex = $_GET['alphindex'];

if ($alphindex==''){

// code for alphindex being blank

} else {

//code for a non blank alphindex

}

 

 

// Common footer section goes here before the end of the page

This is so called GET method of passing variables to a script.

 

Try

<?php

echo $_GET["txt"];
?>

 

save it as test.php and then point your browser to test.php?txt=foobar

A little confused.. where does the term "foobar" come from the code? Is there a tutorial link you can provide where I can start this from scratch.. it would be much appreciated.

 

Thanks.

I had a topic just like this, and there were a few replies, this was the best system i found to do it for on my site...depending how large your site is, or how in depth it gets you may need more than this. just copy this code to a blank page and try it out. save the page as pagetest.php and upload it.

 

 

 

<?php


$p = $_GET['p'];  //get the correct page id (p) from the URL

switch ($p) {  //begin switch, choose the right resulting page data

	default:   //this is the default, so whenever the page is loaded without an id, it displays this
	  echo '<a href="pagetest.php?p=hello"> HELLO</a><BR /><BR />';  
	  echo '<a href="pagetest.php?p=goodbye"> GOODBYE</a><BR /><BR />';
	 break;

	case "hello" :  //if the id is hello
	 echo 'Hello, and welcome to our page!';
	 break;

	case "goodbye" : //if the ?p= is goodbye
	 echo 'Thanks for coming, Goodbye!';
	 break;
} //end switch

?>

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.