ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

Anyone on here know php?



  172 FF
Hello, Im stuck on a project im doing for uni. I have never done php before so im a real novice. anyway to the point I cant seem to get session's working on it and if anyone knows anything it'll be a real bonus!
 

KDF

  Audi TT Stronic
Its not a difficult language to learn.. there is also a new php-gtk extension which will (in simple terms) allow you to write stand alone grapihcal programs.
 

sn00p

ClioSport Club Member
  A blue one.
make sure you put session_start() before anything is output (even whitespace) otherwise it'll be b0rked.
 
  172 FF
<?php
Session_start();
$_Session['LoggedOn'] = 'False';
//Print $_Session['LoggedOn'];
session_register('LoggedOn');

$UsrIDVar = $_POST['UsrID'];
$Psswd = $_POST['Psswd'];
Include("connection.php");

$query = "select * from logon where UsrID = '$UsrIDVar' AND Psswd = '$Psswd'";

$dbresult = mysql_query ($query, $dblink);
$count=mysql_num_rows($dbresult);
$row = mysql_fetch_array ($dbresult);

//print ("{$row["Psswd"]}\n");
if($count==1){

$_Session['LoggedOn'] = 'True';


//$_Session['UsrName'] = $UsrIDVar;
Header("location:Menu.php?Alevel={$row["Alevel"]}");
//Print $_Session['LoggedOn'];
//Print $_Session['UsrName'];

} Else {
Header("location:Index.php");
//$_Session['LoggedOn'] = "False";

}

?>
// this is my login page that the user name and password is submitted
 

sn00p

ClioSport Club Member
  A blue one.
Yeek! Can you say "SQL Injection"?

I know it's only a UNI project, but you should use:

mysql_real_escape_string()

On any data you use from the outside world in a query.
 

KDF

  Audi TT Stronic
What version of PHP are you using ? is register globals turned on of off?

If you use session_register() and globals is turned off it will not work.

Globals are turned off by default since IIRC PHP4


As sn00p said, in the real world you would be vulenerable to SQL injection attacks. Use what he recommeded or use a PHP function to strip the bad stuff out..
 

KDF

  Audi TT Stronic
Code:
<?php
// Start our session
session_start();
$_SESSION['LoggedOn'] = 'False';

// REQUIRE this as failed include would break the script !
require("connection.php");

// Use HTMLentities to prevent injection of code
$UsrIDVar = htmlentities($_POST['UsrID']);
$Psswd = htmlentities($_POST['Psswd']);

$query     = "SELECT * FROM logon WHERE UsrID = '$UsrIDVar' AND Psswd = '$Psswd'";
$dbresult  = mysql_query($query, $dblink);
$count     = mysql_num_rows($dbresult);
$row       = mysql_fetch_array($dbresult);

if($count==1)
   {
   $_Session['LoggedOn'] = 'True';
   Header("location:Menu.php?Alevel={$row["Alevel"]}");
   } else {
   Header("location:Index.php");
   }
?>

Try that ...
 
  172 FF
I'm such a novice at this!! I have only been learning this about 5 weeks on and off. Never encountered web scripting before.

so when i use the code above on my menu page how do properly retieve the session data?

By the way you guys are stars for helping me!!!
 
Its not a difficult language to learn.. there is also a new php-gtk extension which will (in simple terms) allow you to write stand alone grapihcal programs.

Have you used gtk? I'm currently using gtk2 and finding it a bit hard to find good documentation for it :dapprove: Wondered if you knew anywhere.


The only session data in there is to check if the user is logged in or not. What more info are you wanting in the session? You can add more session variables by using the $row variable kdf has kindly set for you.

PHP:
$row       = mysql_fetch_array($dbresult);
If you want username in the session, use (if your username table field is called username, that is)
PHP:
if($count==1)
   {
   $_SESSION['LoggedOn'] = 'True';
   $_SESSION['username'] = $row['username'];
   Header("location:Menu.php?Alevel={$row["Alevel"]}");
   } else {
   Header("location:Index.php");
   }
