Author Topic: PHP Assistance Required  (Read 15299 times)

Sqthreer!

  • Hero Member
  • *****
  • Posts: 733
  • It's hip to be sq3r.
    • View Profile
    • Sqthreer.com
PHP Assistance Required
« on: January 03, 2008, 07:54:46 PM »
I'm an absolute beginner at PHP, and I'm trying to finish up this stupid-ass website for someone I know so I don't have to bother with it anymore.

Here's the setup I've got right now:

I have an index.php file with three includes in it; one for the header, one for the main page content, and one for the footer, and that's it.

When you visit the site, the index file includes header.php, home.php and footer.php. A very basic situation indeed.

My question is this: how would I modify regular HTML links in order to get them to replace whatever page you're on with a new one?

Example: You're on the home page (home.php), and you click a link to go to the contact page (contact.php). I obviously can't just make the link to contact.php, otherwise it will only load that page, and not the header or footer. I only want to put contact.php where home.php is.

This is probably the simplest of simple questions, and I really just want the easiest way to do it because I seriously do not want to have this crappy project on my plate anymore. I'm not interested in restructuring the site (unless I fucked up somehow and I'd have to to make this work).

I don't know any PHP functions so that makes it kinda hard to search for a tutorial on such a thing.
« Last Edit: January 03, 2008, 08:24:12 PM by Sqthreer! »
"Floors are a lot like walls."
 - Alexxx

Bobbias

  • #1 Poster
  • Hero Member
  • *****
  • Posts: 7210
  • 404 Avatar not found.
    • View Profile
    • Magnetic Architect
Re: PHP Assistance Required
« Reply #1 on: January 03, 2008, 08:00:40 PM »
What you do is send them back to index.php with a post action telling it to load contact.php

Instead of index.php automatically loading the contact page, you make an if statement check if it has been given a page to load from post, and if not, then load the normal content. I hope this makes sense to you, but I don't feel like writing out some code at the moment.
This is going in my sig. :)

BANNED FOR BAD PUNS X_x

Sqthreer!

  • Hero Member
  • *****
  • Posts: 733
  • It's hip to be sq3r.
    • View Profile
    • Sqthreer.com
Re: PHP Assistance Required
« Reply #2 on: January 03, 2008, 08:14:12 PM »
Unfortunately it makes no sense to me :[

Maybe saying I'm a PHP beginner was an exaggeration. A PHP beginner is someone who is actively trying to learn PHP, and has some limited knowledge on the subject already. Literally, all I remember from the hour or so I spent researching PHP from about a year ago is how to include pages. As far as vocab or syntax, I know nothing. My coding capabilities reach about as far as my copy and paste abilities do.
"Floors are a lot like walls."
 - Alexxx

Spectere

  • \m/ (-_-) \m/
  • Administrator
  • Hero Member
  • *****
  • Posts: 5716
  • printf("%s\n", "Hi!");
    • View Profile
    • spectere.net
Re: PHP Assistance Required
« Reply #3 on: January 03, 2008, 09:21:21 PM »
The easiest way to do this is to do something like the following:

Code: [Select]
<?php

include 'header.php';

switch(
$_GET['page']) {
  case 
"contacts":
    include 
'contacts.php';
    break;
  case 
"links":
    include 
'links.php';
    break;
  default:
    include 
'home.php';
}

include 
'footer.php';

?>

Basically, you continue to add other conditions (i.e. the case lines) that include other PHP files.  To link the pages together, use the following: http://www.mysite.com/mypages/index.php?page=somepage

Replace "somepage" with the page that you actually want to link to (one of the ones with case statements).  If it doesn't match any of the given case statements it'll just load the home page so people can't break it in horrific ways.

Apologies if there are any inaccuracies.  I really don't like PHP so I've gotten kind of rusty at it.
"This is a machine for making cows."

Sqthreer!

  • Hero Member
  • *****
  • Posts: 733
  • It's hip to be sq3r.
    • View Profile
    • Sqthreer.com
Re: PHP Assistance Required
« Reply #4 on: January 03, 2008, 10:05:12 PM »
Once again, my hero, Superpectereman has saved the day!!

Thank you, it worked stupendously.

And thank you as well, Bobbias. If I was more motivated to learn PHP I might have been able to understand your advice.
"Floors are a lot like walls."
 - Alexxx

Spectere

  • \m/ (-_-) \m/
  • Administrator
  • Hero Member
  • *****
  • Posts: 5716
  • printf("%s\n", "Hi!");
    • View Profile
    • spectere.net
Re: PHP Assistance Required
« Reply #5 on: January 03, 2008, 10:43:56 PM »
Wow, it seriously worked with little to no effort?  Damn, I'm good. ;)

Glad I could help!
"This is a machine for making cows."

Sqthreer!

  • Hero Member
  • *****
  • Posts: 733
  • It's hip to be sq3r.
    • View Profile
    • Sqthreer.com
Re: PHP Assistance Required
« Reply #6 on: January 03, 2008, 11:11:00 PM »
Indeed it did! I just used my well-developed ctrl+c/ctrl+v technique and it worked like a big shiny charm.

I guess you're not as rusty as you though :o
"Floors are a lot like walls."
 - Alexxx

Spectere

  • \m/ (-_-) \m/
  • Administrator
  • Hero Member
  • *****
  • Posts: 5716
  • printf("%s\n", "Hi!");
    • View Profile
    • spectere.net
Re: PHP Assistance Required
« Reply #7 on: January 03, 2008, 11:28:26 PM »
Perhaps not.  Then again, PHP is sort of similar to C in some ways...with about a bazillion lame, kludgey features added, not to mention several configuration options that cause half of your scripts to break, inconsistent naming conventions, and...well, let's just say it's painful for me to even wrap my head around it. :P  But I think I'll save all of that for another rant.
"This is a machine for making cows."

Bobbias

  • #1 Poster
  • Hero Member
  • *****
  • Posts: 7210
  • 404 Avatar not found.
    • View Profile
    • Magnetic Architect
Re: PHP Assistance Required
« Reply #8 on: January 04, 2008, 01:21:21 AM »
Haha, yeah, but at least PHP looks nice, visually. I described more or less what Spectere wrote, I was just tired and lazy. I've got my own web development stuff I'm working on at the moment, and I've been putting a lot of effort into getting it to work right. Let it suffice to say that turning an integrated system into a fully fledged web server is not an easy process. I've learned more about linux in the past week then I probably ever knew.
This is going in my sig. :)

