Hello.
There was a problem, it is not possible to use the GET request in this part of the code (when you click on the link, it should be translated to the site.ru/lesson.php?id=1 page, but opens the error page (ie, the not_found () function is turned on))

$query = mysqli_query($connect, "SELECT * FROM `lessons` WHERE `teachid` = '".$_SESSION['id']."' "); while ($row = mysqli_fetch_assoc($query)) { $haslesson = TRUE; echo " <br> <a href='lesson.php?id=".$row['id']."'><p>".$row['title']."</p></a><br> "; } 

As I myself assume, most likely it's in .htaccess, or in my index.php

.htaccess:

 AddDefaultCharset utf-8 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] 

The part of the index.php code in which you also need to fix something

 if($_SERVER['REQUEST_URI'] == '/') $page ='home'; else { $page = substr($_SERVER['REQUEST_URI'], 1); if(!preg_match('/^[A-z0-9]{3,40}$/', $page) ) not_found(); } $connect = mysqli_connect('localhost', 'root', '', 'qschool'); if (!$connect) { exit('MySQL error'); } session_start(); if ( file_exists('all/'.$page.'.php')) include 'all/'.$page.'.php'; else if ( $_SESSION['id'] and file_exists('auth/'.$page.'.php')) include 'auth/'.$page.'.php'; else if ( !$_SESSION['id'] and file_exists('guest/'.$page.'.php')) include 'guest/'.$page.'.php'; else not_found(); 

I know that there are plenty of such questions here, but all my attempts were in vain.
I hope for help. thank
PS I'm almost sure that you need to change the preg_match and add something to .htaccess

  • and what debag shows? - N. Turshiev
  • and here is your where? "I can't get a GET request" You seem to have a Super Global SESSION variable in sq - Farkhod Daniyarov
  • Sorry, I do not fully understand what you mean by "debag" .. The browser console does not show errors - D. Joe
  • Should translate to site.ru/lesson.php?id=1 - D. Joe
  • @ D.Joe do you use IDE when developing? or write in a notebook? If isp. IDE then your code can be run and check how and what works, what variables are assigned and what generally happens inside your code. There you can see what comes into the code from global arrays. - N. Turshiev

1 answer 1

In .htaccess replace

 RewriteRule ^(.*)$ index.php?/$1 [L] 

on

 RewriteRule ^ index.php [L,QSA] 

In index.php

 $page = substr($_SERVER['REQUEST_URI'], 1); if(!preg_match('/^[A-z0-9]{3,40}$/', $page) ) not_found(); 

on

 if (preg_match('/^\/([a-z0-9]{3,40})(\?.*)?$/i', $_SERVER['REQUEST_URI'], $matches)) { $page = $matches[1]; } else { not_found(); } 
  • It helped! Thank you so much) - D. Joe