Jump to content


Photo

larger code on one page, or spread out(bottom of post)


  • Please log in to reply
13 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 October 2006 - 01:53 PM

I have been trying to think of a way to create a function, where at the beginning of the pages, where I am doing compact programs, with a lot of stuff, where variables can be get, or post, or a combination.  I am trying to setup something to take all post, adn get variables and change them to regular variables.
If I do this is it going to work the way I need, with out any issues, I just thought of it.

If I go to the top of the page, that I need it done at, and put

<?php
session_start(); // I use sessions some so I have to have this
extract($_POST);
extract($_GET);
extract($_SESSION);
extract($_ENVIROMENT);
extract($_SERVER);
?>
this wasn't very realistic, I wouldn't have a need to do this all the time, or use all of these at once, but I was wondering, for instance, if I had a lot of post's and get's coming to the page, along with some sessions, and I wanted to make all of them regular variables.  Would this work

For instance if I have 2 sessions
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
for instance
and they are registered, then on the page, that has the active sessions, in comes 3 get variables
$_GET['hello'];
$_GET['what'];
$_GET['decide'];
Those 3 are coming in for instance, then if I put

<?php
session_start();
extract($_SESSION);
extract($_GET);
?>
Would I then be able to get to sessions and other variables directly, is this safe.
The last, and main question, if it's safe, why haven't I ever seen anyone else do this before?

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 October 2006 - 02:00 PM

This is not safe. Basically what your doing is coding in register_gloabls without register_globals being on. You;re pretty much simulating register_globals being on.

Also if you have a say a get and sessions variable with the same name. Then one or the other will overwrite the other.

Why do you want to us normal variables rather than use the superglobals. If you use the superglobals you wont have to worry about your variables being overwritten and your app will be much safer.

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 October 2006 - 02:04 PM

I normally do like that, but I am starting to try to build a larger cms, without as many pages.

Someone told me the more pages the less the abilities or something.
I wanted to try to use programming logic to do as much as I can on one page, using a status variable and other stuff
but when I have a lot of different get's coming it's hard to keep up with.

EDIT
What about this
if ($_GET['status']) {
$status = $_GET['status'];
}elseif ($_POST['status']) {
$status = $_POST['status'];
}

I have seen even other programmers do things like this, in a tightly packed program.
Is this going to be safe.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 October 2006 - 02:12 PM

To make it safe you first want to check that satus is not set in POST and GET at the same time.
// check that status is only set in either GET or POST and not both!
if(isset($_GET['status']) && isset($_GET['staus']))
{
    die('Hacking attempt');
}
elseif(isset($_GET['status']))
{
    $status = $_GET['status'];
}
elseif(isset($_POST['status']))
{
    $status = $_POST['staus']
}
else
{
    $status = 'Defualt value';
}


#5 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 October 2006 - 02:19 PM

is
if (isset($_GET['status']) {
$status = $_GET['status'];
}elseif (isset($_POST['status']) {
$status = $_POST['status']) {
}

Is that the same as
if ($_GET['status']) {
$status = $_GET['status'];
}elseif ($_POST['status']) {
$status = $_POST['status'];
}
Are those 2 things, the same thing actually.
Meaning do they function the same, and I will keep in mind about what you said as far as checking for the hacking attempt.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 October 2006 - 02:24 PM

No they are not the same. The following:
if ($_GET['status']) {
$status = $_GET['status'];
}elseif ($_POST['status']) {
$status = $_POST['status'];
}

Doesnt check for the existance of the variable, but checks whether $_GET['status'] is either true (it will return true if it holds a boolean, string, numeric value etc) or false. Where as if(isset($_GET['status'])) checks whether the variable exists and not the value

You should use isset for check whether a variable exists, never if($_GET['status'])



#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 October 2006 - 02:26 PM

Someone told me the more pages the less the abilities or something.


That's complete rubbish.
Legend has it that reading the manual never killed anyone.
My site

#8 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 October 2006 - 02:33 PM

That is not good, because I have been doing it that way for a long time, on all my older projects, what problems can that pose later on down the road.

Also when it comes down to the thing he told me
so if I can have a program done, and I end up doing it in 17 pages, I redo it in 2 pages, it's no better than the one on 17 pages??

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 09 October 2006 - 03:20 PM

please your telling us that all the code you see on here that you have not valadated you $_GET method that outrageus.

if you dont valadate a $_GET[''] within a comming link then your codes are all flawed for emaple a user can change and acces all users information buy adding the required infromation to the link.

//a quick example
link example
<?php

echo"<a href='members.php?id=$id&name=$name&password=$password&cmd=access'>go to members page</a>";

//The link has got a condition that is cmd = access then do the get otherwise pee off hacker.  

?>


members.php
<?php

if(isset($_GET['cmd']=="access")){

$id=$_GET['id'];
$name=$_GET['name'];
$password=$_GET['password'];

echo " hi there your in <br> $id <br> $name <br> $password<br>";

}else{

echo "go away hacker";

}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 October 2006 - 03:21 PM

Ok, I will take care of that then, thanks.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#11 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 October 2006 - 03:41 PM

Someone told me the more pages the less the abilities or something.

That's complete rubbish.

That, I asked

Also when it comes down to the thing he told me
so if I can have a program done, and I end up doing it in 17 pages, I redo it in 2 pages, it's no better than the one on 17 pages??

I am confused now, so it isn't true that the lower number of pages taken to do something the better.
Can someone explain this some, I was always trying to fit as much programming as humanly possible on one page, instead of multiple pages, what is a good medium, this is somethign I really wondering about now.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#12 miseleigh

miseleigh
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 09 October 2006 - 06:14 PM

The number of pages your code uses has nothing to do with how well or how quickly it runs.  The only reason someone may have told you that is if you tend to add in a lot of extra code that doesn't actually do anything.  For example, the two snippets here will run exactly the same, despite the extra whitespace and comments, and one of them is a lot more readable:

if ($_GET['status']) {
$status = $_GET['status'];
}elseif ($_POST['status']) {
$status = $_POST['status'];
}

//Something about what this if statement is for

if ($_GET['status']) {
     $status = $_GET['status'];
}

elseif ($_POST['status']) {
     $status = $_POST['status'];
}

Your 2 page version probably does run faster than your 17 page version, because the only way you could get rid of those 15 extra pages is by taking out a whole lot of stuff that the computer didn't need to be doing.  But it's not the number of pages that made the difference, it's the number of calculations and the amount of memory needed to do them.  I don't know how to optimize php at all, cuz I don't do anything that really needs it, but I'm sure you could find stuff on Google if you really wanted to know how to make your scripts either run faster or use less memory.

#13 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 09 October 2006 - 06:20 PM

It doesnt matter how many files you use. You can code a whole app in just one file if you want. However this file will be huge and have tons of lines of code. Hard to debug, edit etc.

Having multiple files is much easier to handle. As you can easily find what you wnat to edit. Rather than opening up your big file and go where is that function or whatever.

#14 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 09 October 2006 - 08:56 PM

ah, thanks.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users