SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic URL Redirecting for dynamic page

    Hi there,

    I have a student database system and I am currently adding a simple discussion forum into it. I have no problem to add a link which connected to the forum, but having difficulty to link the forum back to the home page. The system flow is like this; Users login their account and there will be the home page which showing the main menu and their basic info. From the main menu, there is a tab for the forum. At this stage, there is no problem occur. Problem occurred when I redirecting the forum to the home page, it is an empty page which is not the original home page.

    Usual home page: URL= http://localhost/Mentor Mentee System/test.php?student_id=12345
    Image:
    newpicture1pm.jpg

    [After redirecting back from forum] Empty home page: URL = http://localhost/Mentor Mentee System/test.php?student_id=
    Image:
    newpicturee.jpg

    I need the URL to be "http://localhost/Mentor Mentee System/test.php?student_id=12345" after redirecting from forum.
    What can I do to correct that? Please advice.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Don't pass the student_id in the query string. Use sessions instead.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Don't pass the student_id in the query string. Use sessions instead.
    Like this?
    PHP Code:
    <a href="test.php?student_id=<?php echo $_SESSION['student_id']; ?>"color:# 004080">Home Page</a>

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Php Beginner View Post
    Like this?
    PHP Code:
    <a href="test.php?student_id=<?php echo $_SESSION['student_id']; ?>"color:# 004080">Home Page</a>
    No, what I mean is that once the student has logged in, it's not a good idea to pass the student id around from one page to another in the query string, because it means a lot of work. You'll have to add it to the query string of each and every link in your site (which is what is missing in the link back to the main page).
    If you save it in a session variable, you'll always have it ready for use on each page.

    If you need help with sessions, you can start by studying the manual, or by googling for a tutorial. And of course, you can ask any questions here if you can't get it to work.

    P.S. the part in red is called the query string:
    Code:
    test.php?student_id=12345
    Last edited by guido2004; Feb 8, 2012 at 07:23. Reason: added query string explanation

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still couldn't get my forum page redirect back to my original logged in user home page.

    Here's the code I wrote for the forum log in page:

    PHP Code:
    <?php require_once('Connections/connection.php'); ?>

    <?php
    //initialize the session
    if (!isset($_SESSION)) {
      
    session_start();
    }
    ?>
    <?php 
    include "incl/hdr.inc"
    $j=0;$fx=array();$fy=opu();$fy=explode("\n",$fy);$nick='';
    if(isset(
    $nnk)){$nnk=urldecode($nnk);$nnk=explode(":|:",$nnk);$nick=$nnk[2];}
    if(isset(
    $tkn)&&!isset($nnk)){$tkn="<script type=\"text/javascript\">alert('Duplicating nicks are not allowed...')</script>";}else{$tkn='';}

    for(
    $i=0;$i<count($fy);$i++){
    if(isset(
    $fy[$i])&&$fy[$i]!=''){$rt=explode(":|:",$fy[$i]);
    if(
    $pp-$rt[0]<70&&$nick!=$rt[2]){$fx[$j]=$fy[$i];$j++;}
    }}
    $fx=implode("\n",$fx);wru($fx); ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
    <link rel="stylesheet" type="text/css" href="incl/nstl.css">
    <?php print $crl[1];?><title><?php print $crl[2];?></title>
    <script type="text/javascript" src="incl/inx.js"></script>
    <?php include "incl/sty.inc";?></head><body onLoad="lo()">
    <form action="set.php" method="post"><input type="hidden" value="w1" name="b">
    <table align="center" class="tbl" width="330"><tr><td align="center" valign="middle">
    <table border="0" width="100%" cellpadding="1" cellspacing="2"><tr><td class="c">
    <table border="0" width="100%" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff">
    <table border="0" width="100%" cellpadding="5" cellspacing="1">
    <tr><td class="c" align="center"><?php print "$crl[2]";?></td></tr><tr><td class="b">

    <table border="0" cellpadding="1" cellspacing="1"><tr>
    <td rowspan="2" valign="top" nowrap><b><?php print $crl[24];?> <script type="text/javascript">df()</script>:</b></td>
    <td valign="bottom" align="center"><input type="text" size="30" name="n" maxlength="8" class="ia" value="<?php print $nick?>"></td>
    <td rowspan="2" valign="top"> <input type="submit" value=" OK " class="ib"></td>
    </tr><tr><td align="center" valign="top" nowrap>
    <a href="#" onClick="wr('w1');return false"><img src="pics/w1.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s1');return false"><img src="pics/s1.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w2');return false"><img src="pics/w2.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s2');return false"><img src="pics/s2.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w3');return false"><img src="pics/w3.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s3');return false"><img src="pics/s3.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w4');return false"><img src="pics/w4.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s4');return false"><img src="pics/s4.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w5');return false"><img src="pics/w5.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s5');return false"><img src="pics/s5.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w6');return false"><img src="pics/w6.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s6');return false"><img src="pics/s6.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w7');return false"><img src="pics/w7.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s7');return false"><img src="pics/s7.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    </td></tr></table></td></tr>
    <tr><td class="c" align="center"><?php print "$crl[22]";?></td></tr>
    <tr><td class="b" align="center">
    <?php $fy=opu();if(strlen($fy)<20){print "<b>$crl[23]</b>";}else{duu(' ');} ?></td></tr>
    </table></td></tr></table></td></tr></table></td></tr></table></form><?php print $tkn?><tr bgcolor="#FFCCCC">
    <?php session_start ();
    $_SESSION['student_id']=$student_id;
    ?>
      <td height="21" colspan="3">&nbsp;&nbsp;&nbsp;<a href="manage_student.php?student_id=<?php echo $_SESSION['student_id']; ?>"color:#004080">Back to home</a></strong></td>
    </tr></strong></td>
    </tr></body></html>
    <?php $fsr=opl();$myar=explode("\n",$fsr);$nr='';
    for(
    $i=0;$i<150;$i++){if(isset($myar[$i])){$nr=$nr.$myar[$i]."\n";}}wrl($nr);?>
    Please correct where I am did wrongly.

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Holy code-formatting nightmare Batman
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You have to use session_start() once per script, on top of each script.
    And then you have to set the session variable with the student id once the student has successfully logged in.

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Location
    Kuching, Sarawak
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it like this?

    PHP Code:
    <?php require_once('Connections/connection.php'); ?>

    <?php
    //initialize the session
    if (!isset($_SESSION)) {
      
    session_start();
    }
    ?>

    <?php
    if (!isset($_SESSION)) {
      
    session_start();
    }
    $MM_authorizedUsers "";
    $MM_donotCheckaccess "true";

    // *** Restrict Access To Page: Grant or deny access to this page
    function isAuthorized($strUsers$strGroups$UserName$UserGroup) { 
      
    // For security, start by assuming the visitor is NOT authorized. 
      
    $isValid False

      
    // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
      // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
      
    if (!empty($UserName)) { 
        
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
        // Parse the strings into arrays. 
        
    $arrUsers Explode(","$strUsers); 
        
    $arrGroups Explode(","$strGroups); 
        if (
    in_array($UserName$arrUsers)) { 
          
    $isValid true
        } 
        
    // Or, you may restrict access to only certain users based on their username. 
        
    if (in_array($UserGroup$arrGroups)) { 
          
    $isValid true
        } 
        if ((
    $strUsers == "") && true) { 
          
    $isValid true
        } 
      } 
      return 
    $isValid
    }

    $MM_restrictGoTo "index.php";
    if (!((isset(
    $_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
      
    $MM_qsChar "?";
      
    $MM_referrer $_SERVER['PHP_SELF'];
      if (
    strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
      if (isset(
    $QUERY_STRING) && strlen($QUERY_STRING) > 0
     
    // $MM_referrer .= "?" . $QUERY_STRING;
      
    $MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
      
    header("Location: "$MM_restrictGoTo); 
      exit;
    }
    ?>

    <?php
    $editFormAction 
    $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }
    ?>

    <?php include "incl/hdr.inc"
    $j=0;$fx=array();$fy=opu();$fy=explode("\n",$fy);$nick='';
    if(isset(
    $nnk)){$nnk=urldecode($nnk);$nnk=explode(":|:",$nnk);$nick=$nnk[2];}
    if(isset(
    $tkn)&&!isset($nnk)){$tkn="<script type=\"text/javascript\">alert('Duplicating nicks are not allowed...')</script>";}else{$tkn='';}

    for(
    $i=0;$i<count($fy);$i++){
    if(isset(
    $fy[$i])&&$fy[$i]!=''){$rt=explode(":|:",$fy[$i]);
    if(
    $pp-$rt[0]<70&&$nick!=$rt[2]){$fx[$j]=$fy[$i];$j++;}
    }}
    $fx=implode("\n",$fx);wru($fx); ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>
    <link rel="stylesheet" type="text/css" href="incl/nstl.css">
    <?php print $crl[1];?><title><?php print $crl[2];?></title>
    <script type="text/javascript" src="incl/inx.js"></script>
    <?php include "incl/sty.inc";?></head><body onLoad="lo()">
    <form action="set.php" method="post"><input type="hidden" value="w1" name="b">
    <table align="center" class="tbl" width="330"><tr><td align="center" valign="middle">
    <table border="0" width="100%" cellpadding="1" cellspacing="2"><tr><td class="c">
    <table border="0" width="100%" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff">
    <table border="0" width="100%" cellpadding="5" cellspacing="1">
    <tr><td class="c" align="center"><?php print "$crl[2]";?></td></tr><tr><td class="b">

    <table border="0" cellpadding="1" cellspacing="1"><tr>
    <td rowspan="2" valign="top" nowrap><b><?php print $crl[24];?> <script type="text/javascript">df()</script>:</b></td>
    <td valign="bottom" align="center"><input type="text" size="30" name="n" maxlength="8" class="ia" value="<?php print $nick?>"></td>
    <td rowspan="2" valign="top"> <input type="submit" value=" OK " class="ib"></td>
    </tr><tr><td align="center" valign="top" nowrap>
    <a href="#" onClick="wr('w1');return false"><img src="pics/w1.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s1');return false"><img src="pics/s1.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w2');return false"><img src="pics/w2.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s2');return false"><img src="pics/s2.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w3');return false"><img src="pics/w3.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s3');return false"><img src="pics/s3.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w4');return false"><img src="pics/w4.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s4');return false"><img src="pics/s4.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w5');return false"><img src="pics/w5.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s5');return false"><img src="pics/s5.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w6');return false"><img src="pics/w6.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s6');return false"><img src="pics/s6.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('w7');return false"><img src="pics/w7.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    <a href="#" onClick="wr('s7');return false"><img src="pics/s7.gif" width="11" height="14" vspace="6" border="0" alt=""></a>
    </td></tr></table></td></tr>
    <tr><td class="c" align="center"><?php print "$crl[22]";?></td></tr>
    <tr><td class="b" align="center">
    <?php $fy=opu();if(strlen($fy)<20){print "<b>$crl[23]</b>";}else{duu(' ');} ?></td></tr>
    </table></td></tr></table></td></tr></table></td></tr></table>
    </form>
    <?php if(isset($_REQUEST['id'])&&($_REQUEST['student_id']=='profile')){?>
    <?php 
    print $tkn?><tr bgcolor="#FFCCCC">
      <td height="21" colspan="3">&nbsp;&nbsp;&nbsp;<a href="manage_student.php?student_id=<?php echo $_SESSION['student_id']; ?>"color:#004080">Back to home</a></strong></td>
    </tr></strong></td>
    </tr></body></html>
    <?php $fsr=opl();$myar=explode("\n",$fsr);$nr='';
    for(
    $i=0;$i<150;$i++){if(isset($myar[$i])){$nr=$nr.$myar[$i]."\n";}}wrl($nr);?>
    It prompt me syntax error or the last line. Sorry if I still not get what you trying to say, because this is my 1st project on php and I am trying to learn. Thanks for any advice.

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    No. Once means once. Not twice.
    Like this:
    PHP Code:
    <?php 
      session_start
    ();

      require_once(
    'Connections/connection.php'); 

      
    $MM_authorizedUsers "";
      
    $MM_donotCheckaccess "true";


Tags for this Thread

Bookmarks

Posting Permissions

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