Jump to content

Ques for Making Links


evilgenius

Recommended Posts

Hi,

 

I'm quite new to PHP, and need help with making links for my new website.

 

If there are two page

1- Index.php

2- contact.php

 

What do I have to do to make them appear like, www.sitename.com/index.php?action=contact

 

Thanks in advance for any help

Link to comment
Share on other sites

everything after a questionmark ( ? ) is in the global $_GET-Array.

So if you say:

<?php
   if (isset($_GET['action'])) { //action set?
      if ($_GET['action'] == 'contact') { //does action has the value contact?
         require 'contact.php'; //bind contact.php
      }
   }
?>

Link to comment
Share on other sites

Here is what I would do, and it allows you to add pages as you wish:

 

<?php

$action= $_GET['action'];

if (isset($action)) {
include "$action.php";
} else {
include "home.php";
}

?>

 

Make your link just as you stated, then it will set action from the url as a variable "$action". From that you include the correct page, if action isn't set, then it includes a home page. You can do a lot with this basis.

Link to comment
Share on other sites

thanks

 

Im quite new with php so can you please help me, how would I fit in the code with this

 

<span class="style22">Comments and suggestion are welcome, please [b]Contact Us[/b] and lets know what you think of Funmasti. </span><br>

 

with contact us.

 

thanks

Link to comment
Share on other sites

If you use the code I put for you, you would just simply do this:

 

<span class="style22">Comments and suggestion are welcome, please [b]<a href="index.php?action=contact">Contact Us</a>[/b] and lets know what you think of Funmasti. </span><br>

 

This will link you to - www.____.com/index.php?action=contact  which will be your index page and include the contact wherever you place that bit of code. ( or any page you want to link like this, which is how you do templates )

Link to comment
Share on other sites

What you said is that you want the contact page pulled in to the index page, when you click a link such as 'contact us'. You use the first code that I posted to pull the contact page in, if it is set in the url. The code pulls in home.php if nothing is set, if it is set, it pulls in whatever it is set to. You can easily make it work only if action = contact.

 

<?php

$action= $_GET['action'];

if ($action == contact) {
include "contact.php";
}

?>

 

The link you have on your site now will cause this script to include contact.php wherever you place it.

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.