1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can somebody please take a quick look at my php code

Discussion in 'Black Hat SEO' started by bagging, Mar 2, 2009.

  1. bagging

    bagging Newbie

    Joined:
    Jan 15, 2009
    Messages:
    39
    Likes Received:
    29
    Location:
    Denmark
    Hi all BHW members!

    This is kinda my first post in here so i would like to start by saying "thank you" to all you guys that make this forum so nice! Hopefully I too could start sharing some nice info when I get better at all this BH stuff :)

    I have a problem with some php code (I am not an expert) and I cant seem to get it right. Maybe someone in here could help me out.. Thanks in advance..

    Here is my prob:

    I have a php page that starts a session and then redirect the user to another page where i would like to show 2 different html pages based on if/else the session is true or not (Did the user come from the previous site or not).

    page 1 looks like this:
    Code:
    <?php
     session_start();
     $_SESSION['BeenToA']='yes';
     header('Location: page2.php');
    ?>
    Page 2 looks like this:
    Code:
    <?php 
     session_start();
     
      if  ($_SESSION['BeenToA']=='yes')
     unset($_SESSION['BeenToA']);
    {
       print ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    </head>
    <body>
     <div><h1>Hello world!</h1>
        </div>
     
    </body>
        </html>');
     }
      else ($_SESSION=='no')
     
       {
     
    print ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
     
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    </body>
    </html>');
    }
    ?>
    In case you dont see my point I will try to explain the usage of the script. I would like to start a session "page1" and then when the session starts bring the user to "page2" where the person then see 1 html code if they came from "page1" otherwise 2 html code.

    Maybe this code is totally wrong or it could be made more simple! if so then please advise me :)


    Please help!
    Bagging
     
  2. luxint

    luxint Registered Member

    Joined:
    Jun 16, 2008
    Messages:
    68
    Likes Received:
    22
    You've got

    Code:
    unset($_SESSION['BeenToA']);
    
    after the if braces on page 2 which is wrong. Nothing but { should come after if(){

    also your else should be 'else if'

    L
     
  3. bagging

    bagging Newbie

    Joined:
    Jan 15, 2009
    Messages:
    39
    Likes Received:
    29
    Location:
    Denmark
    Hi lixint,

    Thanks alot :) I will try that now.. I will post again to let you all know what happens :D

    Bagging
     
  4. bagging

    bagging Newbie

    Joined:
    Jan 15, 2009
    Messages:
    39
    Likes Received:
    29
    Location:
    Denmark
    Hi Luxint,

    I still cant get it to work. Am I still doing something wrong?

    Here is my page2:


    Thanks for helping me out!

    Bagging
     
  5. bagging

    bagging Newbie

    Joined:
    Jan 15, 2009
    Messages:
    39
    Likes Received:
    29
    Location:
    Denmark
    I think i am pretty close now but could somebody tell me what i am missing in the code? I get this error: Parse error: syntax error, unexpected T_ELSE on line 20

    Code:
    <?php 
     session_start();
     
    if
       ($_SESSION['BeenToA']=='yes') 
      unset($_SESSION['BeenToA']);
     {
      echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
       <html>
       <head>
       </head>
       <body>
       <div><h1>Hello world!</h1>
       </div>
     
       </body>
       </html>');
     }
    else // This is line 20
     {
     
      echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
       <html>
       <head>
       </head>
       <body>
       </body>
       </html>');
     }
     
    ?>

    Bagging
     
  6. detox1978

    detox1978 Junior Member

    Joined:
    Jan 16, 2009
    Messages:
    110
    Likes Received:
    33
    <?php
    session_start();

    if
    ($_SESSION['BeenToA']=='yes')
    {
    unset($_SESSION['BeenToA']);
    echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    </head>
    <body>
    <div><h1>Hello world!</h1>
    </div>

    </body>
    </html>');
    }
    else // This is line 20
    {

    echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html>
    <head>
    </head>
    <body>
    </body>
    </html>');
    }

    ?>
     
    • Thanks Thanks x 1
  7. silvermario

    silvermario Regular Member

    Joined:
    Feb 26, 2008
    Messages:
    218
    Likes Received:
    89
    Location:
    Europe
    try this one

    Code:
    <?php 
     session_start();
     
    if   ($_SESSION['BeenToA']=='yes') 
      
     {
      unset($_SESSION['BeenToA']);
    
      echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
       <html>
       <head>
       </head>
       <body>
       <div><h1>Hello world!</h1>
       </div>
     
       </body>
       </html>');
     }
    else // This is line 20
     {
       echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
       <html>
       <head>
       </head>
       <body>
       </body>
       </html>');
     }
     
    ?>
    EDIT: well, detox1978 was quicker than me ;)

    you got this error because after an IF statement you either execute 1 line of code, or more than 1 line of code in brackets { }
     
    • Thanks Thanks x 1
    Last edited: Mar 2, 2009
  8. bagging

    bagging Newbie

    Joined:
    Jan 15, 2009
    Messages:
    39
    Likes Received:
    29
    Location:
    Denmark
    It works! Thanks alot detox1978 and silvermario.. You guys just made my day alot better :D

    But thats pretty amazing that 1 line of empty code did all that!
     
  9. silvermario

    silvermario Regular Member

    Joined:
    Feb 26, 2008
    Messages:
    218
    Likes Received:
    89
    Location:
    Europe
    You're welcome :)

    But it wasn't 1 line of empty code that did it, it was moving 1 line of code

    this one >> unset($_SESSION['BeenToA']);

    into the brackets ;)
     
  10. bagging

    bagging Newbie

    Joined:
    Jan 15, 2009
    Messages:
    39
    Likes Received:
    29
    Location:
    Denmark
    Thanks for letting me know that!