{"id":21496745,"url":"https://github.com/alaeddinejebali/ajax-php-token","last_synced_at":"2026-04-25T22:32:34.285Z","repository":{"id":75772056,"uuid":"94818451","full_name":"alaeddinejebali/ajax-php-token","owner":"alaeddinejebali","description":"AJAX implementation with PHP using a secure token","archived":false,"fork":false,"pushed_at":"2017-08-18T09:27:37.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T02:40:33.898Z","etag":null,"topics":["ajax","php","token"],"latest_commit_sha":null,"homepage":null,"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/alaeddinejebali.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":"2017-06-19T20:33:19.000Z","updated_at":"2017-08-18T09:23:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"f226d0d5-d208-4e7b-877e-5ae27a7d62de","html_url":"https://github.com/alaeddinejebali/ajax-php-token","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alaeddinejebali/ajax-php-token","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaeddinejebali%2Fajax-php-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaeddinejebali%2Fajax-php-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaeddinejebali%2Fajax-php-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaeddinejebali%2Fajax-php-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alaeddinejebali","download_url":"https://codeload.github.com/alaeddinejebali/ajax-php-token/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alaeddinejebali%2Fajax-php-token/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32279654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"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":["ajax","php","token"],"created_at":"2024-11-23T16:18:28.279Z","updated_at":"2026-04-25T22:32:34.280Z","avatar_url":"https://github.com/alaeddinejebali.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AJAX implementation with PHP using a secure token\n\n## server.php\n\n```php\n\u003c?php\n  session_start();\n  $token = md5(rand(1000,9999)); //you can use any encryption\n  $_SESSION['token'] = $token; //store it as session variable\n?\u003e\n```\n## file.php\n```php\n\u003c?php\nsession_start();\n\nif($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {\n\t//Request identified as ajax request\n\tif(@isset($_SERVER['HTTP_REFERER']) \u0026\u0026 $_SERVER['HTTP_REFERER']==\"http://yourdomain/ajaxurl\"){\n\t\t//HTTP_REFERER verification\n\t\tif($_POST['token'] == $_SESSION['token']) {\n\t\t\t//do your ajax task\n\t\t\t//don't forget to use sql injection prevention here.\n\t\t}\n\t\telse {\n\t\t\theader('Location: http://yourdomain.com');\n\t\t}\n\t}\n\telse {\n\t\theader('Location: http://yourdomain.com');\n\t}\n}\nelse {\n\theader('Location: http://yourdomain.com');\n}\n?\u003e\n```\n\n## script.js\n```javascript\nvar formData = {\n\tdata: $(\"#data\").val(), //your data being sent with ajax\n\ttoken:'\u003c?php echo $token; ?\u003e', //used token here.\n\tis_ajax: 1\n};\n\n$.ajax({\n\ttype: \"POST\",\n\turl: 'yourajax_url_here',\n\tdata: formData,\n\tsuccess: function(response){\n\t\t//do further\n\t}\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaeddinejebali%2Fajax-php-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falaeddinejebali%2Fajax-php-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falaeddinejebali%2Fajax-php-token/lists"}