BANNED FOR BAD PUNS X_x

Spectere

  • \m/ (-_-) \m/
  • Administrator
  • Hero Member
  • *****
  • Posts: 5716
  • printf("%s\n", "Hi!");
    • View Profile
    • spectere.net
Re: PHP Assistance Required
« Reply #9 on: January 04, 2008, 11:17:13 AM »
PHP would look nice if it actually made sense.  There are so many exceptions to the rule in that language that it's hard to tell what's going on sometimes.  Aside from the inconsistent naming conventions, many functions are called in completely different ways.  It's not like we're talking about third-party addons here; this is all first-party work that doesn't line up.

The lack of namespace support is also very lame.  Because they literally have thousands of functions associated with the language, it's quite easy to run into collisions with other functions.  Namespaces would have made their OO design much easier to work with.

It's just an unmitigated disaster of a programming language.  They clearly didn't put a whole lot of thought into future planning when they designed it.  It might be easy to learn at the beginning, but I know after I worked with it for a while I found it to be hard to tolerate.
"This is a machine for making cows."

Bobbias

  • #1 Poster
  • Hero Member
  • *****
  • Posts: 7210
  • 404 Avatar not found.
    • View Profile
    • Magnetic Architect
Re: PHP Assistance Required
« Reply #10 on: January 04, 2008, 03:21:38 PM »
I was just talking about comparing it to say, Perl, visually. It looks nice, but it has all those issues behind it. I agree the namespaces and more organization in general would REALLY help, though.
This is going in my sig. :)

BANNED FOR BAD PUNS X_x

Spectere

  • \m/ (-_-) \m/
  • Administrator
  • Hero Member
  • *****
  • Posts: 5716
  • printf("%s\n", "Hi!");
    • View Profile
    • spectere.net
Re: PHP Assistance Required
« Reply #11 on: January 04, 2008, 07:52:36 PM »
Perl looks like noise but, really, it makes a lot of sense if you understand the language.  It's kind of a strange thing.

PHP has potential, but I think at this point it basically needs a VB.NET-esque revamp to make it tolerable for me.  While VB6 might not be a very good language, at least it's generally pretty consistent with a lot of things.  PHP is all over the map with its naming conventions.  And, like I said, the fact that making a simple change to your configuration file can break your code is a real bummer.  It must be hell for the programmers behind massive projects like phpBB, SMF, Joomla, PHPNuke, Invision, etc, simply because they literally have to write code for every type of scenario imaginable.
"This is a machine for making cows."

Sqthreer!

  • Hero Member
  • *****
  • Posts: 733
  • It's hip to be sq3r.
    • View Profile
    • Sqthreer.com
Re: PHP Assistance Required
« Reply #12 on: January 04, 2008, 09:56:43 PM »
u guys ar smarter den me :((((
"Floors are a lot like walls."
 - Alexxx

Spectere

  • \m/ (-_-) \m/
  • Administrator
  • Hero Member
  • *****
  • Posts: 5716
  • printf("%s\n", "Hi!");
    • View Profile
    • spectere.net
Re: PHP Assistance Required
« Reply #13 on: January 04, 2008, 11:34:23 PM »
No, just nerdier. =(
"This is a machine for making cows."

Sqthreer!

  • Hero Member
  • *****
  • Posts: 733
  • It's hip to be sq3r.
    • View Profile
    • Sqthreer.com
Re: PHP Assistance Required
« Reply #14 on: January 04, 2008, 11:58:12 PM »
Psh, what's the difference?
"Floors are a lot like walls."
 - Alexxx