?>
 
  172 FF
yeah i was gonna add a username varible and make it display it in the rest of the site, also futher into my project i have to use session varibles to add multiple rows into the database however to collect the data it need to be a session varible not just a normal varible. I have tried everything i have found on the internet so far to help me but i cant get the session varibles once the header has loaded the new page. it just seems to loose them or im not retieving them correclty (more than like the second one).
 
To retrieve the variables, you need to make sure session_start() is called at the top of the page. try using print_r($_SESSION) to see what session data is getting transferred. You can call/echo the session vars by using
PHP:
echo $_SESSION['username']
etc
 

sn00p

ClioSport Club Member
  A blue one.
Have you used gtk? I'm currently using gtk2 and finding it a bit hard to find good documentation for it :dapprove: Wondered if you knew anywhere.

It is all there on the php gtk website (http://gtk.php.net).

However, if you've never written a program for an event based OS (like gtk, windows, carbon etc) then it's going to be a bit of a shock to the system.

Maybe a good read up on the standard "C" GTK api might give you a bit more flavour of how it all works, plenty of tutorials on the web.
 
  172 FF
I get this error when i put session_start(); on the menu.php
"Fatal error: Call to undefined function start_session() in D:\mysqlwork\xampp\htdocs\Menu.php on line 1"
 

sn00p

ClioSport Club Member
  A blue one.
I get this error when i put session_start(); on the menu.php
"Fatal error: Call to undefined function start_session() in D:\mysqlwork\xampp\htdocs\Menu.php on line 1"

That's because it should be session_start()
 
  172 FF
yeah on my menu.php i have
"<?php start_session();
print_r($_SESSION) ;
echo $_Session['LoggedOn'];?>"
and it wont work?
 
Have you used gtk? I'm currently using gtk2 and finding it a bit hard to find good documentation for it :dapprove: Wondered if you knew anywhere.

It is all there on the php gtk website (http://gtk.php.net).

However, if you've never written a program for an event based OS (like gtk, windows, carbon etc) then it's going to be a bit of a shock to the system.

Maybe a good read up on the standard "C" GTK api might give you a bit more flavour of how it all works, plenty of tutorials on the web.

Yeah I've never written anything like this before, I'll take a look at C. Still learning OOP :eek:
 
  172 FF
thanks i will? saying that do you know if you can have an array in a session varible ive been looking on the internet and i cant seem to find anything?
 

KDF

  Audi TT Stronic
you can use a comma seperated list then use a function like explode() to put the values into an array.

there are many functions that deal with arrays.. for example you can create an array with implode()

You can check if a value is already in an array using in_array()
 
  Megane 230 R26
The "proper" way to store an array where it's not really designed to be stored, and to retrieve it again afterwards, is to use the serialize() and unserialize() functions.
 

KDF

  Audi TT Stronic
I only use serialize() for multi-dimensional arrays, but yes that will work too for storing arrays in sessions.
 

sn00p

ClioSport Club Member
  A blue one.
I use JSON for storing data quite often. The site I've just done (goes live on monday) for work uses it.

It's uber-convenient for transferring data between javascript and php and vice-versa as at each end it appears as a native "object".
 
  172 FF
ok this is what im wanting to do it might not make any sence but im so rubbish at this still i'm not getting anywhere and my project is due in in two weeks! right

I want to take 2 values posted from the page and use these values so that the page will loop and show the values from a database!

I'll try an explain better

I have a page say (page.php) i have 2 values summited from page.php to page.php. one of these values is an id for a record in a database. i then want to display the entire record not just the id on the same page. so that the user can just go down use the dropdown box to select which id he wants to add to. it must also carry a text field with the id. i need it to display more than one record until the user has selected all the relvant records. then the user selects a hyperlink that takes the user to another page that then inserts the id's of all the selected item and inserts them into the database.

most of this i can do but the array bit is still confusing me?
 


Top