Ninjakreborn Posted October 9, 2006 Share Posted October 9, 2006 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<?phpsession_start(); // I use sessions some so I have to have thisextract($_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 workFor instance if I have 2 sessions$_SESSION['username'] = $username;$_SESSION['password'] = $password;for instanceand 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<?phpsession_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? Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/ Share on other sites More sharing options...
wildteen88 Posted October 9, 2006 Share Posted October 9, 2006 This is not safe. Basically what your doing is coding in register_gloabls without register_globals being on. You;re pretty much [i]simulating[/i] 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 [i]normal[/i] 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. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106238 Share on other sites More sharing options...
Ninjakreborn Posted October 9, 2006 Author Share Posted October 9, 2006 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 stuffbut when I have a lot of different get's coming it's hard to keep up with.EDITWhat about thisif ($_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. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106240 Share on other sites More sharing options...
wildteen88 Posted October 9, 2006 Share Posted October 9, 2006 To make it safe you first want to check that satus is not set in POST and GET at the same time.[code=php:0]// 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';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106248 Share on other sites More sharing options...
Ninjakreborn Posted October 9, 2006 Author Share Posted October 9, 2006 isif (isset($_GET['status']) {$status = $_GET['status'];}elseif (isset($_POST['status']) {$status = $_POST['status']) {}Is that the same asif ($_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. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106252 Share on other sites More sharing options...
wildteen88 Posted October 9, 2006 Share Posted October 9, 2006 No they are not the same. The following:[code=php:0]if ($_GET['status']) {$status = $_GET['status'];}elseif ($_POST['status']) {$status = $_POST['status'];}[/code]Doesnt check for the [b]existance[/b] 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 valueYou should use isset for check whether a variable exists, never if($_GET['status']) Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106255 Share on other sites More sharing options...
AndyB Posted October 9, 2006 Share Posted October 9, 2006 [quote author=businessman332211 link=topic=110953.msg449249#msg449249 date=1160402656]Someone told me the more pages the less the abilities or something.[/quote]That's complete rubbish. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106256 Share on other sites More sharing options...
Ninjakreborn Posted October 9, 2006 Author Share Posted October 9, 2006 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 meso 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?? Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106259 Share on other sites More sharing options...
redarrow Posted October 9, 2006 Share Posted October 9, 2006 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 [code]link example<?phpecho"<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<?phpif(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";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106288 Share on other sites More sharing options...
Ninjakreborn Posted October 9, 2006 Author Share Posted October 9, 2006 Ok, I will take care of that then, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106289 Share on other sites More sharing options...
Ninjakreborn Posted October 9, 2006 Author Share Posted October 9, 2006 [quote]Someone told me the more pages the less the abilities or something.That's complete rubbish.[/quote]That, I asked[quote]Also when it comes down to the thing he told meso 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??[/quote]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. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106305 Share on other sites More sharing options...
miseleigh Posted October 9, 2006 Share Posted October 9, 2006 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:[code]if ($_GET['status']) {$status = $_GET['status'];}elseif ($_POST['status']) {$status = $_POST['status'];}[/code][code]//Something about what this if statement is forif ($_GET['status']) { $status = $_GET['status'];}elseif ($_POST['status']) { $status = $_POST['status'];}[/code]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. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106395 Share on other sites More sharing options...
wildteen88 Posted October 9, 2006 Share Posted October 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106399 Share on other sites More sharing options...
Ninjakreborn Posted October 9, 2006 Author Share Posted October 9, 2006 ah, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/23426-larger-code-on-one-page-or-spread-outbottom-of-post/#findComment-106485 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.