Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:35:04+00:00 2026-06-17T12:35:04+00:00

This may be a stupid question but I have some code like: $userData =

  • 0

This may be a stupid question but I have some code like:

$userData = array_map('htmlentities', mysql_fetch_assoc(mysql_query(
    "SELECT * FROM `smf_members` 
    WHERE `id_member` = (SELECT `id_member` FROM `smf_log_online` WHERE `session` = '" . mysql_real_escape_string($session) . "')"
    )));

function printHeader() 
{
    $header = <<<eof
<!DOCTYPE html>
<html lang="en">
<head>
        ...
            <li><a href="#"><img src="images/avatar.gif" alt="" /> {$userData['member_name']}</a>
        ...
eof;
    echo $header;
}

That is in a file named config.php and is requireed in my index page like so:

<?php require 'config.php';printHeader(); ?>

However inside the printHeader() function $userData isn’t set, where as if I print_r($userData) in the global scope it is set. Do I need to put the rest of the “global” code in a constructor of sorts? Or am I missing something really small.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:35:05+00:00Added an answer on June 17, 2026 at 12:35 pm

    Use the global keyword.

    $userData = array_map('htmlentities', mysql_fetch_assoc(mysql_query(
        "SELECT * FROM `smf_members` 
        WHERE `id_member` = (SELECT `id_member` FROM `smf_log_online` WHERE `session` = '" . mysql_real_escape_string($session) . "')"
        )));
    
    function printHeader() 
    {
                global $userData;
    
        $header = <<<eof
    <!DOCTYPE html>
    <html lang="en">
    <head>
            ...
                <li><a href="#"><img src="images/avatar.gif" alt="" /> {$userData['member_name']}</a>
            ...
    eof;
        echo $header;
    }
    
    <?php require 'config.php';printHeader(); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a stupid question but I have a code with the following
Evening guys, This may seem like a stupid question but im having some issues
This may seem like a stupid Question but i have two cubes being rendered
This may be a stupid question, but I have to ask! I have the
This may sound like a stupid question but I can't seem to find an
This may sound like a stupid question but I'm a beginner not just to
This may sounds like a stupid question but can't find anything on google, probably
this may be a stupid question: I currently have some VM arguments that my
This question may seem stupid, but, so be it! I have a stupid problem
This may seem like a stupid question, but: So what i would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.