returning session, Parse URL, Return and redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
teezilla
Forum Newbie
Posts: 6
Joined: Tue Feb 03, 2009 2:48 pm

returning session, Parse URL, Return and redirect

Post by teezilla »

My goal is to have the pid change every time the user returns and redirect to appropriate next page on the site. So in essence if I leave the site and come back I go from pg1.php to pg2.php..

code follows..

<?php

session_start();

function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

//$link = "http://www.ikyp.com/pharma/tutorial/214";
$link = curPageURL();
$digit = explode("http://www.ikyp.com/pharma/tutorial/",$link);
$_SESSION["pid"] = $digit[1];

?>


<?php
session_start();

if (isset($_SESSION['pid'])) {

if ($_SESSION['pid'] == "214") {
header ("Location: 1A.php");
}
else if ($_SESSION['pid'] == "215") {
header ("Location: 1B.php");
}
else if ($_SESSION['pid'] == "216") {
header ("Location: 2.php");
}
else if ($_SESSION['pid'] == "217") {
header ("Location: 3.php");
}
else if ($_SESSION['pid'] == "218") {
header ("Location: 4A.php");
}
else if ($_SESSION['pid'] == "219") {
header ("Location: 4B.php");
}
else if ($_SESSION['pid'] == "220") {
header ("Location: 4C.php");
}
else if ($_SESSION['pid'] == "221") {
header ("Location: 5A.php");
}

else if ($_SESSION['pid'] == "222") {
header ("Location: 5B.php");
}
else if ($_SESSION['pid'] == "223") {
header ("Location: 5C.php");
}
else if ($_SESSION['pid'] == "224") {
header ("Location: 5D.php");
}
else if ($_SESSION['pid'] == "225") {
header ("Location: 6A.php");
}
else if ($_SESSION['pid'] == "226") {
header ("Location: 6B.php");
}
else if ($_SESSION['pid'] == "227") {
header ("Location: 6C.php");
}
else if ($_SESSION['pid'] == "228") {
header ("Location: 7A.php");
}
else if ($_SESSION['pid'] == "229") {
header ("Location: 7B.php");
}
else if ($_SESSION['pid'] == "230") {
header ("Location: 7C.php");
}
else if ($_SESSION['pid'] == "231") {
header ("Location: 8A.php");
}
else if ($_SESSION['pid'] == "232") {
header ("Location: 8B.php");
}
else if ($_SESSION['pid'] == "233") {
header ("Location: 8C.php");
}
else if ($_SESSION['pid'] == "234") {
header ("Location: 9A.php");
}
else if ($_SESSION['pid'] == "235") {
header ("Location: 9B.php");
}
else if ($_SESSION['pid'] == "236") {
header ("Location: 10A.php");
}
else if ($_SESSION['pid'] == "237") {
header ("Location: 10B.php");
}
else if ($_SESSION['pid'] == "238") {
header ("Location: 11A.php");
}
else if ($_SESSION['pid'] == "239") {
header ("Location: 11B.php");
}
else if ($_SESSION['pid'] == "240") {
header ("Location: 11C.php");
}
else if ($_SESSION['pid'] == "241") {
header ("Location: 11D.php");
}
else if ($_SESSION['pid'] == "242") {
header ("Location: 12A.php");
}
else if ($_SESSION['pid'] == "243") {
header ("Location: 12B.php");
}
else {
header ("Location: 1B.php");
}

}
else {
echo "Session var is not set!";
}


session_start();
session_unregister("pid");
session_destroy();


?>

Any help would be greatly appreciated..
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: returning session, Parse URL, Return and redirect

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Post Reply