Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts

    creating a function

    a new site I'm working on has a login function and a user type check on the pages within - I'm attempting to create a bounce function because the site is currently on my server but I know at some point it will get moved from there and if you think I want to go through page by page to change the redirect url it's not going to happen

    anywho - this is how it currently looks on most of the pages:

    PHP Code:
    if ($_SESSION['users'] == "1")
     
      {
        
    session_write_close();
        
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
        exit();

      } 
    I've attempted with:

    PHP Code:
    function bounce_in()
            {
            
    session_write_close();
            
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
            exit();
            } 
    which I then tried to use as:

    PHP Code:
    if ($_SESSION['users'] == "1")
     
      {
        
    bounce_in();

      } 
    bounce_in requires you to log in twice (you can login though) and I also made a bounce_out but that generates a function not defined error

    any help is greatly appreciated
    Last edited by harlequin2k5; 07-13-2007 at 07:34 PM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    So whats the issue? To fix the function not defined error make sure the function is in the server side code before its called. Not sure what to tell you about the logging in twice thing as you've given us very little code. Why are you using session_write_close() anyways? I suspect that might be your problem with having to log in twice. It locks the session data or only the script using it can write to it.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts
    the main issue is that I wanted to have a simple way of updating the header url when this site moves from my server

    I'm reusing code from a previous attempt at the same type of site (a simple intranet) and I've never made my own function before

    the complete php code from the index.php is:

    PHP Code:
    <?
      session_start
    ();
      include_once(
    "functionlist.php");

      if (
    $_SESSION['users'] == "1")
     
      {
        
    session_write_close();
        
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
        exit();
      }

      else if (
    $_SESSION['users'] == "2")
      {
        
    session_write_close();
        
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
        exit();

      }

      else if (
    $_SESSION['users'] == "3")
      {
        
    session_write_close();
        
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
        exit();

      }

     
    $error_message ""// Set error message to empty string

      // Check to see if form has been submitted
      
    if (isset($_POST['submit']))
      {

        
    // Grab username and password
        
    $userid $_POST['username'];
        
    $userpassword $_POST['password'];

        
    // Make connection to DB and query database for username, password, and group
        
    $conn doconnect();

        
    $query "SELECT username, password, typeid FROM users WHERE username = '" safe($userid$conn) . "' AND password = '" safe($userpassword$conn) . "' AND active= 'y'";
    ;
        
    $result mysql_query($query$conn) or die('Query Error - ' mysql_error());
        
    $numRows mysql_num_rows($result);
        if(
    $numRows 0)
        {
            
    $row mysql_fetch_assoc($result);

            
    $realID $row['username'];
            
    $realPass $row['password'];
            
    $users $row['typeid'];

            
    // Find group and redirect them after setting their session
            
    $_SESSION['users'] = $users;
            
    $_SESSION['userid'] = $userid;

     if (
    $_SESSION['users'] == "1")
     
      {
        
    session_write_close();
        
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
        exit();

      }

      else if (
    $_SESSION['users'] == "2")
      {
        
    session_write_close();
        
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
        exit();

      }

      else if (
    $_SESSION['users'] == "3")
      {
        
    session_write_close();
        
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
        exit();

      }

            else
            {
                
    $error_message "<p style=\"font-weight:bold;color:#ff0000;font-size:14px;\">Could not find you in our system...<br />\nPlease try again...</p>\n";
            }

        }
        else
        {
            
    $error_message "<p style=\"font-weight:bold;color:#ff0000;font-size:14px;\">Incorrect username/password!<br />\nPlease try again...</p>\n";
        }
      }
    ?>
    the two bounce functions are:

    PHP Code:
    function bounce_in()
            {
            
    session_write_close();
            
    header("Location: http://shiznit.no-ip.info/lane/main-index.php");
            exit();
            }

        function 
    bounce_out()
            {
            
    session_write_close();
            
    header("Location: http://shiznit.no-ip.info/lane/index.php");
            exit();
            } 
    Last edited by harlequin2k5; 07-13-2007 at 07:49 PM.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts

    Post

    Not sure how the PHP pros do it but I use a file which I call env.php which stores a bunch of constants such as path, MySQL connection info, etc. etc... these are values that will be different depending on where the script is run.

    I then store different versions of that file in the code library, and then simply use the version of the file appropriate to the environment I am running in.

    In addition, you can use $_SERVER variables to derive the domain name to use with the header() function so that it redirects to the current directory regardless of the domain it is running on. Here's what I use:

    PHP Code:
    page_redirect('home.php');

    function 
    page_redirect ($destinationPage) {
        
    $host  $_SERVER['HTTP_HOST'];
        
    $uri  rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
        
    header("Location: http://$host$uri/$destinationPage");


  • #5
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    @ FUMIGATOR
    Do you mind posting that in my thread?
    http://www.codingforums.com/showthread.php?t=118611

    @Harlequin2k5
    I really don't understand the session_write_close() unless you're currently redirecting to a different server and you're ensuring that the session is closed on yours.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #6
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts
    I don't even remember where I got the session_write_close() from - if there's a better way to create a login/logout then by all means enlighten me

    I've been reading through my "PHP and MySQL Web Development" book and unfortunately the user system they have is all tied together with an online store application and I'm having too much difficulty pulling it back apart

    I don't need anyone to build it for me - even a google keyword would work or what to look for on hotscripts or something

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I just copied the example code from the manual for my session destroying needs... seems to do the job.

    http://us.php.net/manual/en/function...on-destroy.php

  • #8
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts
    let me try this again...

    it doesn't matter to me whether it's a session_ or login function that I use - I only used the session_write because that's all I could get my hands on that I knew worked

    I've searched high and low for a login function that would work and have been unsuccessful in finding one for what I need

    the session is not the issue - like I said I know this is going to work for what I need - the issue is that I need a way to be able to store the header location url
    PHP Code:
    header("Location: http://shiznit.no-ip.info/lane/main-index.php"); 
    in such a way that I can go back and change the location url once this site is moved off of my server

    I've tried to use includes and tried to create my own function and neither have worked
    Last edited by harlequin2k5; 07-16-2007 at 04:28 PM.

  • #9
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The code I posted in post #4 of this thread won't work because...?

  • #10
    Regular Coder harlequin2k5's Avatar
    Join Date
    Sep 2005
    Location
    Holiday, FL
    Posts
    635
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    The code I posted in post #4 of this thread won't work because...?
    fumi - I'm sorry - that worked just fine brando had to help me with it a bit more cuz I'm dense but that was exactly what I needed


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •