Jump to content

Recommended Posts

I have a URL that changes depending on the page number,, like so...

http://www.--------/-------.php?pageno=2

 

Is there a way to get the URL and put it in a variable so I can use that variable in a header statement

 

header("location: http://www.---------.com/--------.php?$variable");

 

something like that

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/
Share on other sites

Something like that,,, but the progress bar on the bottom of my browser slowing gets to 100%,, really really slow.. and then does nothing.

 

 

Lol, because you're infinitely redirecting. If you just keep calling to the Location header and redirecting to the page you're already on every time it loads, immediately, the page will just keep refreshing over and over again.

 

You need to call to the Location header only in specific cases.

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840549
Share on other sites

Again,,, All I want is to get the URL,, save it as a variable so I can use that in my header statement... The reason being is that lets say I have 10 pages with pictures.... And a user modifies a picture on page 6,, after the modification,, it takes the user back to to original page....

 

original page http://www.---------.com/-------.php

page with whatever page there on http://www.--------.com/--------.php?pageno=2

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840552
Share on other sites

On the page before the page on which a user modifies a picture, store the current page in a session variable:

 

$_SESSION['last_page'] = $_SERVER['PHP_SELF'];

 

Then, on the page on which a user actually modifies a picture, after the modification is complete, call to header like this:

 

header("Location: ".$_SESSION['last_page']);

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840554
Share on other sites

dude lol easy stuff here lol

 

okay.  user click a link to edit image or something right?

 

so...

<form action=save.php method=post>

<input type=hidden name=url value="<?= $_SERVER["HTTP_REFERER"]; ?>">

more input forms or w/e...

<input type=submit>

</form>

 

save.php should have

<?

//code for saving changes to your image modifications... then

header("Location: ".$_POST["url"]);

die;

?>

end of story

 

also by you saying original page, do you mean page 1 or the page 6 that user was on?

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840559
Share on other sites

the only down site to that, is if user accesses the edit page without going to the "paging" system it will screw things up... so maybe you'd want to make a check to see if they actually came from looking at pictures in the first place, rather than entering it in the url

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840560
Share on other sites

Alright,, I try this again,, I know its hard for someone when its not right in front of them... I have a page called.. http://www.mypage.com/mypage.php that is displayed with the users first picture. When they click the link to see there second picture..  the url shows. http://www.mypage.com/mypage.php?pageno=2... when the user clicks the link to go back to the first picture.. the url shows... http://www.tradekrazy.com/mytrades.php?pageno=1...... Each page gives the user the ability to update the picture and the name(which works great) but when they change something on page 2,, the browser will refresh and go back to http://www.mypage.com/mypage.php..... I would like it to go back to the page that they were on so they can instantly see the change that was made instead of going through the pages to find what they changed...  I hope you understand this... Maybe you already did, and I'm not understanding what everyone was trying to tell me.

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840568
Share on other sites

Here is the form with the script that shows the users pictures with the pagination integrated into it.

<form id="form2" name="form2" method="post" action="updatepicture.php">
        <?php
session_start();
include "connection.php";
if (isset($_GET['pageno']))
{
  $pageno = $_GET['pageno'];
}
else
{
  $pageno = 1;
}
$findit = $_SESSION['id'];
$result = mysql_query("SELECT id FROM members WHERE username = '$findit' LIMIT 1");
$e_row = mysql_fetch_assoc($result);
$query = mysql_query("SELECT count(*) FROM abcxyz WHERE user_id = " . $e_row['id']) or die(mysql_error());


$query_data = mysql_fetch_row($query);
$numrows = $query_data[0];
$rows_per_page = 1;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
$prevpage = $pageno-1;
$nextpage = $pageno+1;


if ($pageno > $lastpage)
{
  $pageno = $lastpage;
}
if ($pageno < 1)
{
  $pageno = 1;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;

$sql = mysql_query("SELECT id, category, imgpath, imgpath2, imgpath3, imgpath4, imgpath5, item_name, description, in_return FROM abcxyz WHERE user_id = " . $e_row['id'] . " $limit");   

$_SESSION['rid_of_delete_button'] = $lastpage;
if($lastpage != 0)
{
echo "<table width='954' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='#000000' bgcolor='#BBD4E1'>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr><td width='188' height='180'><div align='center'>";

echo '<img src="' . $row['imgpath'] . '" width="125" alt="" />';

echo "</div></td><td width='188'><div align='center'>";

if(empty($row['imgpath2'])) 
{
  echo '<div align="center"><a href="picture2.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath2']))
  {
    echo "";
  }
  else
  {
    echo '<img src="' . $row['imgpath2'] . '" width="125" alt="" /><a href="delete_image2.php"><font color="red"> X</a>';
  }
}

echo "</div></td><td width='188'><div align='center'>";

if((empty($row['imgpath3'])) and (!empty($row['imgpath2'])))
{
  echo '<div align="center"><a href="picture3.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
  if(empty($row['imgpath3']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath3'] . '" width="125" alt="" /><a href="delete_image3.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='188'><div align='center'>";
if( (empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )

{
  echo '<div align="center"><a href="picture4.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath4']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath4'] . '" width="125" alt="" /><a href="delete_image4.php"><font color="red"> X</a>';
   }
}
echo "</div></td><td width='190'><div align='center'>";
if( (empty($row['imgpath5'])) and (!empty($row['imgpath4'])) and (!empty($row['imgpath3'])) and (!empty($row['imgpath2'])) )
{
  echo '<div align="center"><a href="picture5.php"><img src="images/uploadanother.png" border="0"></a></div>';
}
else
{
   if(empty($row['imgpath5']))
   {
   echo "";
   }
   else
   {
     echo '<img src="' . $row['imgpath5'] . '" width="125" alt="" /><a href="delete_image5.php"><font color="red"> X</a>';
   }
}
echo "</div></td></tr><tr><td height='43' colspan='4'>";
echo '<strong>Item Name:</strong> <input type="text" name="item_name" value="' . $row['item_name'] . '" size="50" />   ';
if ($pageno == 1)
{
  echo " Previous Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'> Previous Item </a>";
}
echo "($pageno of $lastpage)";
if ( $pageno == $lastpage )
{
  echo " Next Item ";
}
else
{
  echo "<a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'> Next Item </a>";
}
echo "</td><td><div align='center'>";
echo '<input type="hidden" name="id" value="' . $row['id'] . '" size="25" />';
echo "</div></td></tr><tr><td height='116' colspan='4'>";
echo '<strong>Description:</strong> <textarea name="description" cols="75" rows="5">' . $row['description'] . '</textarea>';
echo "</td><td><div align='center'>";
echo '<input type="submit" name="submit" id="submit" value="Update Item">';
echo "</div></td></tr><tr><td height='124' colspan='4'>";
echo '<strong>Seeking:</strong>       <textarea name="in_return" cols="75" rows="5">' . $row['in_return'] . '            </textarea>';
echo "</td><td><div align='center'>";
if(isset($_SESSION['updatecomplete']))
{
  unset($_SESSION['updateerror']);
  echo $_SESSION['updatecomplete'];
}
if(isset($_SESSION['updateerror']))
{
  unset($_SESSION['updatecomplete']);
  echo $_SESSION['updateerror'];
}
if(isset($_SESSION['picupload']))
{
  unset($_SESSION['updatecomplete']);
  unset($_SESSION['updateerror']);
  echo $_SESSION['picupload'];
}
echo "</div></td></tr><tr><td colspan='4'>";
echo '<input type="hidden" name="category" value="' . $row['category'] . '" size="25" />';
//echo "</td><td><div align='center'>";
//echo '';
echo "</td></tr>";

$_SESSION['move_id'] = $row['id'];
$_SESSION['move_category'] = $row['category'];
$_SESSION['path_1'] = $row['imgpath'];
$_SESSION['path_2'] = $row['imgpath2'];
$_SESSION['path_3'] = $row['imgpath3'];
$_SESSION['path_4'] = $row['imgpath4'];
$_SESSION['path_5'] = $row['imgpath5'];
}
echo "</table>";
}
else
{
  echo '<div align="center">You currently have no items.<br />Post your first item now!</div>';
}
?>
      </form>

 

When a user deletes an image... this script does just that...

<?php
//error_reporting(E_ALL);
//ini_set('display_errors',1);

session_start();
require 'connection.php';

$id_gone = $_SESSION['move_id'];
$image2 = $_SESSION['path_2'];
$empty = "";

unlink($image2);
$sql = "UPDATE abcxyz SET imgpath2 = '$empty' WHERE id = '$id_gone'";    

if(mysql_query($sql))
{
  
  header("location: http://www.mypage.com/mypage.php");  // This should have a something refering to what page they were on.
}

?>

Link to comment
https://forums.phpfreaks.com/topic/159360-url-question/#findComment-840578
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.