simple question...

Discussion in 'PHP' started by bluemouse2, Feb 9, 2007.

  1. #1
    Can someone please help me with this simple question?

    How to limit the size of referrer value to maximum 8 characters?

    $REFERRER = $_POST['REFERRER'];
    	if ($REFERRER==$name || $REFERRER==$_acct || $REFERRER=="") {
    		$REFERRER = $_def_ref;
    	}
    PHP:
    Thank you!
     
    bluemouse2, Feb 9, 2007 IP
  2. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #2
    
    if (strlen($REFERRER) > 8)
     {
     echo "You have entered a referrer name longer than 8 characters";
     }
    else
     {
     //rest of code.
     }
    
    
    PHP:
     
    papa_face, Feb 9, 2007 IP
    bluemouse2 likes this.
  3. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #3
    If your looking for a way to limit the length, rather than not allow, like papa_faces's code try:

    
    <?php
    echo substr('$REFERRER', 0, 8);
    ?>
    
    Code (markup):
    That will only output the first 8 characters.
     
    smatts9, Feb 9, 2007 IP
  4. bluemouse2

    bluemouse2 Well-Known Member

    Messages:
    4,055
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    185
    #4
    what i really want is: if referrer is longer than 8 chars then exit script

    something like that...
    if ($referrer==0) exit;

    just instead of 0 i want my 8 chars rule

    thank you everyone so far


    is this correct?

    if (strlen($REFERRER) > 8) exit;
     
    bluemouse2, Feb 9, 2007 IP
  5. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #5
    Use

    
    if (strlen($REFERRER) > 8)
     {
     exit;
     } else {
    blah blah blah
     }
    
    Code (markup):
     
    smatts9, Feb 9, 2007 IP
  6. bluemouse2

    bluemouse2 Well-Known Member

    Messages:
    4,055
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    185
    #6
    can't i write this without the else code? only like this:

    if (strlen($REFERRER) > 8) exit;

    then continue with normal code...


    OR USE THIS:

    if ($REFERRER==$name || $REFERRER==$_acct || $REFERRER=="" || strlen($REFERRER) < 8)
     
    bluemouse2, Feb 9, 2007 IP
  7. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #7
    Yes you can use just something like this:

    
    $REFERRER = $_POST['REFERRER'];
    if (strlen($REFERRER) > "8") { exit; } 
    // continue script here.
    
    Code (markup):
     
    smatts9, Feb 9, 2007 IP
    bluemouse2 likes this.
  8. bluemouse2

    bluemouse2 Well-Known Member

    Messages:
    4,055
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    185
    #8
    thank you! thread closed now.
     
    bluemouse2, Feb 9, 2007 IP