Staredit Network > Forums > Technology & Computers > Topic: PHP Ongoing Assistance
PHP Ongoing Assistance
Mar 9 2008, 4:20 pm
By: InsolubleFluff
Pages: < 1 2 3 46 >
 

Mar 11 2008, 9:16 pm Centreri Post #21

Relatively ancient and inactive

That quiz is pretty much easy. I got a 90% without knowing C/Perl syntax, and a few of the other 'weird' questions that reference things outside PHP. I had like four of those. Not something to judge your power with PHP on.



None.

Mar 12 2008, 8:39 am (U)Bolt_Head Post #22



I just spent forever debugging and slaving over my code just to find out that functions do not use the same global variables unless defined that way.... ack.

Quesiton 1
I'm writing a generic file to edit a specific user's fields in the database. My goal is to be able to use it in a many places instead of separate file for each form or function. Right now it uses url variables accessed with $_GET to determan what table and what field is to be edited. The new value can either be from a form using $_GET or from a Session. My question is:
A) How can I detect where the php page was called from? I want to make sure it redirects back to the page it was called from.
B) I'm not concentrating much on security but I can for see this script being potentially very insecure. What are some easy ways to help keep the script from being used to tamper with my database?

Quesiton 2
Perhaps this should be question 1, but here goes. I'm working with two other guys on this project and most php appears as it should be all written into one file. How would i call a function in a different file?, Do you have to link to another file and then return like I mentioned above? Do you have any suggestions for working in groups?

Edit: I just read a summary about includes from the W3 page.... I think that will solve many of my problems... And i'm looking forward to experimenting with them, but for now I should sleep.

Post has been edited 4 time(s), last time on Mar 12 2008, 9:58 am by BoltHead.



None.

Mar 12 2008, 10:59 am Forsaken Archer Post #23



