Question!!

Discussion in 'Web Programming' started by demonavenger, Aug 2, 2009.

Question!!
  1. Unread #1 - Aug 2, 2009 at 10:15 PM
  2. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Question!!

    Hi all,

    Okay my question is revolving around PHP so if you have no knowledge whatsoever, your best to close this thread right now...

    Okay, at the moment, i am doing an IPT assessment revolving around PHP and mySQL, I am wanting to create a page that has different outputs, via php...

    Example:
    This forum has, displaythread.php?=.....|

    (Note: Of course the forum is a little technical, but you should get the idea.)

    What i want to do is make it have different outputs depending on what is after the equals sign...
    I have tried googling the information but need a little more help. I am slowly understanding PHP, the only thing i basically need to know is its features, functions, etc...

    Thanks guys if you can help me...
    Hope to hear from you guys soon...


    -EDIT-
    I just found something that might be useful to me, and i believe its straight forward:
    Code:
    <?php
    $content = $HTTP_GET_VARS['content'];
    if (!$content ¦¦ $content == "" )
    { echo blog(); }
    else if (function_exists( "$content" ))
    { echo $content();}
    else
    { echo error(); }
    ?> 
    
     
  3. Unread #2 - Aug 2, 2009 at 11:00 PM
  4. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Question!!

    Um. You can do that the same way you get form fields I think... Havn't done any PHP in a long time...
     
  5. Unread #3 - Aug 3, 2009 at 10:05 AM
  6. Deacon Frost
    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57

    Deacon Frost Grand Master
    Banned

    Question!!

    That is a get method. That's all it is. So if you have such link like:

    display.php?text=Hello

    and then a php page like:

    Code:
    <?php
    
    $string = $_GET['text'];
    
    echo $string;
    
    ?>
    
    You would see whatever is in the url after the = sign, which, in this case, you would see on the page:

    Code:
    Hello
    
    And if you went to display.php?text=foobar, you would see:

    Code:
    foobar
    
    Hope you understood that ;).


    To further expand on this, you can also visit links like so:

    display.php?text=foo&text2=bar

    And then have a php page like this:

    Code:
    <?php
    
    $string = $_GET['text'];
    $string2 = $_GET['text2'];
    
    echo $string . "" . $string2;
    
    ?>
    
    And the page would display:

    Code:
    foobar
    
    :)
     
  7. Unread #4 - Aug 3, 2009 at 10:37 PM
  8. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Question!!

    Yeah thanx deacon frost, i understood that far... but I still have issues, but this time its with the $_POST method, it's pissing me off because i fill in a form and then click submit, only to be faced with a blank screen...

    I'll post the code up here, I believe I am doing everything right, I have looked at other tutorials and provide me no answer as to what is wrong with it...

    Login.php:
    (Is just a html file so I'll just show the form)
    Code:
    <form action="login2.php" method="post">
    Username: <br><input name="username" type="text"><br>
    Password: <br><input name="password" type="password"><br>
    <input name="submit" type="submit" value="Login"> <input name="reset" type="reset" value="Reset"> 
    </form>
    
    Login2.php
    (Merged with HTML and PHP, I'll post just the php section.)
    Code:
    <?php
    if ($_POST[username]=="admin" && $_POST[password]=="password" ) {
    	echo "Login successful, please wait while the web page redirects you";
    	session_start();
    	$_SESSION['value'] = 1;
    	\\ redirection part here, when it works of course	
    								} else {
    								echo "Error: No such credentials exists, please try again.";
    ?>
        --DISPLAY LOGIN FORM AGAIN
    
    <?
    	}
    ?>
    
    All help is appreciated and thanks in advance.
     
  9. Unread #5 - Aug 4, 2009 at 1:48 AM
  10. Deacon Frost
    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57

    Deacon Frost Grand Master
    Banned

    Question!!

    Code:
    <?php
    	session_start();
    
    if ($_POST['username'] == "admin" && $_POST['password'] == "password" ) {
    	echo "Login successful, please wait while the web page redirects you";
    
    	$_SESSION['value'] = 1;
    	\\ redirection part here, when it works of course	
     } 
    
    else {							
    session_destroy();
    echo "Error: No such credentials exists, please try again.";
    
    ?>
        --DISPLAY LOGIN FORM AGAIN
    
    <?
    	}
    ?>
    I think that'll work :p. You forgot your '' inside of the $_POST[] thing. I also moved your sessions around a bit. You always have to start a session before anything else...

    I'm not too sure on all of it, because I suck at sessions still, but yeh, it should work.
     
  11. Unread #6 - Aug 4, 2009 at 7:59 PM
  12. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Question!!

    Hmm, i had suspected that myself, but still get nothing on the other page...

    It's just blank, and it's pissing me off D:
    Thanks for the help though, the $_GET[] method is working fine, it must be the server the school's website is using.

    I'll have to test it on another site, I'll look around for a free hosting one and get back to you.

    -EDIT-
    LMFAO, as i expected, works perfectly fine, the schools server is to blame, ahh, how can they expect me to do something if they got a shit server.
    Thanks deacon, it works fine now... (well it always has)

    Will take it up with the school though :mad:
     
  13. Unread #7 - Aug 4, 2009 at 9:25 PM
  14. PublicityFtF
    Joined:
    Mar 10, 2009
    Posts:
    1,178
    Referrals:
    0
    Sythe Gold:
    0

    PublicityFtF Guru
    Banned

    Question!!

    Umm... Pretty sure you can exploit those via RFI.
     
  15. Unread #8 - Aug 5, 2009 at 9:15 AM
  16. Deacon Frost
    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57

    Deacon Frost Grand Master
    Banned

    Question!!

    Most major websites use them ;). Everything is exploitable >.>...GET/POST... it doesn't matter..
     
  17. Unread #9 - Aug 5, 2009 at 1:57 PM
  18. PublicityFtF
    Joined:
    Mar 10, 2009
    Posts:
    1,178
    Referrals:
    0
    Sythe Gold:
    0

    PublicityFtF Guru
    Banned

    Question!!

    I know, but most major websites also have a little added security just in case. I don't know much PHP, however, I'm very sure there's a way(s) to make sure that the link after '?test=' is ending with whatever you specify.
     
  19. Unread #10 - Aug 5, 2009 at 2:31 PM
  20. Deacon Frost
    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57

    Deacon Frost Grand Master
    Banned

    Question!!

    Well, logically, you would first assign the request to a local variable before you use it, then you'd put it through a series of injection prevention, correction checks, etc...

    The point of request variables is to retrieve dynamic data, the only thing you can do is make sure the data is not invalid for use in your script by running it through a series of checks and such.
     
  21. Unread #11 - Aug 5, 2009 at 7:51 PM
  22. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Question!!

    Heh, no need to debate over something like this guys, this site is only for a school project to which i really couldn't care less if it is exploitable or not...

    I have found the reason as to why the PHP coding wasn't working for me;
    Quote from:
    http://www.php-mysql-tutorial.com/wikis/php-tutorial/opening-amp-closing-php-tags.aspx

    The school's server didn't have the short tags enabled, so therefore killed all mine, due to me being lazy and always using short tags. :p

    Thanks for the help though guys, really appreciated it.
     
  23. Unread #12 - Aug 5, 2009 at 8:08 PM
  24. Deacon Frost
    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57

    Deacon Frost Grand Master
    Banned

    Question!!

    That's retarded. Tell your school to get with the damn program. Like that post said, I have never seen a host that doesn't support short tags.


    Wow. Lol.
     
  25. Unread #13 - Aug 9, 2009 at 7:59 PM
  26. demonavenger
    Joined:
    Feb 25, 2007
    Posts:
    536
    Referrals:
    0
    Sythe Gold:
    0

    demonavenger Forum Addict
    $5 USD Donor

    Question!!

    Lol, i recon... Fails badly.

    Rofl, but now I am having another problem, I am still receiving a blank page, but my PHP tags have been fixed, I'd presume its something else, so see if anyone here can identify it for me, cause i am clueless... :S

    Login.php Is a mixture of HTML and PHP
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TITLE>.</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=utf-8">
    <META http-equiv=EXPIRES content=0>
    <META content="Microsoft FrontPage 6.0" name=GENERATOR><LINK title=RSS 
    href="backend.php" type=application/rss+xml rel=alternate><LINK 
    href="EoC_files/style.css" type=text/css rel=StyleSheet>
    </HEAD>
    <BODY text=#FFFFFF link="#DD0000" vlink="#DEE3E7" alink="#445588">
    <TABLE cellSpacing=0 cellPadding=0 width="95%" align=center border=0>
      <TBODY>
      <TR>
        <TD class=lefttd noWrap width=10></TD>
        <TD width="100%">
          <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 height="13">
            <TBODY>
            <TR>
              <TD class=navpic noWrap width=170 height="13">
                <DIV align=left></DIV></TD>
              <TD class=navpic noWrap align=middle width="100%" height="13"></TD>
              <TD class=navpic noWrap width=170 height="13">
                <DIV align=right>
                </DIV></TD></TR></TBODY></TABLE>
          <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
            <TBODY>
            <TR vAlign=top>
              <TD><IMG height=1 alt="" src="EoC_files/7px.gif" width=1 
                border=0></TD></TR></TBODY></TABLE>
          <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
            <TBODY>
            <TR vAlign=top>
              <TD vAlign=top width=1 background=EoC_files/7px.gif>
                <BR></TD>
              <TD vAlign=top width="100%">
                <TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
                  <TBODY>
                  <TR>
                    <TD>
                      <TABLE cellSpacing=0 cellPadding=1 width="100%" border=0>
                        <TBODY>
                        <TR>
                          <TD bgColor=#a9b8c2>
                            <TABLE cellSpacing=0 cellPadding=1 width="100%" border=0>
                              <TBODY>
                              <TR>
                                <TD bgColor=#ffffff>
                                  <TABLE cellSpacing=0 cellPadding=0 width="100%" 
                                  border=0>
                                    <TBODY>
                                    <TR>
                                    <TD bgColor=#ffffff>
                                    <TABLE cellSpacing=0 cellPadding=2 width="100%" 
                                    border=0>
                                    <TBODY>
                                    <TR>
                                    <TD height="250">
                                    <p align="center">
    								<BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
                      <TABLE class=tbl cellSpacing=0 cellPadding=0 border=0>
                        <TBODY>
                        <TR>
                          <TD class=tbll><IMG height=4 alt="" 
                            src="EoC_files/spacer.gif" width=8></TD>
                          <TD class=tblbot><IMG height=4 alt="" 
                            src="EoC_files/spacer.gif" width=8></TD>
                          <TD class=tblr><IMG height=4 alt="" 
                            src="EoC_files/spacer.gif" 
                      width=8></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
                <TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
                  <TBODY>
                  <TR>
                    <TD height="100%">
                      <TABLE class=forumline cellSpacing=1 cellPadding=0 
                      width="100%" border=0; border-width: 1px">
                        <TBODY>
                        <tr>
                          <TH width="100%" height=20>
                            <DIV align=center>Please type in your username and password:</DIV></TH>
                        </tr>
                        <TR>
                          <TD class=row1 height="100%">
    					  <?PHP
    						if ($_GET['msg'] != '') {
    							echo "<DIV align=center> $_GET['msg'] </DIV>";
    						}
    						
    						// Includes database information, stored to variables $user, $password & $database
    						include("dbinfo.inc.php");
    						
    						// Check if the form has sent it's self some information for it to work on, else log in...
    						if (isset($_POST['username'])) {
    							// Start session, to keep data for the computer to identify if your logged in.
    							session_start();
    							
    							// Connect to database and select the columns ID, Password, Userlevel, First and Last Name.
    							mysql_connect("localhost",$user,$password) or die( "Unable to connect to server");
    							mysql_select_db($database) or die("Unable to select database");
    							$form_user = mysql_real_escape_string($_POST['username']);
    							$form_pass = mysql_real_escape_string($_POST['password']);
    							$query = "SELECT 'id', 'password', 'userlevel', 'first', 'last' FROM employee WHERE id = '$form_user' AND password = '$form_pass'";
    							$result = mysql_query($query) or die("Unable to collect information from database.");
    							
    							
    							if ($row = mysql_fetch_array($result)) {
    									// A result has returned true, there for sets the session variables to true, etc. 
    									$_SESSION['view'] = 1;
    									$_SESSION['id'] = $row['1'];
    									$_SESSION['userlevel'] = $row['10'];
    									$_SESSION['fullname'] = "$row['2'] $row['3']";
    									
    									// Also redirects user to next page.
    									header("Location: employee.php");
    							
    								} else {
    							
    								// --Else the while loop has not recorded any results from table.
    								echo "Error: No such credentials exists, please try again.\n";
    								echo "<DIV align=center><form name='Login' method='post' action='login.php'>\n";
    								echo "Username: <br><input name='username' type='text'><br>\n";
    								echo "Password: <br><input name='password' type='password'><br>\n";
    								echo "<input name='submit' type='submit' value='Submit Form'> <input name='reset' type='reset' value='Reset'></form>\n"; 
    								
    								// Destroy the session and delete all information recorded.
    								session_destroy();
    								}
    					?>
    					
    					
    				  </font></DIV></p></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><p><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR></TD>
              <TD vAlign=top width=170 rowspan="2"></TD></TR>
            <TR vAlign=top>
              <TD vAlign=top background=EoC_files/7px.gif colspan="2" height="7">
                <p align="center"><FONT color=black>Website design created by David de Nava</FONT></TD>
              </TR></TBODY></TABLE>
          </TD>
        <TD class=righttd noWrap width=10>&nbsp;</TD></TR></TBODY></TABLE>
          <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 id="table1">
            <TBODY>
            <TR>
              <TD vAlign=center width="60%" background="EoC_files/bg.jpg">
    			<IMG 
                src="EoC_files/banner.gif" border=0 width="32" height="32"></A></TD>
              <TD width="40%" 
            background="EoC_files/bg.jpg"></TD></TR></TBODY></TABLE>
          	
    </BODY></HTML>
    					<?PHP
    								} else {
    					?>
    					  <FONT color=black><DIV align=center><form action="login.php" method="post">
    						Username: <br><input name="username" type="text"><br>
    						Password: <br><input name="password" type="password"><br>
    						<input name="submit" type="submit" value="Login"> <input name="reset" type="reset" value="Reset"> 
    						</form>
    						</font></DIV></TD></TR></TBODY></TABLE>
                      </TD></TR></TBODY></TABLE>
    			<p>
                <BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR></TD>
              <TD vAlign=top width=170 rowspan="2"></TD></TR>
            <TR vAlign=top>
              <TD vAlign=top background=EoC_files/7px.gif colspan="2" height="7">
                <p align="center"><FONT color=black>Website design created by David de Nava</FONT></TD>
              </TR></TBODY></TABLE>
          </TD>
        <TD class=righttd noWrap width=10>&nbsp;</TD></TR></TBODY></TABLE>
          <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 id="table1">
            <TBODY>
            <TR>
              <TD vAlign=center width="60%" background="EoC_files/bg.jpg">
    			<IMG 
                src="EoC_files/banner.gif" border=0 width="32" height="32"></A></TD>
              <TD width="40%" 
            background="EoC_files/bg.jpg"></TD></TR></TBODY></TABLE>
          
    </BODY></HTML>
    
    				<?PHP
    							}
    				?>
    
    My teacher was telling me that I cannot have a header tag before all html output?
    Is that correct? Thanks again guys, :)
     
  27. Unread #14 - Aug 14, 2009 at 1:08 AM
  28. Deacon Frost
    Joined:
    Jan 30, 2007
    Posts:
    2,905
    Referrals:
    3
    Sythe Gold:
    57

    Deacon Frost Grand Master
    Banned

    Question!!

    Uhm, all header/session_start()/etc HAS to go before any other data. It has to load first.
     
< need help (coder needed) | Looking For a Website Designer (High level Rs Account with 21+M as payment) >

Users viewing this thread
1 guest


 
 
Adblock breaks this site