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

  • SEARCH
  • Home
  • 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 6199265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:09:31+00:00 2026-05-24T04:09:31+00:00

I am a beginner to PHP and i want to make a static method

  • 0

I am a beginner to PHP and i want to make a static method that if its argument is empty it’ll show the message. If not, it’ll set the given message to a static variable for later use. But when i call the method to set the message, and then call it in another page to show the message. Nothing appear.

Here’s my portion of code for this “session.php” :

   class Session {

            public static $message; 


            public static function notify($message = ""){
                if(!empty($message)){
                    self::$message = $message;                    
                } else {                        
                    return self::$message;
                }
            }
}

    $session = new Session();

“add_user.php” :

<?php       
    require_once '../helper/session.php';       
?>

<?php
    if (isset($_POST["submit"])) {        

        $user->username = $_POST["username"];
        $user->password = $_POST["password"];
        $user->first_name = $_POST["first_name"];
        $user->last_name = $_POST["last_name"];
        if($result = $user->add_user()){
            Session::notify("New user added");
            redirect_to("../view/login.php");
        } else { Session::notify("Cannot add new user"); }

    }
?>

“login.php” :

<?php 
    require_once "../control/add_user.php";
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <link rel="stylesheet" href="../stylesheet/login.css" />
        <title>Welcome to Harmony</title>
    </head>

    <body>
        <header>
            <h2>Harmony</h2>
        </header>

        <section>
            <div id="formStyle">
                <h3>Login or Signup:</h3>
                <form action="login.php" method="post">

                    <p><label for="username">Username: </label>
                        <input type="text" name="username" value="" placeholder="Username"/></p>

                    <p><label for="password">Password: </label>
                        <input type="text" name="password" value="" placeholder="Password"/></p>

                    <input type="submit" name="submit" value="Submit" />
                    <input type="button" name="sign_up" value="Sign up" onClick="parent.location='add_user.php'">
                </form>
                            <?php echo Session::notify();  ?>
            </div>
        </section>
    </body>
</html>
  • 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-05-24T04:09:32+00:00Added an answer on May 24, 2026 at 4:09 am

    You aren’t really writing to the session, now are you?
    You should create two more methods for getting and setting the variables in the actual session. After the redirect, your message dissapears, because it is only saved on script execution.

    function set_notification($message) {
    $_SESSION['notification'] = $message; }
    function get_notification() {
    if(!empty($_SESSION['notification'])) {
    return $_SESSION['notification']; }
    

    Something like that 🙂

    Of course, for sessions to work, you should do a session_start() call in the beginning of the script. read more about them here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a topic that, as a beginner to PHP and programming, sort of
i m the beginner in iphone programming i want to make an application which
I am editing somebody else's code and I am a PHP beginner. I want
I am beginner in PHP and i read in manual that $_REQUEST is a
I am php beginner and I am trying to make e-commerce by using php.
I want to create a site in php such that, when user would login
Am Newbie here.Am Beginner in php.I Create a sample Reg form.Here i want to
I'm a beginner with PHP security issues. Someone reported a security issue with my
i'm a beginner to php. i need to use php function which process some
I am a PHP beginner. I have developed a social networking website similar 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.