Quote
I think that will solve many of my problems
I'll answer anyways :}
1A. My go back to previous page code after login is this:
if ($p != "login") $_SESSION['visit'][0] = $_SERVER['REQUEST_URI'];
However, you'd have to modify it so that the ($p != "login") part is if (current page != post-form script).
Or. You could just write that in the form. <input type="hidden" name="go_here" value = "{$_SERVER['REQUEST_URI']}" />
php.net -- all $_SERVER values
2A. Make sure all your values are what you intend. I love ctype functions for basic checking. Like if you expect a value greater than 0 from a form, use if (isset($var) && $var > 0 && ctype_digit($v)).
Parse all sql characters as entities.
my basic $_POST cleaning
array_walk_recursive($_POST, 'html_clean');
function html_clean(&$v, $cookie=0)
{
    $v = trim($v);
    $v = htmlspecialchars($v, ENT_QUOTES, "ISO-8859-1", 0);  // ' " < >
    $v = preg_replace("/\%/", "%", $v);  // can be used in hex type xss attacks
    $v = preg_replace("#\\\#", "\", $v);  // kills sql
}


2. Just require("file.php") would give you access to all the functions in that file. If the functions are just written as functions, no part of a class, you'd just call them like you'd call any php function. If you write code outside of functions / classes, it would be executed at the time the file was required.
As far as working in groups, I got none. I'm really bad with this... I keep overwriting Moose's code. ;o



None.

Mar 12 2008, 4:26 pm InsolubleFluff Post #24



Quote from Centreri
That quiz is pretty much easy. I got a 90% without knowing C/Perl syntax, and a few of the other 'weird' questions that reference things outside PHP. I had like four of those. Not something to judge your power with PHP on.

I know they were easy, but I was just kidding :P

Today I am gonna try a little CSS but I think I have to go movies with girlfriend...



None.

Mar 14 2008, 5:09 am InsolubleFluff Post #25



Hey so I have been wondering. If I obtained the skin for the website me and my friends are making, how would you recommend we layout the page?
By this I mean, my friend suggests we use tables and my other friend suggests we use frames. However, from what I have acquired from SEN it includes neither frames and minimal tables. How would I make the site know what graphics to load and where? IP mentioned using "wrappers" which I kind of understood but would like further in-depth explanation of how to use a wrapper.
My general concern is making a clean layout with everything where I want it, and not extending beyond the boundaries I want it within.
Absolutely any suggestions on how to do this layout?



None.

Mar 14 2008, 8:41 am (U)Bolt_Head Post #26



Quote from Shocko
Hey so I have been wondering. If I obtained the skin for the website me and my friends are making, how would you recommend we layout the page?
By this I mean, my friend suggests we use tables and my other friend suggests we use frames. However, from what I have acquired from SEN it includes neither frames and minimal tables. How would I make the site know what graphics to load and where? IP mentioned using "wrappers" which I kind of understood but would like further in-depth explanation of how to use a wrapper.
My general concern is making a clean layout with everything where I want it, and not extending beyond the boundaries I want it within.
Absolutely any suggestions on how to do this layout?

SEN is loaded with tables, and as far as I'm concerned tables are your best friend :)
Frames on the other hand is the swear word of web development. From what i can tell there are several reasons why not to layout your page using them.
Most commonly it is mentioned that frames do not work well with browsers. You can't bookmark frame layouts and it many times messes up the back and forward options in the browser.

Anyways I would suggest using tables and you can mimic frame activity using the url variables and includes. I just did this with my site and i'm quite proud of the outcome.

Anyways on with my question..
Question 3
I don't know what the name of the variables you use $_GET is but I've been calling them URL variables lol. Anyways I'm curious if there is a better way to work with multiple variables when linking.
Say for an example I am currently at 'main.php?view=1' and I want to use an independent variable unrelated to view. Maybe my desired result is to go to 'main.php?view=1&action=3'.
Is there a simple way to append '&action=3' to the current url or should I use additional code to get the current url and add it to it?
I guess it is just a few easy steps but I'm curious if it gets easier or is the best way something like..
"currenturl" + "&action=3"
And then of course if 'action=3 is already in the url I don't want to add another..\

hope that makes since...

Shocko here is a sample of a test page I made. view is more likely a more suitable variable name than action.
Code
<?php
    $action =$_GET['action'];
?>

<html>
<head>
<title>Frame Test</title>
</head>
<body>

<table border=1 cellspacing=0 cellpadding=0 align=center width=90%>
    <tr>
    <td><!-- ** Cell 1 ** -->
        <b>Navagation</b>
    </td>
    <td><!-- ** Cell 2 ** -->
        <a href="?action=1">javascript1</a> |
        <a href="?action=2">javascript2</a> |
        <a href="?action=3">javascript3</a> |
        <a href="?action=4">javascript4</a>
    </td>
    </tr><tr>
    <td colspan=2><!-- ** Cell 3 ** -->
    <?php
        if($action == 1)
            require 'javascript1.html';
        if($action == 2)
            require 'javascript2.html';
        if($action == 3)
            require 'javascript3.html';
        if($action == 4)
            require 'javascript4.html';
    ?>
    </td></tr>
</table>
</body>
</html>


Post has been edited 2 time(s), last time on Mar 14 2008, 8:52 am by BoltHead.



None.

Mar 14 2008, 10:34 am Fierce Post #27



You may want to secure your inputs too from any mysql injections and what not.

Code
<?php
function secure($string) {
$string = strip_tags($string);
$string = htmlspecialchars($string);
$string = trim($string);
$string = stripslashes($string);
$string = mysql_real_escape_string($string);
return $string;
}
?>


Now all you need to do is have a..
Code
<?php
$username = secure($_POST['username']);
?>


Source: iScripting.net

So for example you could use:

--On index.html..
Code
<form action="login.php" method="post">
<input type="text" name="username" value="Username"><br />
<input type="password" name="password"><br />
<input type="submit" name="login" value="Login">
</form>


--On login.php
Code
<?php
$username = secure($_POST['username']);
$password = secure(sha1($_POST['password'])); // Includes sha1 encryption (very important)
echo ('Hello, ' . $username . '. Welcome to blah! You have successfully logged in.');
?>


Oh and BoltHead, you could also use switch:
Code
$act = secure($_GET['act']);
switch ($act) {
case "index":
   require("index.html");
   break;
case "page":
   require("page.html");
   break;
default:
   require("index.html");
   break;
}


It does the same thing as yours, but I believe it should be used more commonly.

Oh and to answer your question.. (which I'm pretty sure I know what you mean)
Code
if($act=='index' AND $test=='meh'){
// do stuff
}elseif($act=='page' AND $test=='test'){
// do more stuff


Is that what you mean?

Post has been edited 2 time(s), last time on Mar 14 2008, 10:47 am by Fierce.



None.

Mar 14 2008, 12:49 pm Forsaken Archer Post #28



Quick tip about security:
Turn of magic quotes and registered globals.



None.

Mar 14 2008, 4:28 pm InsolubleFluff Post #29



IP what is it that you do for SEN?



None.

Mar 14 2008, 6:15 pm Forsaken Archer Post #30



I don't understand what you are asking Shocko.
If you are talking about security, I posted some above. If you are talking about HTML, I already told you ;o

Bolthead, maybe something like this:
$keep_me_in_urls = array("view", "action");
foreach($_GET as $k => $v)
if (in_array($k, $keep_me_in_urls))
$this->href .= "&{$k}={$v}";

Then... <a href="blahblah{$this->href}">linky</a>

Depending on how widely used these variables are, you could just write all the urls with them, like href="blahblah&action={$action}"
If action isn't set yet, set it to some unused value (zero?) and just ignore it until it's a useable value.
Or. If the value is really commonly used and you want it to be easily transfered across pages, you could write it to _SESSION (like the portal thingy in the DLDB). Changing it is easy, If ($_GET['action'] != $_SESSION['action']) { $_SESSION['action'] = $_GET['action'] }. Then you don't have to worry about the urls at all.



None.

Mar 14 2008, 7:15 pm (U)Bolt_Head Post #31



Quote from Fierce
Oh and BoltHead, you could also use switch:
Code
$act = secure($_GET['act']);
switch ($act) {
case "index":
   require("index.html");
   break;
case "page":
   require("page.html");
   break;
default:
   require("index.html");
   break;
}


It does the same thing as yours, but I believe it should be used more commonly.

Oh and to answer your question.. (which I'm pretty sure I know what you mean)
Code
if($act=='index' AND $test=='meh'){
// do stuff
}elseif($act=='page' AND $test=='test'){
// do more stuff


Is that what you mean?

I suppose I've never thought of comparing the usefulness of a switch vs sequined if statements... Am I correct to assume that a is more time effective because it only checks the conditions once as opposed to once for each output?

Also about my question...
say my current url is
main.php?view=1
and I want to keep 'view=1' but also go to action=3 so my result will be
main.php?veiw=1&action=3
I don't know the value of view, nor if action is set at all. I do not want to make a different statement for each possibility
My guess is I would do something like this...
Code
//This is my suto code
$bool = false;
if(isset($view))
{
  if( $bool == false)
  {   $append += "?";
      $bool = true;}
  else
  {   $append += "&";  }
  $append += "view=";
  $append += $veiw;
}
if(bool==false)
{  $append += "?";
  $bool = true;  }
else
{  $append += "&";   }

  $append += "action=";
  $append += 3;
}
//make link
echo "<a href='main.php$append'>New Link</a>";


Post has been edited 1 time(s), last time on Mar 14 2008, 7:24 pm by BoltHead.



None.

Mar 14 2008, 8:09 pm Forsaken Archer Post #32



$keep_me_in_urls = array("view", "action");
foreach($_GET as $k => $v)
if (in_array($k, $keep_me_in_urls))
$append .= "&{$k}={$v}";

Would be incredibly simpler... If you don't mind extra ? or & in your urls. Just write links like main.php?{$append}
A downfall of your method would be if you want to include extra variables somewhere else (and not keep them forever), you wouldn't know if $append has the ? already or not. With something like a simple add &variable=value, you can always attach more: main.php?{$append}&extravalue=1. No issues involved.

And it looks like you are using registered globals. Tsk tsk. ;o



None.

Mar 14 2008, 9:48 pm InsolubleFluff Post #33



I am talking about like skins and laying out the actual website.
You said something about wrappers?
I think if I don't get this we'll just use tables and then inside the table's cells use require to get the information we want in the page?
Couldn't the same effect be achieved using divs?



None.

Mar 14 2008, 10:16 pm (U)Bolt_Head Post #34



Quote from isolatedpurity
Quick tip about security:
Turn of magic quotes and registered globals.
Quote from isolatedpurity
And it looks like you are using registered globals. Tsk tsk. ;o

Thanks for all your input IP, I haven't used arrays in php yet. So the format still looks foreign to me. But I understand your suggestion, thanks :)
also as you can tell I'm still pretty newb at this, I don't know what you are referring to by magic quotes or registered globals.

You mentioned registered globals twice now but I don't know what they are nor why not to use them.
- Thanks.



None.

Mar 14 2008, 11:22 pm InsolubleFluff Post #35



I have put an image on the page but i get the little red x what do i need to change to fix that?



None.

Mar 14 2008, 11:55 pm InsolubleFluff Post #36



Moose helped me over msn that problem is fixed.
However, for my background we were hoping to use tiles and so I would really like some help. The concept is there is a part of the background that is different from the rest, so how would I make the layout as so:

[1][1][1][1]
[2][2][2][2]
[2][2][2][2]
[2][2][2][2]

1= images/background1.png
2= images/background2.png



None.

Mar 15 2008, 12:09 am Moose Post #37

We live in a society.

http://www.google.com/search?hl=en&q=css+tiled+background&btnG=Google+Search
You're designing pages on the internet. Use the internet. :P




Mar 15 2008, 12:48 am InsolubleFluff Post #38



didn't help:
body
{
background-image: url('/images/background.jpg');
background-repeat: repeat-x
background-image: url('/images/background2.jpg');
}
is there a way to change the background-image after it repearts horizontally and still keep the original iamge there?



None.

Mar 15 2008, 1:13 am AfterLifeLochie Post #39



Quote from isolatedpurity
Quick tip about security: Turn of magic quotes and registered globals.

You should also escape user-input. If a user 'closes' a text box, they can then enter a ton of commands, like getting all the user's data from mysql, or, worse, deleting things!
Quote from isolatedpurity
And it looks like you are using registered globals. Tsk tsk. ;o

Mmmm...... :-_-:
Quote from Shocko
didn't help: body { background-image: url('/images/background.jpg'); background-repeat: repeat-x background-image: url('/images/background2.jpg'); } is there a way to change the background-image after it repearts horizontally and still keep the original iamge there?
Err... Check that background-image: url('/images/background.jpg'); should be background-image: url('images/background.jpg'); (no first-slash.
As for changing the original image, try making the images overlap (by this I mean that the background image 1 is less transparent than the other one, so that the 2nd image will still start at the top of the page, but it will be covered by image 1, which is less transparent.



None.

Mar 15 2008, 1:17 am InsolubleFluff Post #40



no see the problem is it doesn't like the declaration of background-image: twice... because that's like setting it to one thing then changing your mind. I tried however to do this:

Code
body
{
background-image: url('/images/background2.jpg');
background-position: top left
}
center
{
background-image: url('/images/background.jpg');
background-position: top left
background-repeat: repeat-x
}


However the problem is, on the center, it doesn't want to repeat horizontally.. it wants to repeat the whole thing, not only that, even with positioning to the top left, the center images do not start at the same place the body images do, and so in turn you can still see the body's images in the top left, top right, top parts of the page below the center parts...



None.

Options
Pages: < 1 2 3 46 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[06:36 pm]
RIVE -- Nah, I'm still on Orange Box.
[04:36 pm]
Oh_Man -- anyone play Outside the Box yet? it was a fun time
[12:52 pm]
Vrael -- if you're gonna link that shit at least link some quality shit: https://www.youtube.com/watch?v=uUV3KvnvT-w
[11:17 am]
Zycorax -- :wob:
[2024-4-27. : 9:38 pm]
NudeRaider -- Ultraviolet
Ultraviolet shouted: NudeRaider sing it brother
trust me, you don't wanna hear that. I defer that to the pros.
[2024-4-27. : 7:56 pm]
Ultraviolet -- NudeRaider
NudeRaider shouted: "War nie wirklich weg" 🎵
sing it brother
[2024-4-27. : 6:24 pm]
NudeRaider -- "War nie wirklich weg" 🎵
[2024-4-27. : 3:33 pm]
O)FaRTy1billion[MM] -- o sen is back
[2024-4-27. : 1:53 am]
Ultraviolet -- :lol:
[2024-4-26. : 6:51 pm]
Vrael -- It is, and I could definitely use a company with a commitment to flexibility, quality, and customer satisfaction to provide effective solutions to dampness and humidity in my urban environment.
Please log in to shout.


Members Online: Moose, Roy