{"id":28167957,"url":"https://github.com/qaiswardag/php-rest-api-with-token-authentication-for-tasks-management","last_synced_at":"2026-02-05T07:32:30.231Z","repository":{"id":141546594,"uuid":"470305742","full_name":"qaiswardag/php-rest-api-with-token-authentication-for-tasks-management","owner":"qaiswardag","description":"PHP REST API with token authentication for Tasks Management application.","archived":false,"fork":false,"pushed_at":"2024-10-24T18:56:42.000Z","size":49,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T14:14:28.217Z","etag":null,"topics":["authentication","javascript","php","rest-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qaiswardag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-15T19:35:29.000Z","updated_at":"2024-11-08T11:20:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"4bc8623b-ff78-4150-9347-730965ae1f0a","html_url":"https://github.com/qaiswardag/php-rest-api-with-token-authentication-for-tasks-management","commit_stats":null,"previous_names":["qaiswardag/php-rest-api-with-token-authentication-for-tasks-management"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/qaiswardag/php-rest-api-with-token-authentication-for-tasks-management","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qaiswardag","download_url":"https://codeload.github.com/qaiswardag/php-rest-api-with-token-authentication-for-tasks-management/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29115550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T05:31:32.482Z","status":"ssl_error","status_checked_at":"2026-02-05T05:31:29.075Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","javascript","php","rest-api"],"created_at":"2025-05-15T14:14:27.971Z","updated_at":"2026-02-05T07:32:30.209Z","avatar_url":"https://github.com/qaiswardag.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP REST API with Token Authentication for Tasks Management\n\nThis repository contains a PHP-based REST API with token authentication, designed to manage tasks. It follows a token-based authentication method to ensure secure access to the API endpoints.\n\n## Features\n\n- **Token-based Authentication:** Secure authentication mechanism using tokens.\n- **Task Management:** Create, update, and delete tasks through API requests.\n- **Error Handling:** Custom error messages and HTTP status codes for better debugging and client interaction.\n- **Preflight Requests (CORS):** Handles preflight `OPTIONS` requests for cross-origin resource sharing (CORS).\n\n## Prerequisites\n\n- **PHP 7.2+**\n- **MySQL/MariaDB** for the database\n- **Composer** to manage dependencies\n- A web server like Apache or Nginx\n\n## Setup\n\n1. Clone the repository:\n\n    ```bash\n    git clone https://github.com/your-username/php-rest-api-with-token-authentication-for-tasks-management.git\n    ```\n\n2. Install dependencies:\n\n    ```bash\n    composer install\n    ```\n\n3. Set up the database:\n\n    Import the provided SQL file to create the necessary tables in your database.\n\n    ```bash\n    mysql -u username -p database_name \u003c path/to/sqlfile.sql\n    ```\n\n4. Configure the database connection in `db.php`:\n\n    ```php\n    \u003c?php\n    class DB {\n        private static $writeDBConnection;\n        \n        public static function connectWriteDB() {\n            if (self::$writeDBConnection === null) {\n                self::$writeDBConnection = new PDO('mysql:host=localhost;dbname=your_database;charset=utf8', 'your_user', 'your_password');\n                self::$writeDBConnection-\u003esetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n                self::$writeDBConnection-\u003esetAttribute(PDO::ATTR_EMULATE_PREPARES, false);\n            }\n            return self::$writeDBConnection;\n        }\n    }\n    ```\n\n5. Run the API on your local server or configure it on a production server.\n\n## Endpoints\n\n### User Registration\n\n- **URL:** `/register`\n- **Method:** `POST`\n- **Request Body:** JSON\n\n    ```json\n    {\n        \"fullname\": \"John Doe\",\n        \"username\": \"john123\",\n        \"password\": \"yourPassword\"\n    }\n    ```\n\n- **Response:**\n\n    - Success: `201 Created`\n    - Error: `400 Bad Request` | `409 Conflict` (if username exists)\n\n```php\n\u003c?php\n\nrequire_once 'db.php';\nrequire_once '../model/response.php';\n\n// Database connection setup and validation logic here\n\n// Sample user registration handling\nif ($_SERVER['REQUEST_METHOD'] === 'POST') {\n    $rawPostData = file_get_contents('php://input');\n    if ($jsonData = json_decode($rawPostData)) {\n        if (isset($jsonData-\u003efullname, $jsonData-\u003eusername, $jsonData-\u003epassword)) {\n            $fullname = trim($jsonData-\u003efullname);\n            $username = trim($jsonData-\u003eusername);\n            $password = password_hash($jsonData-\u003epassword, PASSWORD_DEFAULT);\n            \n            try {\n                $query = $writeDB-\u003eprepare('SELECT id FROM tblusers WHERE username = :username');\n                $query-\u003ebindParam(':username', $username, PDO::PARAM_STR);\n                $query-\u003eexecute();\n                \n                if ($query-\u003erowCount() \u003e 0) {\n                    $response = new Response();\n                    $response-\u003esetHttpStatusCode(409);\n                    $response-\u003esetSuccess(false);\n                    $response-\u003eaddMessage('Username already exists');\n                    $response-\u003esend();\n                } else {\n                    $query = $writeDB-\u003eprepare('INSERT INTO tblusers (fullname, username, password) VALUES (:fullname, :username, :password)');\n                    $query-\u003ebindParam(':fullname', $fullname, PDO::PARAM_STR);\n                    $query-\u003ebindParam(':username', $username, PDO::PARAM_STR);\n                    $query-\u003ebindParam(':password', $password, PDO::PARAM_STR);\n                    $query-\u003eexecute();\n                    \n                    $response = new Response();\n                    $response-\u003esetHttpStatusCode(201);\n                    $response-\u003esetSuccess(true);\n                    $response-\u003eaddMessage('User created successfully');\n                    $response-\u003esend();\n                }\n            } catch (PDOException $ex) {\n                error_log('Database error: ' . $ex);\n                $response = new Response();\n                $response-\u003esetHttpStatusCode(500);\n                $response-\u003esetSuccess(false);\n                $response-\u003eaddMessage('Internal server error');\n                $response-\u003esend();\n            }\n        } else {\n            $response = new Response();\n            $response-\u003esetHttpStatusCode(400);\n            $response-\u003esetSuccess(false);\n            $response-\u003eaddMessage('Incomplete user data');\n            $response-\u003esend();\n        }\n    }\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqaiswardag%2Fphp-rest-api-with-token-authentication-for-tasks-management/lists"}