Jump to content

Recommended Posts

Good day!

 

I'm not sure if this is the right part of the forum. If it's not, feel free to move my thread where it's supposed to be.

 

Anyway...

 

I've followed phpacademy's tutorial for building a login and register system. I want to extend it, but my problem is with how the system is designed. It's a lot of includes...anyone familiar with this tutorial?

For example, I want to be able to create a link where the widgets are different from the other pages but the includes makes this tough. I'm not sure how I should do this.

 

I realize I didn't specify what the problem is...hehe, sorry about that. 

 

Say we are at produktion.php.

 

In production I have included header.php, and header.php includes widget.php. These three .php files are included on every page to make the site look the same.

 

But when i go to produktion.php I want the widget-page to look different. Right now I'm using this code:

<div class="widget">
	<?php if ($_SERVER['REQUEST_URI'] === '/produktion.php') {
    include 'includes/widgets/produktion_widget.php';
} 

So if I'm currently on that page, It loads a different widget. Is this a good solution or bad?

Based on what I know of the tutorial, this should be fine.  Realistically all you are doing is defining a different include than the system usually uses, which is totally fine to do, it's common practice for such things.  The one thing I would change in the code above is how you are checking the url string, the method you are using is open to xss attacks.  I would switch it to this instead.

if ($_SERVER['SCRIPT_NAME'] === '/produktion.php')

I actually define a var at the beginning of my system that strips out the / and .php so I can simply check for the file name alone.  It also allows me to add this defined var to an id attribute for the body tag of each page in case I need to make a css change specific to that page as a whole.

define ("body_id", basename($_SERVER['SCRIPT_NAME'], ".php"));
echo body_id; // This is just so you can see what it returns for the defined above.
<head>
</head>
<body id="<?php  echo body_id; ?>">
//Content here
</body>

Just some examples and methods that allow for greater usage.

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.