B
B
BlackWolf2018-02-22 16:45:25
PHP
BlackWolf, 2018-02-22 16:45:25

Why is it not reading the GET parameter?

The site currently has several sections. The user gets into profile.php?id=123 after successful authorization (per session). Using the profile.php?id=123 link, the user can view the profile of any other users (we get the data using a database query, sorted by $id.) For example, by writing ?id=1234 in the address bar. It reads like this:

include 'database.php';
if (isset($_GET['id'])) {
    $id = $_GET['id'];
  $url = "profile.php?id=$id";
  parse_url($url);
}

That is, everything is fine on the profile.php page. But in other sections of the site, $_GET is no longer readable.
Let's say a user decides to view another user's friends. From the main page, he went to friends.php?friends=$id. When you go to this page, the address bar contains the required $id (because profile.php?id=$id id is successfully read on the page). But when you try to read the $id on the friends.php?friends=$id page itself, it returns an empty request. The code is identical:
include 'database.php';
if (isset($_GET['id'])) {
    $id = $_GET['id'];
  $url = "friends.php?friends=$id";
  parse_url($url);
}

Why is this happening? Both pages with the same code, session_start() are registered, there is a connection to the database, but $_GET['id'] cannot be read on other pages. Thanks in advance for your reply.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2018-02-22
@blacknightwolf

friends.php?friends=$id
Because you don't have an id parameter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question