Jump to content

IF a link is clicked THEN do this?


hp1

Recommended Posts

Hi all, Just successfully (sort of) completed my first site. Its ok but maintenance heavy. I have a navigation window on the left with links in it. But because its an archive site I keep adding links meaning that I have to add the link to each HTML page that holds the menu. As I understand it, with PHP I could use IF THEN statements taht would do something like:IF this LINK is clickedTHENLoad this HTML (with external CSS) into this <DIV> and so on for each of the links and their associated HTML files. I could then do away with the HTML files because all the content stuff in them will all be contained within the PHP script to be loaded only when the appropriate link is clicked.Hope that makes sense. My problem is I dont know how to start! What function returns the TRUE or FALSE as to whether an <a href> tag has been clicked? I have managed to create a short mail() script that emails my form to me but that is the limit of my experience.Appreciate it if some of you wizard devs could help a newbie out. :) Cheers

Link to comment
Share on other sites

ok, so what you would need to do, is change all your links from stuff like "index.html" or "contact.html" to this: "index.php?page=index" and "index.php?page=contact" then in the php, you would do this:

<?phpif($_GET['page']='index'){echo "index page content here";}elseif($_GET['page']='contact'){echo "contact page content here";}?>

and so on...and you put that PHP code in the place where you usually put all the content.later, when you get into MySQL, you can store it in there, but I think this should work for you.

Link to comment
Share on other sites

ok, so what you would need to do, is change all your links from stuff like "index.html" or "contact.html" to this: "index.php?page=index" and "index.php?page=contact" then in the php, you would do this:
<?phpif($_GET['page']='index'){echo "index page content here";}elseif($_GET['page']='contact'){echo "contact page content here";}?>

and so on...and you put that PHP code in the place where you usually put all the content.later, when you get into MySQL, you can store it in there, but I think this should work for you.

Hey many thanks for the quick response, i'll start tinkering.
Link to comment
Share on other sites

oh, yeah, if you want to put the content for different pages in separate files, you could do that but it also brings up some security issues if someone changed ?page=index to ?page=secretpasswords and you have a file named secretpasswords.html, it would bring it up.

Link to comment
Share on other sites

ok, so what you would need to do, is change all your links from stuff like "index.html" or "contact.html" to this: "index.php?page=index" and "index.php?page=contact" then in the php, you would do this:CODE<?phpif($_GET['page']='index'){echo "index page content here";}elseif($_GET['page']='contact'){echo "contact page content here";}?>and so on...and you put that PHP code in the place where you usually put all the content.later, when you get into MySQL, you can store it in there, but I think this should work for yo
Sorry for the newbie questions but when you say change the links do you mean the bit in qoutes following <a href ="this bit here.html or do i change all my html files to php files?My rough code looks like this:
<html><head>stylesheet.css</head><body><div id=Frame><div id=menu></div><div id=content></div></div></body><html>

Ok so my other newbie question is where do the <?php and ?> tags go in realtion to the <divs> and where does the actual php code itself goes. Do i use one set of <?php and ?> or do I need lots of them for every IF statement.I dont think I have explained myself very well. Does someone have a VERY simple example of the code should look like based on a static menu in the left column and dynamic main column?Cheers

Link to comment
Share on other sites

<?php ?>goes inside the content page.If you have pages that needs security protection and you are the only one that goes into the pages then use : <?$ip = $REMOTE_ADDR;$me="yourip";if($ip!=$me){echo"No entry";exit();}?>..?>And no, you can also have $page.html.->Kristian_C.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...