Page 1 of 1

Some one please explain me this part of code

Posted: Fri Jun 05, 2009 8:01 am
by dodgeqwe
I have completed PHP course , i know basics well .Im doing a case study on project to develop my PHP knowledge , if you have time, please explain me

$GET[a], why it is needed before logging in or doing a search in index page

1.why "a" is needed.
2.From where value is passed to "a"?

the above $GET[a] is repeated in many php pages on this project, i couldnt figure out , why?


if you need complete code,i could send you


Below is the some code of index page. Index page consist of book search and login section.

Code: Select all

 
<?php
session_start();
include 'conn.php';
 
ConnectDB();
$errMsg = "";
if ($_GET[a]=='2')
{
//$a="search.php?txtsearch=" . $_POST[txtsearch];
$a="search.php?cboCategory=" . $_POST[cboCategory];
$_SESSION[searchtext] = $_POST[txtsearch];
$_SESSION[searchauthor] = $_POST[txtauthor];
$_SESSION[searchbook] = $_POST[txtbook];
$_SESSION[cboCategory] = $_POST[cboCategory];
 
header("Location: $a");
}
 
if ($_GET[a]=='1')
{
 
$sql="select nUserId,cUserType from Users where

Re: Some one please explain me this part of code

Posted: Fri Jun 05, 2009 11:21 am
by kalebaustin
$_GET is how you 'get' data from the query string from a method=get form.

posting.php?f=1&t=101259

$_GET[f] would equal 1
$_GET[t] would equal 101259

$_POST is how you get data from method=post form

Re: Some one please explain me this part of code

Posted: Fri Jun 05, 2009 12:08 pm
by mikemike
$_GET variables come from your URL (the address bar). I'm guessing that in this case it stores the page that the user was trying to get to, but wasn't logged in, so this variables is passed using GET so when they do log in they don't have to re-navigate.

Re: Some one please explain me this part of code

Posted: Fri Jun 05, 2009 2:01 pm
by Darhazer
It's really bad code... the PHP interpretor will search for a constand, named "a", and after it do not find such, will assume that this is just a string, and will return the value of the "a" parameter from the URL

Also, it does not uses constants... so no one can tell you what '2' means, even the author of the code, and if for some reason you have to change this value, you have to change it in any place you are using it

Code: Select all

if ($_GET[a]=='2') // don't do this!!!