hide link help on php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

hide link help on php

Post by bonty89 »

Guyz I wanna know how to add like this on link (php)

eg: http://www.websitename.net/index.php?mode=register

can any1 help pls ... thanks
:wink:
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: hide link help on php

Post by davex »

Sorry - not quite sure what you mean?

Do you mean you want a popup "hint" to come up when a user mouses over a link?

Code: Select all

<A HREF="http://www.somesite.com/" TITLE="Popup Text Goes Here">Here is the link</A>
Cheers,

Dave.
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

Re: hide link help on php

Post by bonty89 »

I wanna know how set variable on the Index.php file

eg: when user click to login
it should display like this
http://www.anywebsite.org/index.php?action=login

similar to this forum login link
ucp.php?mode=login
register
ucp.php?mode=register

how to write like that
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: hide link help on php

Post by davex »

Hi,

Oh - ok.

Well you do it exactly like that!

For example:

Code: Select all

<A HREF="login.php?first=1&second=2">Click Here</A>
Would call the PHP file login.php with two variables: $_REQUEST['first'] equal to 1 and $_REQUEST['second'] equal to 2.

This is known as the query string - everything contained after the ?. I would suggest you have a read through one of the many excellent PHP tutorials either on a site like this or on http://www.php.net.

But just to give you a very quick example of how this would work - imagine the following script called index.php:

Code: Select all

<?php
if (isset($_REQUEST['name'])) echo "Hello ".$name."<br /><br />";
?>
<A HREF="index.php?name=bonty89">Click here to set the name to bonty89</A><br /><br />
 
<FORM ACTION="index.php" METHOD="GET">
Name: <INPUT TYPE="TEXT" NAME="name"> <INPUT TYPE="submit" VALUE="Or Enter a Name and Click Here">
</FORM>
This will set the name either by clicking a link or entering in a form and then say hello to that name.

I would strongly recommend you work through some of the tutorials before developing though as this will allow you to learn how to deal the language and variables etc in a good way and avoid any future pitfalls.

Regards,

Dave.
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

Re: hide link help on php

Post by bonty89 »

davex wrote:Hi,

Oh - ok.

Well you do it exactly like that!

For example:

Code: Select all

<A HREF="login.php?first=1&second=2">Click Here</A>
Would call the PHP file login.php with two variables: $_REQUEST['first'] equal to 1 and $_REQUEST['second'] equal to 2.

This is known as the query string - everything contained after the ?. I would suggest you have a read through one of the many excellent PHP tutorials either on a site like this or on http://www.php.net.

But just to give you a very quick example of how this would work - imagine the following script called index.php:

Code: Select all

<?php
if (isset($_REQUEST['name'])) echo "Hello ".$name."<br /><br />";
?>
<A HREF="index.php?name=bonty89">Click here to set the name to bonty89</A><br /><br />
 
<FORM ACTION="index.php" METHOD="GET">
Name: <INPUT TYPE="TEXT" NAME="name"> <INPUT TYPE="submit" VALUE="Or Enter a Name and Click Here">
</FORM>
This will set the name either by clicking a link or entering in a form and then say hello to that name.

I would strongly recommend you work through some of the tutorials before developing though as this will allow you to learn how to deal the language and variables etc in a good way and avoid any future pitfalls.

Regards,

Dave.
thanks

but my requirement is
eg:
<A HREF="index.php?name=bonty89">Click here to set the name to bonty89</A><br /><br /> it should display bonty89 html page or php page

eg2: <A HREF="index.php?name=bontyhelp">help Click here to set the name to bonty89 help</A><br /><br /> it should display bontyhelp html page or php page

how to set or write like that ???

see this site http://www.dushyanth.com/
all the links starting from index.php? action=
but loading different pages

need help

thanks
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: hide link help on php

Post by davex »

Ok...

First a full disclaimer - allowing files to be opened and executed from a variable is a potential big security hole. You should take very special care that you are only opening the files that you want. In the example below I am using an array to avoid manual file/path overloading but even so make sure everything is sanitised which the example below isn't!

Assume you have a directory called "modules" in there you have two files:

one.php

Code: Select all

<h1>One</h1>
two.php

Code: Select all

<h1>Two</h1>
Then in your main directory you have an index.php like:

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
if ( (isset($_POST['module'])) // if the module variable is present
 {
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 }
?>
Hope that is what you are after.

Regards,

Dave.
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

Re: hide link help on php

Post by bonty89 »

davex wrote:Ok...

First a full disclaimer - allowing files to be opened and executed from a variable is a potential big security hole. You should take very special care that you are only opening the files that you want. In the example below I am using an array to avoid manual file/path overloading but even so make sure everything is sanitised which the example below isn't!

Assume you have a directory called "modules" in there you have two files:

one.php

Code: Select all

<h1>One</h1>
two.php

Code: Select all

<h1>Two</h1>
Then in your main directory you have an index.php like:

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
if ( (isset($_POST['module'])) // if the module variable is present
 {
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 }
?>
Hope that is what you are after.

Regards,

Dave.
thanx but :? :? :? :?

Parse error: syntax error, unexpected T_VARIABLE on line 5
Parse error: syntax error, unexpected '{' in on line 10
Last edited by bonty89 on Fri Mar 05, 2010 12:29 pm, edited 2 times in total.
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: hide link help on php

Post by davex »

Sorry typo:

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
if (isset($_POST['module'])) // if the module variable is present
 {
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 }
?>
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

Re: hide link help on php

Post by bonty89 »

davex wrote:Sorry typo:

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
if (isset($_POST['module'])) // if the module variable is present
 {
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 }
?>
still Parse error: syntax error, unexpected '{' in on line 10
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: hide link help on php

Post by davex »

Sorry but parses fine for me.

Haven't copied any newlines in by accident? Comments appear on the same line as code.

The typo was an extra ( on line 9 but my update and your quote don't have that.

Not sure what is causing it.

Cheers,

Dave.
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

Re: hide link help on php

Post by bonty89 »

bonty89 wrote:
davex wrote:Sorry typo:

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
if (isset($_POST['module'])) // if the module variable is present
 {
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 }
?>
still Parse error: syntax error, unexpected '{' in on line 10
Parse error: syntax error, unexpected T_VARIABLE in line 05

but

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 
?>
works

but links not working

<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />

both the links redirecting to index.php :( :( :( :(
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

Re: hide link help on php

Post by bonty89 »

bonty89 wrote:
bonty89 wrote:
davex wrote:Sorry typo:

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
if (isset($_POST['module'])) // if the module variable is present
 {
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 }
?>
still Parse error: syntax error, unexpected '{' in on line 10
Parse error: syntax error, unexpected T_VARIABLE in line 05

but

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 
?>
works

but links not working

<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />

both the links redirecting to index.php :( :( :( :(

Code: Select all

<HTML><BODY>
<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />
<?php
$modules = array(
 "one" => "one.php",
 "two" => "two.php" );
 
if (isset($_POST['module'])) // if the module variable is present
 {
 if (isset($modules[$_POST['module']])) // if the module is listed in the array
  {
  include_once "modules/".$modules[$_POST['module']];
  }
 else // illegal module not in array
  {
  echo "Illegal Module Specified!";
  }
 }
?>
[/quote]

but

works

but links not working

<A HREF="index.php?module=one">Module One</A> | <A HREF="index.php?module=two">Module Two</A>
<HR><BR />

both the links redirecting to index.php :( :( :( :(
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: hide link help on php

Post by davex »

Hi,

Have you created the module files in the module directory?

The page will still be index.php but the different module pages will be displayed as in the example you originally gave.

Cheers,

Dave.
bonty89
Forum Newbie
Posts: 8
Joined: Sun Feb 28, 2010 1:35 am

Re: hide link help on php

Post by bonty89 »

davex wrote:Hi,

Have you created the module files in the module directory?

The page will still be index.php but the different module pages will be displayed as in the example you originally gave.

Cheers,

Dave.
assume that we running from the root

what will be the code !!! thanks
davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: hide link help on php

Post by davex »

From my post above:
Ok...

First a full disclaimer - allowing files to be opened and executed from a variable is a potential big security hole. You should take very special care that you are only opening the files that you want. In the example below I am using an array to avoid manual file/path overloading but even so make sure everything is sanitised which the example below isn't!

Assume you have a directory called "modules" in there you have two files:

one.php

Code: Select all

<h1>One</h1>


two.php

Code: Select all

<h1>Two</h1>
Create a directory called modules and put in it files one.php and two.php - they will be included when selected.

Cheers,

Dave.
Post Reply